| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Template Functions. |
| 4 |
* |
| 5 |
* Functions used with template hooks. |
| 6 |
* |
| 7 |
* @package Charitable/Functions/Templates |
| 8 |
* @author David Bisset |
| 9 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 10 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 |
* @since 1.0.0 |
| 12 |
* @version 1.8.9.1 |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// ////////////////////////////// |
| 21 |
// HEAD OUTPUT |
| 22 |
// ////////////////////////////// |
| 23 |
if ( ! function_exists( 'charitable_template_custom_styles' ) ) : |
| 24 |
|
| 25 |
/** |
| 26 |
* Add custom styles to the <head> section. |
| 27 |
* |
| 28 |
* This is used on the wp_head action. |
| 29 |
* |
| 30 |
* @since 1.2.0 |
| 31 |
* @version 1.8.9.1 |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
function charitable_template_custom_styles() { |
| 36 |
|
| 37 |
if ( ! apply_filters( 'charitable_add_custom_styles', true ) ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ( defined( 'CHARITABLE_NO_CUSTOM_TEMPLATE_STYLES' ) && CHARITABLE_NO_CUSTOM_TEMPLATE_STYLES ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
$styles = get_transient( 'charitable_custom_styles' ); |
| 46 |
|
| 47 |
if ( false === $styles ) { |
| 48 |
|
| 49 |
ob_start(); |
| 50 |
|
| 51 |
charitable_template( 'custom-styles.css.php' ); |
| 52 |
|
| 53 |
$styles = ob_get_clean(); |
| 54 |
|
| 55 |
$styles = charitable_compress_css( $styles ); |
| 56 |
|
| 57 |
set_transient( 'charitable_custom_styles', $styles, 0 ); |
| 58 |
} |
| 59 |
|
| 60 |
echo $styles; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 61 |
} |
| 62 |
|
| 63 |
endif; |
| 64 |
|
| 65 |
if ( ! function_exists( 'charitable_hide_admin_bar' ) ) : |
| 66 |
|
| 67 |
/** |
| 68 |
* Hides the admin bar from header. |
| 69 |
* |
| 70 |
* This is designed to be used when viewing the campaign widget. |
| 71 |
* |
| 72 |
* @since 1.3.0 |
| 73 |
* |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
function charitable_hide_admin_bar() { |
| 77 |
?> |
| 78 |
<style type="text/css" media="screen"> |
| 79 |
html { margin-top: 0 !important; } |
| 80 |
* html body { margin-top: 0 !important; } |
| 81 |
</style> |
| 82 |
<?php |
| 83 |
} |
| 84 |
|
| 85 |
endif; |
| 86 |
|
| 87 |
// ////////////////////////////// |
| 88 |
// BODY CLASSES |
| 89 |
// ////////////////////////////// |
| 90 |
if ( ! function_exists( 'charitable_add_body_classes' ) ) : |
| 91 |
|
| 92 |
/** |
| 93 |
* Adds custom body classes to certain templates. |
| 94 |
* |
| 95 |
* @since 1.3.0 |
| 96 |
* |
| 97 |
* @param string[] $classes Body classes. |
| 98 |
* @return string[] |
| 99 |
*/ |
| 100 |
function charitable_add_body_classes( $classes ) { |
| 101 |
if ( charitable_is_page( 'donation_receipt_page' ) ) { |
| 102 |
$classes[] = 'campaign-donation-receipt'; |
| 103 |
} |
| 104 |
|
| 105 |
if ( charitable_is_page( 'donation_processing_page' ) ) { |
| 106 |
$classes[] = 'campaign-donation-processing'; |
| 107 |
} |
| 108 |
|
| 109 |
if ( charitable_is_page( 'campaign_donation_page' ) ) { |
| 110 |
$classes[] = 'campaign-donation-page'; |
| 111 |
} |
| 112 |
|
| 113 |
if ( charitable_is_page( 'campaign_widget_page' ) ) { |
| 114 |
$classes[] = 'campaign-widget'; |
| 115 |
} |
| 116 |
|
| 117 |
if ( charitable_is_page( 'email_preview' ) ) { |
| 118 |
$classes[] = 'email-preview'; |
| 119 |
} |
| 120 |
|
| 121 |
return $classes; |
| 122 |
} |
| 123 |
|
| 124 |
endif; |
| 125 |
|
| 126 |
// ////////////////////////////// |
| 127 |
// SINGLE CAMPAIGN CONTENT |
| 128 |
// ////////////////////////////// |
| 129 |
if ( ! function_exists( 'charitable_template_campaign_description' ) ) : |
| 130 |
|
| 131 |
/** |
| 132 |
* Display the campaign description before the summary and rest of content. |
| 133 |
* |
| 134 |
* @since 1.0.0 |
| 135 |
* @version 1.8.1 Add check for CHARITABLE_NO_LEGACY_CHECK_CAMPAIGN_DESCRIPTION constant. |
| 136 |
* @version 1.8.2 Added charitable_find_description_in_campaign_settings method |
| 137 |
* |
| 138 |
* @param Charitable_Campaign $campaign The campaign object. |
| 139 |
* @param array $view_args The view arguments. |
| 140 |
* @return void |
| 141 |
*/ |
| 142 |
function charitable_template_campaign_description( $campaign, $view_args = array() ) { |
| 143 |
if ( charitable_is_campaign_legacy( $campaign ) || ( defined( 'CHARITABLE_NO_LEGACY_CHECK_CAMPAIGN_DESCRIPTION' ) && CHARITABLE_NO_LEGACY_CHECK_CAMPAIGN_DESCRIPTION ) ) { |
| 144 |
charitable_template( |
| 145 |
'campaign/description.php', |
| 146 |
array( |
| 147 |
'campaign' => $campaign, |
| 148 |
'view_args' => $view_args, |
| 149 |
) |
| 150 |
); |
| 151 |
} elseif ( $campaign->ID && ! empty( $view_args['shortcode'] ) ) { |
| 152 |
$campaign_settings = get_post_meta( $campaign->ID, 'campaign_settings_v2', true ); |
| 153 |
if ( is_array( $campaign_settings ) && ! empty( $campaign_settings ) ) { |
| 154 |
$description_limit = isset( $view_args['description_limit'] ) ? intval( $view_args['description_limit'] ) : 0; |
| 155 |
$description = charitable_find_description_in_campaign_settings( $campaign_settings, $description_limit ); |
| 156 |
charitable_template( |
| 157 |
'campaign/description.php', |
| 158 |
array( |
| 159 |
'campaign' => $campaign, |
| 160 |
'description' => $description, |
| 161 |
'view_args' => $view_args, |
| 162 |
) |
| 163 |
); |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
endif; |
| 170 |
|
| 171 |
if ( ! function_exists( 'charitable_template_campaign_finished_notice' ) ) : |
| 172 |
|
| 173 |
/** |
| 174 |
* Display the campaign finished notice. |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
* |
| 178 |
* @param Charitable_Campaign $campaign The campaign object. |
| 179 |
* @return void |
| 180 |
*/ |
| 181 |
function charitable_template_campaign_finished_notice( $campaign ) { |
| 182 |
if ( ! $campaign->has_ended() ) { |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
charitable_template( 'campaign/finished-notice.php', array( 'campaign' => $campaign ) ); |
| 187 |
} |
| 188 |
|
| 189 |
endif; |
| 190 |
|
| 191 |
if ( ! function_exists( 'charitable_template_campaign_percentage_raised' ) ) : |
| 192 |
|
| 193 |
/** |
| 194 |
* Display the percentage that the campaign has raised in summary block. |
| 195 |
* |
| 196 |
* @since 1.0.0 |
| 197 |
* |
| 198 |
* @param Charitable_Campaign $campaign The campaign object. |
| 199 |
* @return boolean True if the template was displayed. False otherwise. |
| 200 |
*/ |
| 201 |
function charitable_template_campaign_percentage_raised( $campaign ) { |
| 202 |
// Check if $campaign is a valid object. |
| 203 |
if ( ! is_a( $campaign, 'Charitable_Campaign' ) ) { |
| 204 |
return false; |
| 205 |
} |
| 206 |
|
| 207 |
if ( ! $campaign->has_goal() ) { |
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
// Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings. |
| 212 |
if ( false === apply_filters( 'charitable_display_template_campaign_percentage_raised', true, $campaign ) ) { |
| 213 |
return false; |
| 214 |
} |
| 215 |
|
| 216 |
charitable_template( 'campaign/summary-percentage-raised.php', array( 'campaign' => $campaign ) ); |
| 217 |
|
| 218 |
return true; |
| 219 |
} |
| 220 |
|
| 221 |
endif; |
| 222 |
|
| 223 |
if ( ! function_exists( 'charitable_template_campaign_donation_summary' ) ) : |
| 224 |
|
| 225 |
/** |
| 226 |
* Display campaign goal in summary block. |
| 227 |
* |
| 228 |
* @since 1.0.0 |
| 229 |
* |
| 230 |
* @param Charitable_Campaign $campaign The campaign object. |
| 231 |
* @return true |
| 232 |
*/ |
| 233 |
function charitable_template_campaign_donation_summary( $campaign ) { |
| 234 |
charitable_template( 'campaign/summary-donations.php', array( 'campaign' => $campaign ) ); |
| 235 |
return true; |
| 236 |
} |
| 237 |
|
| 238 |
endif; |
| 239 |
|
| 240 |
if ( ! function_exists( 'charitable_template_campaign_donor_count' ) ) : |
| 241 |
|
| 242 |
/** |
| 243 |
* Display number of campaign donors in summary block. |
| 244 |
* |
| 245 |
* @since 1.0.0 |
| 246 |
* |
| 247 |
* @param Charitable_Campaign $campaign The campaign object. |
| 248 |
* @return true |
| 249 |
*/ |
| 250 |
function charitable_template_campaign_donor_count( $campaign ) { |
| 251 |
|
| 252 |
// Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings. |
| 253 |
if ( false === apply_filters( 'charitable_display_template_campaign_donor_count', true, $campaign ) ) { |
| 254 |
return false; |
| 255 |
} |
| 256 |
|
| 257 |
charitable_template( 'campaign/summary-donors.php', array( 'campaign' => $campaign ) ); |
| 258 |
return true; |
| 259 |
} |
| 260 |
|
| 261 |
endif; |
| 262 |
|
| 263 |
if ( ! function_exists( 'charitable_template_campaign_time_left' ) ) : |
| 264 |
|
| 265 |
/** |
| 266 |
* Display the amount of time left in the campaign in the summary block. |
| 267 |
* |
| 268 |
* @since 1.0.0 |
| 269 |
* |
| 270 |
* @param Charitable_Campaign $campaign The campaign object. |
| 271 |
* @return boolean True if the template was displayed. False otherwise. |
| 272 |
*/ |
| 273 |
function charitable_template_campaign_time_left( $campaign ) { |
| 274 |
if ( ! is_a( $campaign, 'Charitable_Campaign' ) ) { |
| 275 |
return false; |
| 276 |
} |
| 277 |
|
| 278 |
if ( $campaign->is_endless() ) { |
| 279 |
return false; |
| 280 |
} |
| 281 |
|
| 282 |
// Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings. |
| 283 |
if ( false === apply_filters( 'charitable_display_template_campaign_time_remaining', true, $campaign ) ) { |
| 284 |
return false; |
| 285 |
} |
| 286 |
|
| 287 |
charitable_template( 'campaign/summary-time-left.php', array( 'campaign' => $campaign ) ); |
| 288 |
return true; |
| 289 |
} |
| 290 |
|
| 291 |
endif; |
| 292 |
|
| 293 |
if ( ! function_exists( 'charitable_template_donate_button' ) ) : |
| 294 |
|
| 295 |
/** |
| 296 |
* Display donate button or link in the campaign summary. |
| 297 |
* |
| 298 |
* @since 1.0.0 |
| 299 |
* |
| 300 |
* @param Charitable_Campaign $campaign The campaign object. |
| 301 |
* @return boolean True if the template was displayed. False otherwise. |
| 302 |
*/ |
| 303 |
function charitable_template_donate_button( $campaign ) { |
| 304 |
if ( ! is_a( $campaign, 'Charitable_Campaign' ) ) { |
| 305 |
return false; |
| 306 |
} |
| 307 |
|
| 308 |
if ( ! $campaign->can_receive_donations() ) { |
| 309 |
return false; |
| 310 |
} |
| 311 |
|
| 312 |
$campaign->donate_button_template(); |
| 313 |
|
| 314 |
return true; |
| 315 |
} |
| 316 |
|
| 317 |
endif; |
| 318 |
|
| 319 |
if ( ! function_exists( 'charitable_template_campaign_summary' ) ) : |
| 320 |
|
| 321 |
/** |
| 322 |
* Display campaign summary before rest of campaign content. |
| 323 |
* |
| 324 |
* @since 1.0.0 |
| 325 |
* |
| 326 |
* @param Charitable_Campaign $campaign The campaign object. |
| 327 |
* @return void |
| 328 |
*/ |
| 329 |
function charitable_template_campaign_summary( $campaign ) { |
| 330 |
if ( charitable_is_campaign_legacy( $campaign ) ) { |
| 331 |
charitable_template( 'campaign/summary.php', array( 'campaign' => $campaign ) ); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
endif; |
| 336 |
|
| 337 |
if ( ! function_exists( 'charitable_template_campaign_progress_bar' ) ) : |
| 338 |
|
| 339 |
/** |
| 340 |
* Output the campaign progress bar. |
| 341 |
* |
| 342 |
* @since 1.0.0 |
| 343 |
* |
| 344 |
* @param Charitable_Campaign $campaign The campaign object. |
| 345 |
* @return void |
| 346 |
*/ |
| 347 |
function charitable_template_campaign_progress_bar( $campaign ) { |
| 348 |
charitable_template( 'campaign/progress-bar.php', array( 'campaign' => $campaign ) ); |
| 349 |
} |
| 350 |
|
| 351 |
endif; |
| 352 |
|
| 353 |
if ( ! function_exists( 'charitable_template_campaign_donate_button' ) ) : |
| 354 |
|
| 355 |
/** |
| 356 |
* Output the campaign donate button. |
| 357 |
* |
| 358 |
* @since 1.0.0 |
| 359 |
* |
| 360 |
* @param Charitable_Campaign $campaign The campaign object. |
| 361 |
* @return void |
| 362 |
*/ |
| 363 |
function charitable_template_campaign_donate_button( $campaign ) { |
| 364 |
if ( charitable_is_campaign_legacy( $campaign ) ) { |
| 365 |
charitable_template( 'campaign/donate-button.php', array( 'campaign' => $campaign ) ); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
endif; |
| 370 |
|
| 371 |
if ( ! function_exists( 'charitable_template_campaign_donate_link' ) ) : |
| 372 |
|
| 373 |
/** |
| 374 |
* Output the campaign donate link. |
| 375 |
* |
| 376 |
* @since 1.0.0 |
| 377 |
* |
| 378 |
* @param Charitable_Campaign $campaign The campaign object. |
| 379 |
* @return void |
| 380 |
*/ |
| 381 |
function charitable_template_campaign_donate_link( $campaign ) { |
| 382 |
charitable_template( 'campaign/donate-link.php', array( 'campaign' => $campaign ) ); |
| 383 |
} |
| 384 |
|
| 385 |
endif; |
| 386 |
|
| 387 |
if ( ! function_exists( 'charitable_template_campaign_status_tag' ) ) : |
| 388 |
|
| 389 |
/** |
| 390 |
* Output the campaign status tag. |
| 391 |
* |
| 392 |
* @since 1.0.0 |
| 393 |
* |
| 394 |
* @param Charitable_Campaign $campaign The campaign object. |
| 395 |
* @return void |
| 396 |
*/ |
| 397 |
function charitable_template_campaign_status_tag( $campaign ) { |
| 398 |
charitable_template( 'campaign/status-tag.php', array( 'campaign' => $campaign ) ); |
| 399 |
} |
| 400 |
|
| 401 |
endif; |
| 402 |
|
| 403 |
if ( ! function_exists( 'charitable_template_campaign_donation_form_in_page' ) ) : |
| 404 |
|
| 405 |
/** |
| 406 |
* Add the donation form straight into the campaign page. |
| 407 |
* |
| 408 |
* @since 1.0.0 |
| 409 |
* @since 1.5.0 Function now returns true/false depending |
| 410 |
* on whether the template is rendered. |
| 411 |
* @since 1.8.1 Added check to see if charitable_get_current_donation_form() returns false, preventing fatal error |
| 412 |
* |
| 413 |
* @param Charitable_Campaign $campaign The campaign object. |
| 414 |
* @return boolean |
| 415 |
*/ |
| 416 |
function charitable_template_campaign_donation_form_in_page( $campaign ) { |
| 417 |
if ( ! is_a( $campaign, 'Charitable_Campaign' ) ) { |
| 418 |
return false; |
| 419 |
} |
| 420 |
if ( $campaign->can_receive_donations() && 'same_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 421 |
$donation_id = get_query_var( 'donation_id', false ); |
| 422 |
|
| 423 |
/* If a donation ID is included, make sure it belongs to the current user. */ |
| 424 |
if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) { |
| 425 |
return false; |
| 426 |
} |
| 427 |
|
| 428 |
if ( false !== charitable_get_current_donation_form() ) { |
| 429 |
charitable_get_current_donation_form()->render(); |
| 430 |
} |
| 431 |
|
| 432 |
return true; |
| 433 |
} |
| 434 |
|
| 435 |
return false; |
| 436 |
} |
| 437 |
|
| 438 |
endif; |
| 439 |
|
| 440 |
if ( ! function_exists( 'charitable_template_campaign_modal_donation_window' ) ) : |
| 441 |
|
| 442 |
/** |
| 443 |
* Adds the modal donation window to a campaign page. |
| 444 |
* |
| 445 |
* @since 1.0.0 |
| 446 |
* @since 1.5.0 Function now returns true/false depending |
| 447 |
* on whether the template is rendered. |
| 448 |
* @version 1.8.2 Added additional pattern to search for campaign id in the content. |
| 449 |
* |
| 450 |
* @global WP_Query $wp_query |
| 451 |
* @return boolean |
| 452 |
*/ |
| 453 |
function charitable_template_campaign_modal_donation_window() { |
| 454 |
global $wp_query, $post; |
| 455 |
|
| 456 |
// We need to find the campaign so we can use charitable_get_current_campaign(). |
| 457 |
if ( Charitable::CAMPAIGN_POST_TYPE === get_post_type() ) { |
| 458 |
|
| 459 |
if ( isset( $wp_query->query_vars['donate'] ) ) { |
| 460 |
return false; |
| 461 |
} |
| 462 |
|
| 463 |
$campaign_ids = array( charitable_get_current_campaign_id() ); |
| 464 |
|
| 465 |
} elseif ( 'page' === get_post_type() && ! empty( $post->post_content ) ) { |
| 466 |
|
| 467 |
// Find all instances of {"campaignID":"126"} in the content and extract all the different campaign ID and put them into a PHP array. |
| 468 |
$pattern = '/{"campaignID":"(\d+)"}/'; |
| 469 |
preg_match_all( $pattern, $post->post_content, $matches ); |
| 470 |
$campaign_ids = array_unique( $matches[1] ); |
| 471 |
// if empty, then find all instances of "campaign id=126" in the content and extract all the different campaign ID and put them into a PHP array. |
| 472 |
if ( empty( $campaign_ids ) ) { |
| 473 |
$pattern = '/campaign id="(\d+)"/'; |
| 474 |
preg_match_all( $pattern, $post->post_content, $matches ); |
| 475 |
$campaign_ids = array_unique( $matches[1] ); |
| 476 |
} |
| 477 |
|
| 478 |
} else { |
| 479 |
|
| 480 |
return false; |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
if ( ! $campaign_ids ) { |
| 485 |
return false; |
| 486 |
} |
| 487 |
|
| 488 |
foreach ( $campaign_ids as $campaign_id ) { |
| 489 |
|
| 490 |
$campaign = charitable_get_campaign( $campaign_id ); |
| 491 |
|
| 492 |
if ( $campaign->can_receive_donations() && 'modal' === charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 493 |
charitable_template( 'campaign/donate-modal-window.php', array( 'campaign' => $campaign ) ); |
| 494 |
} |
| 495 |
|
| 496 |
} |
| 497 |
|
| 498 |
return true; |
| 499 |
} |
| 500 |
|
| 501 |
endif; |
| 502 |
|
| 503 |
if ( ! function_exists( 'charitable_template_elementor_campaign_modal_donation_window' ) ) : |
| 504 |
|
| 505 |
/** |
| 506 |
* Adds the modal donation window for Elementor widgets. |
| 507 |
* |
| 508 |
* @since 1.8.7.1 |
| 509 |
* |
| 510 |
* @global WP_Post $post |
| 511 |
* @return boolean |
| 512 |
*/ |
| 513 |
function charitable_template_elementor_campaign_modal_donation_window() { |
| 514 |
global $post; |
| 515 |
|
| 516 |
// Only run if Elementor is active. |
| 517 |
if ( ! did_action( 'elementor/loaded' ) ) { |
| 518 |
return false; |
| 519 |
} |
| 520 |
|
| 521 |
// Only run on pages/posts. |
| 522 |
if ( ! $post || ! in_array( $post->post_type, array( 'page', 'post' ) ) ) { |
| 523 |
return false; |
| 524 |
} |
| 525 |
|
| 526 |
// Get Elementor data. |
| 527 |
$elementor_data = get_post_meta( $post->ID, '_elementor_data', true ); |
| 528 |
if ( empty( $elementor_data ) ) { |
| 529 |
return false; |
| 530 |
} |
| 531 |
|
| 532 |
// Decode JSON data. |
| 533 |
$data = json_decode( $elementor_data, true ); |
| 534 |
if ( ! is_array( $data ) ) { |
| 535 |
return false; |
| 536 |
} |
| 537 |
|
| 538 |
$campaign_ids = array(); |
| 539 |
|
| 540 |
// Recursively search for Charitable widgets. |
| 541 |
$campaign_ids = charitable_extract_campaign_ids_from_elementor_data( $data ); |
| 542 |
|
| 543 |
if ( empty( $campaign_ids ) ) { |
| 544 |
return false; |
| 545 |
} |
| 546 |
|
| 547 |
// Remove duplicates. |
| 548 |
$campaign_ids = array_unique( $campaign_ids ); |
| 549 |
|
| 550 |
foreach ( $campaign_ids as $campaign_id ) { |
| 551 |
|
| 552 |
$campaign = charitable_get_campaign( $campaign_id ); |
| 553 |
|
| 554 |
if ( $campaign->can_receive_donations() && 'modal' === charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 555 |
charitable_template( 'campaign/donate-modal-window.php', array( 'campaign' => $campaign ) ); |
| 556 |
} |
| 557 |
|
| 558 |
} |
| 559 |
|
| 560 |
return true; |
| 561 |
} |
| 562 |
|
| 563 |
endif; |
| 564 |
|
| 565 |
if ( ! function_exists( 'charitable_extract_campaign_ids_from_elementor_data' ) ) : |
| 566 |
|
| 567 |
/** |
| 568 |
* Recursively extract campaign IDs from Elementor data. |
| 569 |
* |
| 570 |
* @since 1.8.7.1 |
| 571 |
* |
| 572 |
* @param array $data Elementor data array. |
| 573 |
* @return array |
| 574 |
*/ |
| 575 |
function charitable_extract_campaign_ids_from_elementor_data( $data ) { |
| 576 |
$campaign_ids = array(); |
| 577 |
|
| 578 |
foreach ( $data as $element ) { |
| 579 |
if ( ! is_array( $element ) ) { |
| 580 |
continue; |
| 581 |
} |
| 582 |
|
| 583 |
// Check if this is a Charitable widget. |
| 584 |
if ( isset( $element['widgetType'] ) ) { |
| 585 |
$widget_type = $element['widgetType']; |
| 586 |
|
| 587 |
// Check for Charitable campaign widgets. |
| 588 |
if ( in_array( $widget_type, array( 'charitable_campaign', 'charitable_button', 'charitable_donation_form' ) ) ) { |
| 589 |
if ( isset( $element['settings']['campaign_id'] ) && ! empty( $element['settings']['campaign_id'] ) ) { |
| 590 |
$campaign_ids[] = absint( $element['settings']['campaign_id'] ); |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
// Recursively check child elements. |
| 596 |
if ( isset( $element['elements'] ) && is_array( $element['elements'] ) ) { |
| 597 |
$child_campaign_ids = charitable_extract_campaign_ids_from_elementor_data( $element['elements'] ); |
| 598 |
$campaign_ids = array_merge( $campaign_ids, $child_campaign_ids ); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
return $campaign_ids; |
| 603 |
} |
| 604 |
|
| 605 |
endif; |
| 606 |
|
| 607 |
// ////////////////////////////// |
| 608 |
// CAMPAIGN LOOP |
| 609 |
// ////////////////////////////// |
| 610 |
if ( ! function_exists( 'charitable_template_campaign_loop' ) ) : |
| 611 |
|
| 612 |
/** |
| 613 |
* Display the campaign loop. |
| 614 |
* |
| 615 |
* This is used instead of the_content filter. |
| 616 |
* |
| 617 |
* @since 1.0.0 |
| 618 |
* |
| 619 |
* @param WP_Query $campaigns Query with campaigns. |
| 620 |
* @param int $columns Number of columns to use for loop. |
| 621 |
* @return void |
| 622 |
*/ |
| 623 |
function charitable_template_campaign_loop( $campaigns = false, $columns = 1 ) { |
| 624 |
if ( ! $campaigns ) { |
| 625 |
global $wp_query; |
| 626 |
$campaigns = $wp_query; |
| 627 |
} |
| 628 |
|
| 629 |
charitable_template( |
| 630 |
'campaign-loop.php', |
| 631 |
array( |
| 632 |
'campaigns' => $campaigns, |
| 633 |
'columns' => $columns, |
| 634 |
) |
| 635 |
); |
| 636 |
} |
| 637 |
|
| 638 |
endif; |
| 639 |
|
| 640 |
if ( ! function_exists( 'charitable_template_responsive_styles' ) ) : |
| 641 |
|
| 642 |
/** |
| 643 |
* Add responsive styles for the campaign loop. |
| 644 |
* |
| 645 |
* @since 1.4.0 |
| 646 |
* @version 1.8.9.1 |
| 647 |
* |
| 648 |
* @param WP_Query $campaigns The campaigns that will be displayed. |
| 649 |
* @param array $args The view arguments. |
| 650 |
* @return void |
| 651 |
*/ |
| 652 |
function charitable_template_responsive_styles( $campaigns, $args ) { |
| 653 |
if ( ! isset( $args['responsive'] ) || ! $args['responsive'] || is_admin() ) { |
| 654 |
return; |
| 655 |
} |
| 656 |
|
| 657 |
// Check if we're in Elementor editor or preview mode |
| 658 |
$is_elementor = false; |
| 659 |
if ( class_exists( '\Elementor\Plugin' ) ) { |
| 660 |
$is_elementor = \Elementor\Plugin::$instance->editor->is_edit_mode() || \Elementor\Plugin::$instance->preview->is_preview_mode(); |
| 661 |
} |
| 662 |
|
| 663 |
// If we're in Elementor, don't output inline styles |
| 664 |
if ( $is_elementor ) { |
| 665 |
return; |
| 666 |
} |
| 667 |
|
| 668 |
$breakpoint = '768px'; |
| 669 |
|
| 670 |
if ( preg_match( '/[px|em]/', $args['responsive'] ) ) { |
| 671 |
$breakpoint = $args['responsive']; |
| 672 |
} |
| 673 |
?> |
| 674 |
<style type="text/css" media="screen"> |
| 675 |
@media only screen and (max-width: <?php echo esc_attr( $breakpoint ); ?>) { |
| 676 |
.campaign-loop.campaign-grid.masonry { -moz-column-count: 1; -webkit-column-count: 1; column-count: 1; } |
| 677 |
.campaign-loop.campaign-grid .campaign,.campaign-loop.campaign-grid .campaign.hentry { width: 100% !important; } |
| 678 |
} |
| 679 |
</style> |
| 680 |
<?php |
| 681 |
} |
| 682 |
|
| 683 |
endif; |
| 684 |
|
| 685 |
if ( ! function_exists( 'charitable_template_campaign_loop_thumbnail' ) ) : |
| 686 |
|
| 687 |
/** |
| 688 |
* Output the campaign thumbnail on campaigns displayed within the loop. |
| 689 |
* |
| 690 |
* @since 1.0.0 |
| 691 |
* |
| 692 |
* @param Charitable_Campaign $campaign The campaign object. |
| 693 |
* @return void |
| 694 |
*/ |
| 695 |
function charitable_template_campaign_loop_thumbnail( $campaign ) { |
| 696 |
charitable_template( 'campaign-loop/thumbnail.php', array( 'campaign' => $campaign ) ); |
| 697 |
} |
| 698 |
|
| 699 |
endif; |
| 700 |
|
| 701 |
if ( ! function_exists( 'charitable_template_campaign_loop_donation_stats' ) ) : |
| 702 |
|
| 703 |
/** |
| 704 |
* Output the campaign donation status on campaigns displayed within the loop. |
| 705 |
* |
| 706 |
* @since 1.0.0 |
| 707 |
* |
| 708 |
* @param Charitable_Campaign $campaign The campaign object. |
| 709 |
* @return void |
| 710 |
*/ |
| 711 |
function charitable_template_campaign_loop_donation_stats( $campaign ) { |
| 712 |
charitable_template( 'campaign-loop/donation-stats.php', array( 'campaign' => $campaign ) ); |
| 713 |
} |
| 714 |
|
| 715 |
endif; |
| 716 |
|
| 717 |
if ( ! function_exists( 'charitable_template_campaign_loop_donate_link' ) ) : |
| 718 |
|
| 719 |
/** |
| 720 |
* Output the campaign donation status on campaigns displayed within the loop. |
| 721 |
* |
| 722 |
* @since 1.0.0 |
| 723 |
* |
| 724 |
* @param Charitable_Campaign $campaign The campaign object. |
| 725 |
* @param mixed[] $args Optional arguments. |
| 726 |
* @return void |
| 727 |
*/ |
| 728 |
function charitable_template_campaign_loop_donate_link( $campaign, $args = array() ) { |
| 729 |
if ( isset( $args['button'] ) && 'donate' != $args['button'] ) { |
| 730 |
return; |
| 731 |
} |
| 732 |
|
| 733 |
$campaign->donate_button_loop_template(); |
| 734 |
} |
| 735 |
|
| 736 |
endif; |
| 737 |
|
| 738 |
if ( ! function_exists( 'charitable_template_campaign_loop_more_link' ) ) : |
| 739 |
|
| 740 |
/** |
| 741 |
* Output the read more link on campaigns displayed within the loop. |
| 742 |
* |
| 743 |
* @since 1.2.3 |
| 744 |
* |
| 745 |
* @param Charitable_Campaign $campaign The campaign object. |
| 746 |
* @param mixed[] $args Optional arguments. |
| 747 |
* @return void |
| 748 |
*/ |
| 749 |
function charitable_template_campaign_loop_more_link( $campaign, $args = array() ) { |
| 750 |
if ( ! isset( $args['button'] ) || 'details' !== $args['button'] ) { |
| 751 |
return; |
| 752 |
} |
| 753 |
|
| 754 |
charitable_template( 'campaign-loop/more-link.php', array( 'campaign' => $campaign ) ); |
| 755 |
} |
| 756 |
|
| 757 |
endif; |
| 758 |
|
| 759 |
if ( ! function_exists( 'charitable_template_campaign_loop_add_modal' ) ) : |
| 760 |
|
| 761 |
/** |
| 762 |
* Checks if the modal option is enabled and hooks the modal template up to wp_footer if it is. |
| 763 |
* |
| 764 |
* @since 1.2.3 |
| 765 |
* |
| 766 |
* @return void |
| 767 |
*/ |
| 768 |
function charitable_template_campaign_loop_add_modal() { |
| 769 |
if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 770 |
add_action( 'wp_footer', 'charitable_template_campaign_loop_modal_donation_window' ); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
endif; |
| 775 |
|
| 776 |
if ( ! function_exists( 'charitable_template_campaign_loop_modal_donation_window' ) ) : |
| 777 |
|
| 778 |
/** |
| 779 |
* Adds the modal donation window to the campaign loop. |
| 780 |
* |
| 781 |
* @since 1.2.3 |
| 782 |
* |
| 783 |
* @return void |
| 784 |
*/ |
| 785 |
function charitable_template_campaign_loop_modal_donation_window() { |
| 786 |
charitable_template( 'campaign-loop/donate-modal-window.php' ); |
| 787 |
} |
| 788 |
|
| 789 |
endif; |
| 790 |
|
| 791 |
/* DONATION FORM */ |
| 792 |
|
| 793 |
|
| 794 |
if ( ! function_exists( 'charitable_template_donation_form' ) ) : |
| 795 |
|
| 796 |
/** |
| 797 |
* Display a campaign's donation form. |
| 798 |
* |
| 799 |
* @since 1.6.55 |
| 800 |
* @since 1.8.3.5 Added get_form_template(). |
| 801 |
* |
| 802 |
* @param int $campaign_id The campaign ID. |
| 803 |
* @param array $args Args to pass to the view. |
| 804 |
* @return false|void |
| 805 |
*/ |
| 806 |
function charitable_template_donation_form( $campaign_id, $args = array() ) { |
| 807 |
if ( Charitable::CAMPAIGN_POST_TYPE !== get_post_type( $campaign_id ) ) { |
| 808 |
return false; |
| 809 |
} |
| 810 |
|
| 811 |
if ( ! array_key_exists( 'campaign_id', $args ) ) { |
| 812 |
$args['campaign_id'] = $campaign_id; |
| 813 |
} |
| 814 |
|
| 815 |
if ( ! charitable_campaign_can_receive_donations( $args['campaign_id'] ) ) { |
| 816 |
return false; |
| 817 |
} |
| 818 |
|
| 819 |
$donation_id = get_query_var( 'donation_id', false ); |
| 820 |
|
| 821 |
/* If a donation ID is included, make sure it belongs to the current user. */ |
| 822 |
if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) { |
| 823 |
return false; |
| 824 |
} |
| 825 |
|
| 826 |
if ( ! wp_script_is( 'charitable-script', 'enqueued' ) ) { |
| 827 |
Charitable_Public::get_instance()->enqueue_donation_form_scripts(); |
| 828 |
} |
| 829 |
|
| 830 |
$form = charitable_get_campaign( $campaign_id )->get_donation_form(); |
| 831 |
|
| 832 |
/** |
| 833 |
* Do something before rendering the donation form. |
| 834 |
* |
| 835 |
* @since 1.0.0 |
| 836 |
* |
| 837 |
* @param Charitable_Donation_Form $form The donation form instance. |
| 838 |
*/ |
| 839 |
do_action( 'charitable_donation_form_before', $form ); |
| 840 |
|
| 841 |
$args['form'] = $form; |
| 842 |
$args['form_template'] = $form->get_form_template(); |
| 843 |
$args['campaign'] = $form->get_campaign(); |
| 844 |
|
| 845 |
charitable_template( 'donation-form/form-donation.php', $args ); |
| 846 |
|
| 847 |
/** |
| 848 |
* Do something after rendering the donation form. |
| 849 |
* |
| 850 |
* @since 1.0.0 |
| 851 |
* |
| 852 |
* @param Charitable_Donation_Form $form The donation form instance. |
| 853 |
*/ |
| 854 |
do_action( 'charitable_donation_form_after', $form ); |
| 855 |
} |
| 856 |
|
| 857 |
endif; |
| 858 |
|
| 859 |
// ////////////////////////////// |
| 860 |
// DONATION RECEIPT |
| 861 |
// ////////////////////////////// |
| 862 |
if ( ! function_exists( 'charitable_template_donation_receipt_content' ) ) : |
| 863 |
|
| 864 |
/** |
| 865 |
* Display the donation form. This is used with the_content filter. |
| 866 |
* |
| 867 |
* @since 1.0.0 |
| 868 |
* |
| 869 |
* @param string $content Page content. |
| 870 |
* @return string |
| 871 |
*/ |
| 872 |
function charitable_template_donation_receipt_content( $content ) { |
| 873 |
|
| 874 |
if ( ! in_the_loop() || ! charitable_is_page( 'donation_receipt_page' ) ) { |
| 875 |
return $content; |
| 876 |
} |
| 877 |
|
| 878 |
/* If we are NOT using the automatic option, this is a static page with the shortcode, so don't filter again. */ |
| 879 |
if ( 'auto' != charitable_get_option( 'donation_receipt_page', 'auto' ) ) { |
| 880 |
return $content; |
| 881 |
} |
| 882 |
|
| 883 |
return charitable_template_donation_receipt_output( $content ); |
| 884 |
} |
| 885 |
|
| 886 |
endif; |
| 887 |
|
| 888 |
if ( ! function_exists( 'charitable_template_donation_receipt_output' ) ) : |
| 889 |
|
| 890 |
/** |
| 891 |
* Render the donation receipt. This can be used by the [donation_receipt] shortcode or through `the_content` filter. |
| 892 |
* |
| 893 |
* @since 1.0.0 |
| 894 |
* @since 1.5.0 Added $donation argument. |
| 895 |
* |
| 896 |
* @param string $content Page content. |
| 897 |
* @param Charitable_Donation|null $donation Optional. Useful when the donation is not the current donation. |
| 898 |
* @return string |
| 899 |
*/ |
| 900 |
function charitable_template_donation_receipt_output( $content, $donation = null ) { |
| 901 |
if ( is_null( $donation ) ) { |
| 902 |
$donation = charitable_get_current_donation(); |
| 903 |
} |
| 904 |
|
| 905 |
if ( ! $donation || 'simple' != $donation->get_donation_type() ) { |
| 906 |
return $content; |
| 907 |
} |
| 908 |
|
| 909 |
ob_start(); |
| 910 |
|
| 911 |
if ( ! $donation->is_from_current_user() ) { |
| 912 |
charitable_template_from_session( |
| 913 |
'donation-receipt/not-authorized.php', |
| 914 |
array( 'content' => $content ), |
| 915 |
'donation_receipt', |
| 916 |
array( 'donation_id' => $donation->ID ) |
| 917 |
); |
| 918 |
|
| 919 |
return ob_get_clean(); |
| 920 |
} |
| 921 |
|
| 922 |
do_action( 'charitable_donation_receipt_page', $donation ); |
| 923 |
|
| 924 |
charitable_template( |
| 925 |
'content-donation-receipt.php', |
| 926 |
array( |
| 927 |
'content' => $content, |
| 928 |
'donation' => $donation, |
| 929 |
) |
| 930 |
); |
| 931 |
|
| 932 |
$content = ob_get_clean(); |
| 933 |
|
| 934 |
return $content; |
| 935 |
} |
| 936 |
|
| 937 |
endif; |
| 938 |
|
| 939 |
if ( ! function_exists( 'charitable_template_donation_receipt_summary' ) ) : |
| 940 |
|
| 941 |
/** |
| 942 |
* Display the donation receipt summary. |
| 943 |
* |
| 944 |
* @since 1.0.0 |
| 945 |
* |
| 946 |
* @param Charitable_Donation $donation The Donation object. |
| 947 |
* @return void |
| 948 |
*/ |
| 949 |
function charitable_template_donation_receipt_summary( Charitable_Donation $donation ) { |
| 950 |
charitable_template( 'donation-receipt/summary.php', array( 'donation' => $donation ) ); |
| 951 |
} |
| 952 |
|
| 953 |
endif; |
| 954 |
|
| 955 |
if ( ! function_exists( 'charitable_template_donation_receipt_offline_payment_instructions' ) ) : |
| 956 |
|
| 957 |
/** |
| 958 |
* Display the offline payment instructions, if applicable. |
| 959 |
* |
| 960 |
* @since 1.0.0 |
| 961 |
* |
| 962 |
* @param Charitable_Donation $donation The Donation object. |
| 963 |
* @return void |
| 964 |
*/ |
| 965 |
function charitable_template_donation_receipt_offline_payment_instructions( Charitable_Donation $donation ) { |
| 966 |
if ( 'offline' != $donation->get_gateway() ) { |
| 967 |
return; |
| 968 |
} |
| 969 |
|
| 970 |
charitable_template( 'donation-receipt/offline-payment-instructions.php', array( 'donation' => $donation ) ); |
| 971 |
} |
| 972 |
|
| 973 |
endif; |
| 974 |
|
| 975 |
if ( ! function_exists( 'charitable_template_donation_receipt_details' ) ) : |
| 976 |
|
| 977 |
/** |
| 978 |
* Display the donation details. |
| 979 |
* |
| 980 |
* @since 1.0.0 |
| 981 |
* |
| 982 |
* @param Charitable_Donation $donation The Donation object. |
| 983 |
* @return void |
| 984 |
*/ |
| 985 |
function charitable_template_donation_receipt_details( Charitable_Donation $donation ) { |
| 986 |
charitable_template( 'donation-receipt/details.php', array( 'donation' => $donation ) ); |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
endif; |
| 991 |
|
| 992 |
// ////////////////////////////// |
| 993 |
// DONATION FORM |
| 994 |
// ////////////////////////////// |
| 995 |
if ( ! function_exists( 'charitable_template_donation_form_content' ) ) : |
| 996 |
|
| 997 |
/** |
| 998 |
* Display the donation form. This is used with the_content filter. |
| 999 |
* |
| 1000 |
* @since 1.0.0 |
| 1001 |
* |
| 1002 |
* @param string $content Page content. |
| 1003 |
* @return string |
| 1004 |
*/ |
| 1005 |
function charitable_template_donation_form_content( $content ) { |
| 1006 |
|
| 1007 |
if ( ! charitable_is_main_loop() || ! charitable_is_page( 'campaign_donation_page' ) ) { |
| 1008 |
return $content; |
| 1009 |
} |
| 1010 |
|
| 1011 |
if ( 'separate_page' != charitable_get_option( 'donation_form_display', 'separate_page' ) |
| 1012 |
&& false === get_query_var( 'donate', false ) ) { |
| 1013 |
return $content; |
| 1014 |
} |
| 1015 |
|
| 1016 |
ob_start(); |
| 1017 |
|
| 1018 |
charitable_template( 'content-donation-form.php' ); |
| 1019 |
|
| 1020 |
return ob_get_clean(); |
| 1021 |
} |
| 1022 |
|
| 1023 |
endif; |
| 1024 |
|
| 1025 |
if ( ! function_exists( 'charitable_template_donation_form_login' ) ) : |
| 1026 |
|
| 1027 |
/** |
| 1028 |
* Display a prompt to login at the start of the user fields block. |
| 1029 |
* |
| 1030 |
* @since 1.0.0 |
| 1031 |
* @version 1.8.2 |
| 1032 |
* |
| 1033 |
* @param Charitable_Donation_Form_Interface $form The donation form object. |
| 1034 |
* @return void |
| 1035 |
*/ |
| 1036 |
function charitable_template_donation_form_login( Charitable_Donation_Form_Interface $form ) { |
| 1037 |
$user = $form->get_user(); |
| 1038 |
|
| 1039 |
if ( $user ) { |
| 1040 |
return; |
| 1041 |
} |
| 1042 |
|
| 1043 |
$allow_login_form = apply_filters( 'charitable_donation_form_login_allow', true ); |
| 1044 |
|
| 1045 |
if ( ! $allow_login_form ) { |
| 1046 |
return; |
| 1047 |
} |
| 1048 |
|
| 1049 |
if ( '0' !== charitable_get_option( 'donation_form_show_login_message', '1' ) ) { |
| 1050 |
charitable_template( 'donation-form/donor-fields/login-form.php' ); |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
endif; |
| 1055 |
|
| 1056 |
if ( ! function_exists( 'charitable_template_donation_form_donor_details' ) ) : |
| 1057 |
|
| 1058 |
/** |
| 1059 |
* Display the donor's saved details if the user is logged in. |
| 1060 |
* |
| 1061 |
* @since 1.0.0 |
| 1062 |
* |
| 1063 |
* @param Charitable_Donation_Form_Interface $form The donation form object. |
| 1064 |
* @return void |
| 1065 |
*/ |
| 1066 |
function charitable_template_donation_form_donor_details( Charitable_Donation_Form_Interface $form ) { |
| 1067 |
/* Verify that the user is logged in and has all required fields filled out */ |
| 1068 |
if ( ! $form->should_hide_user_fields() ) { |
| 1069 |
return; |
| 1070 |
} |
| 1071 |
|
| 1072 |
charitable_template( 'donation-form/donor-fields/donor-details.php', array( 'user' => $form->get_user() ) ); |
| 1073 |
} |
| 1074 |
|
| 1075 |
endif; |
| 1076 |
|
| 1077 |
if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_start' ) ) : |
| 1078 |
|
| 1079 |
/** |
| 1080 |
* If the user is logged in, adds a wrapper around the donor fields that hide them. |
| 1081 |
* |
| 1082 |
* @since 1.0.0 |
| 1083 |
* |
| 1084 |
* @param Charitable_Donation_Form_Interface $form The donation form object. |
| 1085 |
* @return void |
| 1086 |
*/ |
| 1087 |
function charitable_template_donation_form_donor_fields_hidden_wrapper_start( Charitable_Donation_Form_Interface $form ) { |
| 1088 |
/* Verify that the user is logged in and has all required fields filled out */ |
| 1089 |
if ( ! $form->should_hide_user_fields() ) { |
| 1090 |
return; |
| 1091 |
} |
| 1092 |
|
| 1093 |
charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-start.php' ); |
| 1094 |
} |
| 1095 |
|
| 1096 |
endif; |
| 1097 |
|
| 1098 |
if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_end' ) ) : |
| 1099 |
|
| 1100 |
/** |
| 1101 |
* Closes the hidden donor fields wrapper div if the user is logged in. |
| 1102 |
* |
| 1103 |
* @since 1.0.0 |
| 1104 |
* |
| 1105 |
* @param Charitable_Donation_Form_Interface $form The donation form object. |
| 1106 |
* @return void |
| 1107 |
*/ |
| 1108 |
function charitable_template_donation_form_donor_fields_hidden_wrapper_end( Charitable_Donation_Form_Interface $form ) { |
| 1109 |
/* Verify that the user is logged in and has all required fields filled out */ |
| 1110 |
if ( ! $form->should_hide_user_fields() ) { |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
|
| 1114 |
charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-end.php' ); |
| 1115 |
} |
| 1116 |
|
| 1117 |
endif; |
| 1118 |
|
| 1119 |
if ( ! function_exists( 'charitable_template_donation_form_current_amount_text' ) ) : |
| 1120 |
|
| 1121 |
/** |
| 1122 |
* Display the amount currently selected to donate. |
| 1123 |
* |
| 1124 |
* @since 1.5.0 |
| 1125 |
* |
| 1126 |
* @param int|float $amount The current donation amount. |
| 1127 |
* @param string $form_id The current form ID. |
| 1128 |
* @param string $campaign_id The current campaign ID. |
| 1129 |
* @return string |
| 1130 |
*/ |
| 1131 |
function charitable_template_donation_form_current_amount_text( $amount, $form_id, $campaign_id ) { |
| 1132 |
if ( ! $amount ) { |
| 1133 |
return ''; |
| 1134 |
} |
| 1135 |
|
| 1136 |
/** |
| 1137 |
* Format the donation amount. |
| 1138 |
* |
| 1139 |
* @since 1.4.14 |
| 1140 |
* @since 1.5.0 Third parameter has been changed from an instance of |
| 1141 |
* `Charitable_Donation_Form` to a campaign ID. |
| 1142 |
* @since 1.8.3.6 Added <div> wrapper. |
| 1143 |
* |
| 1144 |
* @param string $amount_formatted The formatted amount. |
| 1145 |
* @param int|float $amount The raw amount. |
| 1146 |
* @param int $campaign_id Campaign ID. |
| 1147 |
*/ |
| 1148 |
$amount_formatted = apply_filters( 'charitable_session_donation_amount_formatted', charitable_format_money( $amount, false, true ), $amount, $campaign_id ); |
| 1149 |
|
| 1150 |
$content = '<div class="charitable-your-donation-amount"><p>'; |
| 1151 |
/* translators: %s: donation amount */ |
| 1152 |
$content .= sprintf( __( 'Your Donation Amount: %s.', 'charitable' ), '<strong>' . $amount_formatted . '</strong>' ); |
| 1153 |
$content .= ' <a href="#" class="change-donation" data-charitable-toggle="charitable-donation-options-' . esc_attr( $form_id ) . '">' . __( 'Change', 'charitable' ) . '</a>'; |
| 1154 |
$content .= '</div></p>'; |
| 1155 |
|
| 1156 |
return $content; |
| 1157 |
} |
| 1158 |
|
| 1159 |
endif; |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
// ////////////////////////////// |
| 1164 |
// DONATION PROCESSING PAGE |
| 1165 |
// ////////////////////////////// |
| 1166 |
if ( ! function_exists( 'charitable_template_donation_processing_content' ) ) : |
| 1167 |
|
| 1168 |
/** |
| 1169 |
* Render the content of the donation processing page. |
| 1170 |
* |
| 1171 |
* @since 1.2.0 |
| 1172 |
* |
| 1173 |
* @param string $content Default content to be rendered. |
| 1174 |
* @return string |
| 1175 |
*/ |
| 1176 |
function charitable_template_donation_processing_content( $content ) { |
| 1177 |
if ( ! charitable_is_page( 'donation_processing_page' ) ) { |
| 1178 |
return $content; |
| 1179 |
} |
| 1180 |
|
| 1181 |
$donation = charitable_get_current_donation(); |
| 1182 |
|
| 1183 |
if ( ! $donation ) { |
| 1184 |
return $content; |
| 1185 |
} |
| 1186 |
|
| 1187 |
$content = apply_filters( 'charitable_processing_donation_' . $donation->get_gateway(), $content, $donation ); |
| 1188 |
|
| 1189 |
return $content; |
| 1190 |
} |
| 1191 |
|
| 1192 |
endif; |
| 1193 |
|
| 1194 |
// ////////////////////////////// |
| 1195 |
// ACCOUNT PAGES |
| 1196 |
// ////////////////////////////// |
| 1197 |
if ( ! function_exists( 'charitable_template_forgot_password_content' ) ) : |
| 1198 |
|
| 1199 |
/** |
| 1200 |
* Render the content of the forgot password page. |
| 1201 |
* |
| 1202 |
* @since 1.4.0 |
| 1203 |
* |
| 1204 |
* @param string $content Default content to be rendered. |
| 1205 |
* @return string |
| 1206 |
*/ |
| 1207 |
function charitable_template_forgot_password_content( $content = '' ) { |
| 1208 |
if ( ! charitable_is_page( 'forgot_password_page' ) ) { |
| 1209 |
return $content; |
| 1210 |
} |
| 1211 |
|
| 1212 |
ob_start(); |
| 1213 |
|
| 1214 |
if ( isset( $_GET['email_sent'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 1215 |
|
| 1216 |
charitable_template( 'account/forgot-password-sent.php' ); |
| 1217 |
|
| 1218 |
} else { |
| 1219 |
|
| 1220 |
charitable_template( |
| 1221 |
'account/forgot-password.php', |
| 1222 |
array( |
| 1223 |
'form' => new Charitable_Forgot_Password_Form(), |
| 1224 |
) |
| 1225 |
); |
| 1226 |
|
| 1227 |
} |
| 1228 |
|
| 1229 |
$content = ob_get_clean(); |
| 1230 |
|
| 1231 |
return $content; |
| 1232 |
} |
| 1233 |
|
| 1234 |
endif; |
| 1235 |
|
| 1236 |
if ( ! function_exists( 'charitable_template_reset_password_content' ) ) : |
| 1237 |
|
| 1238 |
/** |
| 1239 |
* Render the content of the reset password page. |
| 1240 |
* |
| 1241 |
* @since 1.4.0 |
| 1242 |
* |
| 1243 |
* @param string $content Default content to be rendered. |
| 1244 |
* @return string |
| 1245 |
*/ |
| 1246 |
function charitable_template_reset_password_content( $content = '' ) { |
| 1247 |
if ( ! charitable_is_page( 'reset_password_page' ) ) { |
| 1248 |
return $content; |
| 1249 |
} |
| 1250 |
|
| 1251 |
ob_start(); |
| 1252 |
|
| 1253 |
charitable_template( |
| 1254 |
'account/reset-password.php', |
| 1255 |
array( |
| 1256 |
'form' => new Charitable_Reset_Password_Form(), |
| 1257 |
) |
| 1258 |
); |
| 1259 |
|
| 1260 |
$content = ob_get_clean(); |
| 1261 |
|
| 1262 |
return $content; |
| 1263 |
} |
| 1264 |
|
| 1265 |
endif; |
| 1266 |
|
| 1267 |
if ( ! function_exists( 'charitable_template_form_login_link' ) ) : |
| 1268 |
|
| 1269 |
/** |
| 1270 |
* Display a link to the login form. |
| 1271 |
* |
| 1272 |
* @since 1.4.2 |
| 1273 |
* @version 1.8.9.1 |
| 1274 |
* |
| 1275 |
* @param Charitable_Registration_Form|null $form Instance of `Charitable_Registration_Form`, or |
| 1276 |
* null in previous versions of Charitable. |
| 1277 |
* @return void |
| 1278 |
*/ |
| 1279 |
function charitable_template_form_login_link( $form = null ) { |
| 1280 |
/** |
| 1281 |
* For backwards compatibility, since previously the |
| 1282 |
* Form object was not passed to the hook. |
| 1283 |
*/ |
| 1284 |
if ( is_null( $form ) ) { |
| 1285 |
return; |
| 1286 |
} |
| 1287 |
|
| 1288 |
if ( ! $form->get_login_link() ) { |
| 1289 |
return; |
| 1290 |
} |
| 1291 |
|
| 1292 |
printf( '<p>%s</p>', wp_kses_post( $form->get_login_link() ) ); |
| 1293 |
} |
| 1294 |
|
| 1295 |
endif; |
| 1296 |
|
| 1297 |
if ( ! function_exists( 'charitable_maybe_hide_campaign_percentage_raised' ) ) : |
| 1298 |
|
| 1299 |
/** |
| 1300 |
* Determine if a campaign setting says to hide this. Return true to show, false to hide. |
| 1301 |
* |
| 1302 |
* @since 1.7.0.8 |
| 1303 |
* |
| 1304 |
* @param boolean $current_value Current value of boolean passed in. |
| 1305 |
* @param Charitable_Campaign $campaign The campaign object. |
| 1306 |
* @return boolean |
| 1307 |
*/ |
| 1308 |
function charitable_maybe_hide_campaign_percentage_raised( $current_value = true, $campaign = false ) { |
| 1309 |
|
| 1310 |
if ( false === $campaign || 0 === $campaign->get_campaign_id() ) { |
| 1311 |
return $current_value; |
| 1312 |
} |
| 1313 |
|
| 1314 |
$campaign_hide_percent_raised = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_percent_raised', true ); |
| 1315 |
|
| 1316 |
if ( false === $campaign_hide_percent_raised || empty( $campaign_hide_percent_raised ) ) { |
| 1317 |
return $current_value; |
| 1318 |
} |
| 1319 |
|
| 1320 |
if ( in_array( 'hide_percent_raised', $campaign_hide_percent_raised ) ) { |
| 1321 |
return false; // hide. |
| 1322 |
} |
| 1323 |
|
| 1324 |
return $current_value; |
| 1325 |
} |
| 1326 |
|
| 1327 |
endif; |
| 1328 |
|
| 1329 |
|
| 1330 |
if ( ! function_exists( 'charitable_maybe_hide_campaign_donor_count' ) ) : |
| 1331 |
|
| 1332 |
/** |
| 1333 |
* Determine if a campaign setting says to hide this. Return true to show, false to hide. |
| 1334 |
* |
| 1335 |
* @since 1.7.0.8 |
| 1336 |
* |
| 1337 |
* @param boolean $current_value Current value of boolean passed in. |
| 1338 |
* @param Charitable_Campaign $campaign The campaign object. |
| 1339 |
* |
| 1340 |
* @return boolean |
| 1341 |
*/ |
| 1342 |
function charitable_maybe_hide_campaign_donor_count( $current_value = true, $campaign = false ) { |
| 1343 |
|
| 1344 |
if ( false === $campaign || 0 === $campaign->get_campaign_id() ) { |
| 1345 |
return $current_value; |
| 1346 |
} |
| 1347 |
|
| 1348 |
$campaign_hide_donor_count = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_number_of_donors', true ); |
| 1349 |
|
| 1350 |
if ( false === $campaign_hide_donor_count || empty( $campaign_hide_donor_count ) ) { |
| 1351 |
return $current_value; |
| 1352 |
} |
| 1353 |
|
| 1354 |
if ( in_array( 'hide_number_of_donors', $campaign_hide_donor_count ) ) { |
| 1355 |
return false; // hide. |
| 1356 |
} |
| 1357 |
|
| 1358 |
return $current_value; |
| 1359 |
} |
| 1360 |
|
| 1361 |
endif; |
| 1362 |
|
| 1363 |
|
| 1364 |
if ( ! function_exists( 'charitable_maybe_hide_campaign_amount_donated' ) ) : |
| 1365 |
|
| 1366 |
/** |
| 1367 |
* Determine if a campaign setting says to hide this. Return true to show, false to hide. |
| 1368 |
* |
| 1369 |
* @since 1.7.0.8 |
| 1370 |
* |
| 1371 |
* @param boolean $current_value Current value of boolean passed in. |
| 1372 |
* @param Charitable_Campaign $campaign The campaign object. |
| 1373 |
* @param int $amount The amount donated. |
| 1374 |
* @param int $goal The campaign goal. |
| 1375 |
* @return boolean |
| 1376 |
*/ |
| 1377 |
function charitable_maybe_hide_campaign_amount_donated( $current_value, $campaign, $amount, $goal ) { // phpcs:ignore |
| 1378 |
|
| 1379 |
if ( false === $campaign || 0 === $campaign->get_campaign_id() ) { |
| 1380 |
return $current_value; |
| 1381 |
} |
| 1382 |
|
| 1383 |
$campaign_hide_amount_donated = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_amount_donated', true ); |
| 1384 |
|
| 1385 |
if ( false === $campaign_hide_amount_donated || empty( $campaign_hide_amount_donated ) ) { |
| 1386 |
return $current_value; |
| 1387 |
} |
| 1388 |
|
| 1389 |
if ( in_array( 'hide_amount_donated', $campaign_hide_amount_donated ) ) { |
| 1390 |
return false; // hide. |
| 1391 |
} |
| 1392 |
|
| 1393 |
return $current_value; |
| 1394 |
} |
| 1395 |
|
| 1396 |
endif; |
| 1397 |
|
| 1398 |
|
| 1399 |
if ( ! function_exists( 'charitable_maybe_hide_campaign_time_remaining' ) ) : |
| 1400 |
|
| 1401 |
/** |
| 1402 |
* Determine if a campaign setting says to hide this. Return true to show, false to hide. |
| 1403 |
* |
| 1404 |
* @since 1.7.0.8 |
| 1405 |
* |
| 1406 |
* @param boolean $current_value Current value of boolean passed in. |
| 1407 |
* @return boolean |
| 1408 |
*/ |
| 1409 |
function charitable_maybe_hide_campaign_time_remaining( $current_value = true, $campaign = false ) { |
| 1410 |
|
| 1411 |
if ( false === $campaign || 0 === $campaign->get_campaign_id() ) { |
| 1412 |
return $current_value; |
| 1413 |
} |
| 1414 |
|
| 1415 |
$campaign_hide_time_remaining = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_time_remaining', true ); |
| 1416 |
|
| 1417 |
if ( false === $campaign_hide_time_remaining || empty( $campaign_hide_time_remaining ) ) { |
| 1418 |
return $current_value; |
| 1419 |
} |
| 1420 |
|
| 1421 |
if ( in_array( 'hide_time_remaining', $campaign_hide_time_remaining ) ) { |
| 1422 |
return false; // hide. |
| 1423 |
} |
| 1424 |
|
| 1425 |
return $current_value; |
| 1426 |
} |
| 1427 |
|
| 1428 |
endif; |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
// ////////////////////////////// |
| 1433 |
// NOTICES |
| 1434 |
// ////////////////////////////// |
| 1435 |
if ( ! function_exists( 'charitable_template_notices' ) ) : |
| 1436 |
|
| 1437 |
/** |
| 1438 |
* Render any notices. |
| 1439 |
* |
| 1440 |
* @since 1.4.0 |
| 1441 |
* |
| 1442 |
* @param array $notices Optional. Notices to be rendered. |
| 1443 |
* @return void |
| 1444 |
*/ |
| 1445 |
function charitable_template_notices( $notices = array() ) { |
| 1446 |
if ( empty( $notices ) ) { |
| 1447 |
$notices = charitable_get_notices()->get_notices(); |
| 1448 |
} |
| 1449 |
|
| 1450 |
charitable_template_from_session( |
| 1451 |
'form-fields/notices.php', |
| 1452 |
array( |
| 1453 |
'notices' => $notices, |
| 1454 |
), |
| 1455 |
'notices' |
| 1456 |
); |
| 1457 |
} |
| 1458 |
|
| 1459 |
endif; |
| 1460 |
|
| 1461 |
if ( ! function_exists( 'charitable_is_campaign_legacy' ) ) : |
| 1462 |
|
| 1463 |
/** |
| 1464 |
* Determine if a campaign is using the legacy settings. |
| 1465 |
* |
| 1466 |
* @since 1.8.0 |
| 1467 |
* |
| 1468 |
* @param mixed $campaign The campaign to check. Can be a campaign ID, a campaign object, or an array with an 'id' key. |
| 1469 |
* @return bool True if the campaign is using the legacy settings, false otherwise. |
| 1470 |
*/ |
| 1471 |
function charitable_is_campaign_legacy( $campaign = false ) { |
| 1472 |
|
| 1473 |
if ( ! $campaign ) { |
| 1474 |
return true; |
| 1475 |
} |
| 1476 |
|
| 1477 |
if ( is_array( $campaign ) && ! empty( $campaign['id'] ) ) { |
| 1478 |
$campaign_id = intval( $campaign['id'] ); |
| 1479 |
} elseif ( is_int( $campaign ) ) { // a campaign ID. |
| 1480 |
$campaign_id = intval( $campaign ); |
| 1481 |
} elseif ( is_a( $campaign, 'Charitable_Campaign' ) ) { |
| 1482 |
$campaign_id = $campaign->__get( 'ID' ); |
| 1483 |
} else { |
| 1484 |
return true; |
| 1485 |
} |
| 1486 |
|
| 1487 |
$campaign_v2_settings = get_post_meta( $campaign_id, 'campaign_settings_v2', true ); |
| 1488 |
|
| 1489 |
return ! empty( $campaign_v2_settings ) ? false : true; |
| 1490 |
} |
| 1491 |
|
| 1492 |
endif; |
| 1493 |
|
| 1494 |
/** |
| 1495 |
* Filters the allowed HTML tags for campaign builder fields. |
| 1496 |
* |
| 1497 |
* @since 1.8.0 |
| 1498 |
* |
| 1499 |
* @param string|bool $text The text to filter. |
| 1500 |
* |
| 1501 |
* @return string|bool The filtered text. |
| 1502 |
*/ |
| 1503 |
function charitable_campaign_builder_filter_allowed_html( $text = false ) { |
| 1504 |
|
| 1505 |
$allowed_html_tags = apply_filters( |
| 1506 |
'charitable_campaign_builder_html_allowed_tags', |
| 1507 |
array( |
| 1508 |
'a' => [ |
| 1509 |
'href' => [], |
| 1510 |
'class' => [], |
| 1511 |
'target' => [], |
| 1512 |
], |
| 1513 |
'p' => [ |
| 1514 |
'class' => [], |
| 1515 |
], |
| 1516 |
'span' => [ |
| 1517 |
'class' => [], |
| 1518 |
], |
| 1519 |
'div' => [ |
| 1520 |
'class' => [], |
| 1521 |
], |
| 1522 |
'strong' => [ |
| 1523 |
'class' => [], |
| 1524 |
], |
| 1525 |
'em' => [ |
| 1526 |
'class' => [], |
| 1527 |
], |
| 1528 |
'b' => [ |
| 1529 |
'class' => [], |
| 1530 |
], |
| 1531 |
'i' => [ |
| 1532 |
'class' => [], |
| 1533 |
], |
| 1534 |
'h1' => [ |
| 1535 |
'class' => [], |
| 1536 |
], |
| 1537 |
'h2' => [ |
| 1538 |
'class' => [], |
| 1539 |
], |
| 1540 |
'h3' => [ |
| 1541 |
'class' => [], |
| 1542 |
], |
| 1543 |
'h4' => [ |
| 1544 |
'class' => [], |
| 1545 |
], |
| 1546 |
'h5' => [ |
| 1547 |
'class' => [], |
| 1548 |
], |
| 1549 |
'h6' => [ |
| 1550 |
'class' => [], |
| 1551 |
], |
| 1552 |
) |
| 1553 |
); |
| 1554 |
|
| 1555 |
return wp_kses( $text, $allowed_html_tags ); |
| 1556 |
} |
| 1557 |
|
| 1558 |
/** |
| 1559 |
* Returns the preview content for a given builder tab type. |
| 1560 |
* |
| 1561 |
* @since 1.8.0 |
| 1562 |
* |
| 1563 |
* @param string $type The type of builder tab. |
| 1564 |
* |
| 1565 |
* @return string The preview content. |
| 1566 |
*/ |
| 1567 |
function charitable_builder_tab_content_preview_by_type( $type = 'html' ) { |
| 1568 |
|
| 1569 |
switch ( $type ) { |
| 1570 |
|
| 1571 |
case 'discussion': |
| 1572 |
$output = ' |
| 1573 |
<div class="placeholder-row"> |
| 1574 |
<div class="placeholder-column avatar big"> |
| 1575 |
<span class="placeholder avatar big"></span> |
| 1576 |
</div> |
| 1577 |
<div class="placeholder-column"> |
| 1578 |
<span class="placeholder"></span> |
| 1579 |
<span class="placeholder"></span> |
| 1580 |
<span class="placeholder"></span> |
| 1581 |
</div> |
| 1582 |
</div> |
| 1583 |
<div class="placeholder-row"> |
| 1584 |
<div class="placeholder-column avatar big right"> |
| 1585 |
<span class="placeholder avatar"></span> |
| 1586 |
</div> |
| 1587 |
<div class="placeholder-column"> |
| 1588 |
<span class="placeholder"></span> |
| 1589 |
<span class="placeholder"></span> |
| 1590 |
<span class="placeholder"></span> |
| 1591 |
</div> |
| 1592 |
</div> |
| 1593 |
<div class="placeholder-row"> |
| 1594 |
<div class="placeholder-column avatar big"> |
| 1595 |
<span class="placeholder avatar big"></span> |
| 1596 |
</div> |
| 1597 |
<div class="placeholder-column"> |
| 1598 |
<span class="placeholder"></span> |
| 1599 |
<span class="placeholder"></span> |
| 1600 |
<span class="placeholder"></span> |
| 1601 |
</div> |
| 1602 |
</div> |
| 1603 |
<div class="placeholder-row"> |
| 1604 |
<div class="placeholder-column avatar big right"> |
| 1605 |
<span class="placeholder avatar"></span> |
| 1606 |
</div> |
| 1607 |
<div class="placeholder-column"> |
| 1608 |
<span class="placeholder"></span> |
| 1609 |
<span class="placeholder"></span> |
| 1610 |
<span class="placeholder"></span> |
| 1611 |
</div> |
| 1612 |
</div> |
| 1613 |
'; |
| 1614 |
break; |
| 1615 |
|
| 1616 |
case 'updates': |
| 1617 |
$output = ' |
| 1618 |
<div class="placeholder-row"> |
| 1619 |
<div class="placeholder-column avatar"> |
| 1620 |
<span class="placeholder avatar"></span> |
| 1621 |
</div> |
| 1622 |
<div class="placeholder-column"> |
| 1623 |
<span class="placeholder"></span> |
| 1624 |
<span class="placeholder"></span> |
| 1625 |
<span class="placeholder"></span> |
| 1626 |
</div> |
| 1627 |
</div> |
| 1628 |
<div class="placeholder-row"> |
| 1629 |
<div class="placeholder-column avatar"> |
| 1630 |
<span class="placeholder avatar"></span> |
| 1631 |
</div> |
| 1632 |
<div class="placeholder-column"> |
| 1633 |
<span class="placeholder"></span> |
| 1634 |
<span class="placeholder"></span> |
| 1635 |
<span class="placeholder"></span> |
| 1636 |
</div> |
| 1637 |
</div> |
| 1638 |
<div class="placeholder-row"> |
| 1639 |
<div class="placeholder-column avatar"> |
| 1640 |
<span class="placeholder avatar"></span> |
| 1641 |
</div> |
| 1642 |
<div class="placeholder-column"> |
| 1643 |
<span class="placeholder"></span> |
| 1644 |
<span class="placeholder"></span> |
| 1645 |
<span class="placeholder"></span> |
| 1646 |
</div> |
| 1647 |
</div> |
| 1648 |
<div class="placeholder-row"> |
| 1649 |
<div class="placeholder-column avatar"> |
| 1650 |
<span class="placeholder avatar"></span> |
| 1651 |
</div> |
| 1652 |
<div class="placeholder-column"> |
| 1653 |
<span class="placeholder"></span> |
| 1654 |
<span class="placeholder"></span> |
| 1655 |
<span class="placeholder"></span> |
| 1656 |
</div> |
| 1657 |
</div> |
| 1658 |
<div class="placeholder-row"> |
| 1659 |
<div class="placeholder-column avatar"> |
| 1660 |
<span class="placeholder avatar"></span> |
| 1661 |
</div> |
| 1662 |
<div class="placeholder-column"> |
| 1663 |
<span class="placeholder"></span> |
| 1664 |
<span class="placeholder"></span> |
| 1665 |
<span class="placeholder"></span> |
| 1666 |
</div> |
| 1667 |
</div> |
| 1668 |
'; |
| 1669 |
break; |
| 1670 |
|
| 1671 |
default: |
| 1672 |
$output = ''; |
| 1673 |
// $output = ' |
| 1674 |
|
| 1675 |
// <div> |
| 1676 |
// <span class="placeholder big"></span> |
| 1677 |
// </div> |
| 1678 |
// '; |
| 1679 |
break; |
| 1680 |
} |
| 1681 |
|
| 1682 |
return $output; |
| 1683 |
} |
| 1684 |
|