| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | +use Give\DonationForms\DonationQuery; | |
| 13 | 14 | use Give\Helpers\Form\Template\Utils\Frontend as FrontendFormTemplateUtils; |
| 14 | 15 | use Give\Helpers\Form\Utils as FormUtils; |
| 15 | 16 | use Give\Helpers\Frontend\ConfirmDonation; |
| 16 | 17 | use Give\Helpers\Frontend\Shortcode as ShortcodeUtils; |
| @@ -24,8 +25,10 @@ | ||
| 24 | 25 | * Donation History Shortcode |
| 25 | 26 | * |
| 26 | 27 | * Displays a user's donation history. |
| 27 | 28 | * |
| 29 | + * @since 3.7.0 Sanitize attributes | |
| 30 | + * @since 3.1.0 pass form id by reference in give_totals shortcode. | |
| 28 | 31 | * @since 1.0 |
| 29 | 32 | * |
| 30 | 33 | * @param array $atts |
| 31 | 34 | * @param string|bool $content |
| @@ -32,9 +35,9 @@ | ||
| 32 | 35 | * |
| 33 | 36 | * @return string|bool |
| 34 | 37 | */ |
| 35 | 38 | function give_donation_history( $atts, $content = false ) { |
| 36 | - | |
| 39 | + $atts = give_clean($atts); | |
| 37 | 40 | $donation_history_args = shortcode_atts( |
| 38 | 41 | [ |
| 39 | 42 | 'id' => true, |
| 40 | 43 | 'date' => true, |
| @@ -130,18 +133,27 @@ | ||
| 130 | 133 | * Donation Form Shortcode |
| 131 | 134 | * |
| 132 | 135 | * Show the Give donation form. |
| 133 | 136 | * |
| 137 | + * @since 4.3.0 Add check for 'modal' in display_style to allow v2 forms to be shown in a modal. | |
| 138 | + * @since 3.7.0 Sanitize attributes | |
| 139 | + * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status. | |
| 134 | 140 | * @since 2.30.0 Add short-circuit filter to allow for custom output. |
| 135 | 141 | * @since 1.0 |
| 136 | - | |
| 142 | + * | |
| 143 | + | |
| 137 | 144 | * @param array $atts Shortcode attributes |
| 138 | 145 | * |
| 139 | 146 | * @return string |
| 140 | 147 | */ |
| 141 | 148 | function give_form_shortcode( $atts ) { |
| 149 | + $atts = give_clean($atts); | |
| 142 | 150 | $atts = shortcode_atts( give_get_default_form_shortcode_args(), $atts, 'give_form' ); |
| 143 | 151 | |
| 152 | + if('fullForm' === $atts['display_style']) { | |
| 153 | + $atts['display_style'] = 'onpage'; | |
| 154 | + } | |
| 155 | + | |
| 144 | 156 | // Convert string to bool. |
| 145 | 157 | $atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN ); |
| 146 | 158 | $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN ); |
| 147 | 159 | |
| @@ -146,10 +158,27 @@ | ||
| 146 | 158 | $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN ); |
| 147 | 159 | |
| 148 | 160 | // Set form id. |
| 149 | 161 | $atts['id'] = $atts['id'] ?: FrontendFormTemplateUtils::getFormId(); |
| 150 | - $formId = absint( $atts['id'] ); | |
| 162 | + $formId = absint($atts['id']); | |
| 151 | 163 | |
| 164 | + if ( ! ShortcodeUtils::isValidForm($formId)) { | |
| 165 | + ob_start(); | |
| 166 | + Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'), | |
| 167 | + true); | |
| 168 | + | |
| 169 | + return ob_get_clean(); | |
| 170 | + } | |
| 171 | + | |
| 172 | + if ( ! ShortcodeUtils::isPublishedForm($formId)) { | |
| 173 | + ob_start(); | |
| 174 | + Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true); | |
| 175 | + | |
| 176 | + return ob_get_clean(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + _give_redirect_form_id($formId, $atts['id']); | |
| 180 | + | |
| 152 | 181 | // Short-circuit the shortcode output if the filter returns a non-empty string. |
| 153 | 182 | $output = apply_filters('givewp_form_shortcode_output', '', $atts); |
| 154 | 183 | |
| 155 | 184 | if ($output) { |
| @@ -159,9 +188,9 @@ | ||
| 159 | 188 | // Fetch the Give Form. |
| 160 | 189 | ob_start(); |
| 161 | 190 | |
| 162 | 191 | if ( ! FormUtils::isLegacyForm( $formId ) ) { |
| 163 | - $showIframeInModal = 'button' === $atts['display_style']; | |
| 192 | + $showIframeInModal = 'button' === $atts['display_style'] || 'modal' === $atts['display_style']; | |
| 164 | 193 | $iframeView = new IframeView(); |
| 165 | 194 | |
| 166 | 195 | ConfirmDonation::storePostedDataInDonationSession(); |
| 167 | 196 | |
| @@ -185,8 +214,11 @@ | ||
| 185 | 214 | * Donation Form Goal Shortcode. |
| 186 | 215 | * |
| 187 | 216 | * Show the Give donation form goals. |
| 188 | 217 | * |
| 218 | + * @since 3.12.0 add start_date and end_date attributes | |
| 219 | + * @since 3.7.0 Sanitize attributes | |
| 220 | + * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status. | |
| 189 | 221 | * @since 1.0 |
| 190 | 222 | * |
| 191 | 223 | * @param array $atts Shortcode attributes. |
| 192 | 224 | * |
| @@ -192,29 +224,38 @@ | ||
| 192 | 224 | * |
| 193 | 225 | * @return string |
| 194 | 226 | */ |
| 195 | 227 | function give_goal_shortcode( $atts ) { |
| 228 | + $atts = give_clean($atts); | |
| 196 | 229 | $atts = shortcode_atts( |
| 197 | 230 | [ |
| 198 | 231 | 'id' => '', |
| 199 | 232 | 'show_text' => true, |
| 200 | 233 | 'show_bar' => true, |
| 201 | - 'color' => '', | |
| 234 | + 'color' => '#66BB6A', | |
| 235 | + 'start_date' => '', | |
| 236 | + 'end_date' => '', | |
| 202 | 237 | ], |
| 203 | 238 | $atts, |
| 204 | 239 | 'give_goal' |
| 205 | 240 | ); |
| 206 | 241 | |
| 242 | + _give_redirect_form_id($atts['id']); | |
| 243 | + | |
| 207 | 244 | // get the Give Form. |
| 208 | 245 | ob_start(); |
| 209 | 246 | |
| 210 | - // Sanity check 1: ensure there is an ID Provided. | |
| 211 | - if ( empty( $atts['id'] ) ) { | |
| 212 | - Give_Notices::print_frontend_notice( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true ); | |
| 213 | - } | |
| 247 | + $formId = (int)$atts['id']; | |
| 214 | 248 | |
| 215 | - // Sanity check 2: Check the form even has Goals enabled. | |
| 216 | - if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) { | |
| 249 | + // Sanity check 1: ensure there is an ID Provided. | |
| 250 | + if ( ! ShortcodeUtils::isValidForm($formId)) { | |
| 251 | + Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'), | |
| 252 | + true); | |
| 253 | + } elseif // Sanity check 2: ensure the form is published. | |
| 254 | + ( ! ShortcodeUtils::isPublishedForm($formId)) { | |
| 255 | + Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true); | |
| 256 | + } elseif // Sanity check 3: Check the form even has Goals enabled. | |
| 257 | + ( ! give_is_setting_enabled(give_get_meta($atts['id'], '_give_goal_option', true))) { | |
| 217 | 258 | |
| 218 | 259 | Give_Notices::print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true ); |
| 219 | 260 | } else { |
| 220 | 261 | // Passed all sanity checks: output Goal. |
| @@ -234,8 +275,9 @@ | ||
| 234 | 275 | * |
| 235 | 276 | * Shows a login form allowing users to users to log in. This function simply |
| 236 | 277 | * calls the give_login_form function to display the login form. |
| 237 | 278 | * |
| 279 | + * @since 3.7.0 Sanitize attributes | |
| 238 | 280 | * @since 1.0 |
| 239 | 281 | * |
| 240 | 282 | * @param array $atts Shortcode attributes. |
| 241 | 283 | * |
| @@ -243,9 +285,9 @@ | ||
| 243 | 285 | * |
| 244 | 286 | * @return string |
| 245 | 287 | */ |
| 246 | 288 | function give_login_form_shortcode( $atts ) { |
| 247 | - | |
| 289 | + $atts = give_clean($atts); | |
| 248 | 290 | $atts = shortcode_atts( |
| 249 | 291 | [ |
| 250 | 292 | // Add backward compatibility for redirect attribute. |
| 251 | 293 | 'redirect' => '', |
| @@ -268,8 +310,9 @@ | ||
| 268 | 310 | * Register Shortcode. |
| 269 | 311 | * |
| 270 | 312 | * Shows a registration form allowing users to users to register for the site. |
| 271 | 313 | * |
| 314 | + * @since 3.7.0 Sanitize attributes | |
| 272 | 315 | * @since 1.0 |
| 273 | 316 | * |
| 274 | 317 | * @param array $atts Shortcode attributes. |
| 275 | 318 | * |
| @@ -277,8 +320,9 @@ | ||
| 277 | 320 | * |
| 278 | 321 | * @return string |
| 279 | 322 | */ |
| 280 | 323 | function give_register_form_shortcode( $atts ) { |
| 324 | + $atts = give_clean($atts); | |
| 281 | 325 | $atts = shortcode_atts( |
| 282 | 326 | [ |
| 283 | 327 | 'redirect' => '', |
| 284 | 328 | ], |
| @@ -295,8 +339,10 @@ | ||
| 295 | 339 | * Receipt Shortcode. |
| 296 | 340 | * |
| 297 | 341 | * Shows a donation receipt. |
| 298 | 342 | * |
| 343 | + * @since 3.16.0 add give_donation_confirmation_page_enqueue_scripts | |
| 344 | + * @since 3.7.0 Sanitize and escape attributes | |
| 299 | 345 | * @since 1.0 |
| 300 | 346 | * |
| 301 | 347 | * @param array $atts Shortcode attributes. |
| 302 | 348 | * |
| @@ -305,8 +351,10 @@ | ||
| 305 | 351 | function give_receipt_shortcode( $atts ) { |
| 306 | 352 | |
| 307 | 353 | global $give_receipt_args; |
| 308 | 354 | |
| 355 | + $atts = give_clean($atts); | |
| 356 | + | |
| 309 | 357 | $give_receipt_args = shortcode_atts( |
| 310 | 358 | [ |
| 311 | 359 | 'error' => __( 'You are missing the donation id to view this donation receipt.', 'give' ), |
| 312 | 360 | 'price' => true, |
| @@ -343,15 +391,17 @@ | ||
| 343 | 391 | // Display donation receipt placeholder while loading receipt via AJAX. |
| 344 | 392 | if ( ! wp_doing_ajax() ) { |
| 345 | 393 | give_get_template_part( 'receipt/placeholder' ); |
| 346 | 394 | |
| 347 | - return sprintf( | |
| 395 | + do_action('give_donation_confirmation_page_enqueue_scripts'); | |
| 396 | + | |
| 397 | + return apply_filters('give_receipt_shortcode_output', sprintf( | |
| 348 | 398 | '<div id="give-receipt" data-shortcode="%1$s" data-receipt-type="%2$s" data-donation-key="%3$s" >%4$s</div>', |
| 349 | 399 | htmlspecialchars( wp_json_encode( $give_receipt_args ) ), |
| 350 | - $receipt_type, | |
| 351 | - $donation_id, | |
| 400 | + esc_attr($receipt_type), | |
| 401 | + esc_attr($donation_id), | |
| 352 | 402 | ob_get_clean() |
| 353 | - ); | |
| 403 | + )); | |
| 354 | 404 | } |
| 355 | 405 | |
| 356 | 406 | return give_display_donation_receipt( $atts ); |
| 357 | 407 | } |
| @@ -368,8 +418,9 @@ | ||
| 368 | 418 | * file called shortcode-profile-editor.php in the give_template directory in your active theme's |
| 369 | 419 | * folder. Please visit the Give Documentation for more information on how the |
| 370 | 420 | * templating system is used. |
| 371 | 421 | * |
| 422 | + * @since 3.7.0 Sanitize attributes | |
| 372 | 423 | * @since 1.0 |
| 373 | 424 | * |
| 374 | 425 | * @param array $atts Shortcode attributes. |
| 375 | 426 | * |
| @@ -376,8 +427,10 @@ | ||
| 376 | 427 | * @return string Output generated from the profile editor |
| 377 | 428 | */ |
| 378 | 429 | function give_profile_editor_shortcode( $atts ) { |
| 379 | 430 | |
| 431 | + $atts = give_clean($atts); | |
| 432 | + | |
| 380 | 433 | ob_start(); |
| 381 | 434 | |
| 382 | 435 | // Restrict access to donor profile, if donor and user are disconnected. |
| 383 | 436 | $is_donor_disconnected = get_user_meta( get_current_user_id(), '_give_is_donor_disconnected', true ); |
| @@ -580,8 +633,10 @@ | ||
| 580 | 633 | * Give totals Shortcode. |
| 581 | 634 | * |
| 582 | 635 | * Shows a donation total. |
| 583 | 636 | * |
| 637 | + * @since 3.14.0 Replace "_give_form_earnings" form meta with $query->form($post)->sumAmount() | |
| 638 | + * @since 3.7.0 Sanitize attributes | |
| 584 | 639 | * @since 2.1 |
| 585 | 640 | * |
| 586 | 641 | * @param array $atts Shortcode attributes. |
| 587 | 642 | * |
| @@ -609,11 +664,14 @@ | ||
| 609 | 664 | |
| 610 | 665 | // Total Goal. |
| 611 | 666 | $total_goal = give_maybe_sanitize_amount( $atts['total_goal'] ); |
| 612 | 667 | |
| 668 | + $atts = give_clean($atts); | |
| 669 | + | |
| 613 | 670 | /** |
| 614 | 671 | * Give Action fire before the shortcode is rendering is started. |
| 615 | 672 | * |
| 673 | + * @since 3.1.0 Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus | |
| 616 | 674 | * @since 2.1.4 |
| 617 | 675 | * |
| 618 | 676 | * @param array $atts shortcode attribute. |
| 619 | 677 | */ |
| @@ -626,8 +684,17 @@ | ||
| 626 | 684 | if ( ! empty( $atts['ids'] ) ) { |
| 627 | 685 | $form_ids = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ); |
| 628 | 686 | } |
| 629 | 687 | |
| 688 | + $form_ids = array_map( | |
| 689 | + static function ($id) { | |
| 690 | + _give_redirect_form_id($id); | |
| 691 | + | |
| 692 | + return $id; | |
| 693 | + }, | |
| 694 | + $form_ids | |
| 695 | + ); | |
| 696 | + | |
| 630 | 697 | /** |
| 631 | 698 | * Filter to modify WP Query for Total Goal. |
| 632 | 699 | * |
| 633 | 700 | * @since 2.1.4 |
| @@ -676,9 +743,10 @@ | ||
| 676 | 743 | |
| 677 | 744 | if ( isset( $forms->posts ) ) { |
| 678 | 745 | $total = 0; |
| 679 | 746 | foreach ( $forms->posts as $post ) { |
| 680 | - $form_earning = give_get_meta( $post, '_give_form_earnings', true ); | |
| 747 | + $query = new DonationQuery(); | |
| 748 | + $form_earning = $query->form($post)->sumAmount(); | |
| 681 | 749 | $form_earning = ! empty( $form_earning ) ? $form_earning : 0; |
| 682 | 750 | |
| 683 | 751 | /** |
| 684 | 752 | * Update Form earnings. |
| @@ -776,10 +844,22 @@ | ||
| 776 | 844 | |
| 777 | 845 | /** |
| 778 | 846 | * Displays donation forms in a grid layout. |
| 779 | 847 | * |
| 848 | + * @since 3.7.0 Sanitize attributes | |
| 780 | 849 | * @since 2.1.0 |
| 781 | 850 | * |
| 851 | + * @since 3.1.0 Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus | |
| 852 | + * @since 2.23.1 Updated the default text color for the donate button, see #6591. | |
| 853 | + * @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868. | |
| 854 | + * change tag_text_color color to #333333. | |
| 855 | + * @since 2.20.0 $show_donate_button Option to show donate button | |
| 856 | + * @since 2.20.0 $donate_button_text Default Donate | |
| 857 | + * @since 2.20.0 $donate_button_background_color Default #66bb6a | |
| 858 | + * @since 2.20.0 $donate_button_text_color Default #fff | |
| 859 | + * @since 2.20.0 $show_bar Default false | |
| 860 | + * @since 2.22.2 remove $show_bar attribute in favor of show_goal | |
| 861 | + * | |
| 782 | 862 | * @param array $atts { |
| 783 | 863 | * Optional. Attributes of the form grid shortcode. |
| 784 | 864 | * |
| 785 | 865 | * @type int $forms_per_page Number of forms per page. Default '12'. |
| @@ -793,28 +873,18 @@ | ||
| 793 | 873 | * @type bool $show_title Whether to display form title. Default 'true'. |
| 794 | 874 | * @type bool $show_goal Whether to display form goal. Default 'true'. |
| 795 | 875 | * @type bool $show_excerpt Whether to display form excerpt. Default 'true'. |
| 796 | 876 | * @type bool $show_featured_image Whether to display featured image. Default 'true'. |
| 797 | - * @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes. | |
| 877 | + * @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes. | |
| 798 | 878 | * @type string $image_height Featured image height. Default 'auto'. Accepts valid CSS heights. |
| 799 | 879 | * @type int $excerpt_length Number of words before excerpt is truncated. Default '16'. |
| 800 | 880 | * @type string $display_style How the form is displayed, either in new page or modal popup. |
| 801 | 881 | * Default 'redirect'. Accepts 'redirect', 'modal'. |
| 802 | 882 | * |
| 803 | - * @since 2.23.1 Updated the default text color for the donate button, see #6591. | |
| 804 | - * @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868. | |
| 805 | - * change tag_text_color color to #333333. | |
| 806 | - * @since 2.20.0 $show_donate_button Option to show donate button | |
| 807 | - * @since 2.20.0 $donate_button_text Default Donate | |
| 808 | - * @since 2.20.0 $donate_button_background_color Default #66bb6a | |
| 809 | - * @since 2.20.0 $donate_button_text_color Default #fff | |
| 810 | - * @since 2.20.0 $show_bar Default false | |
| 811 | - * @since 2.22.2 remove $show_bar attribute in favor of show_goal | |
| 812 | - * | |
| 813 | 883 | * @return string|bool The markup of the form grid or false. |
| 814 | 884 | */ |
| 815 | 885 | function give_form_grid_shortcode( $atts ) { |
| 816 | - | |
| 886 | + $atts = give_clean($atts); | |
| 817 | 887 | $give_settings = give_get_settings(); |
| 818 | 888 | |
| 819 | 889 | $atts = shortcode_atts( |
| 820 | 890 | [ |
| @@ -894,9 +964,15 @@ | ||
| 894 | 964 | } |
| 895 | 965 | |
| 896 | 966 | // Maybe filter forms by IDs. |
| 897 | 967 | if ( ! empty( $atts['ids'] ) ) { |
| 898 | - $form_args['post__in'] = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ); | |
| 968 | + $form_args['post__in'] = array_map( | |
| 969 | + static function ($id) { | |
| 970 | + _give_redirect_form_id($id); | |
| 971 | + | |
| 972 | + return $id; | |
| 973 | + }, array_filter(array_map('trim', explode(',', $atts['ids']))) | |
| 974 | + ); | |
| 899 | 975 | } |
| 900 | 976 | |
| 901 | 977 | // Convert comma-separated form IDs into array. |
| 902 | 978 | if ( ! empty( $atts['exclude'] ) ) { |