| @@ -3,14 +3,21 @@ | ||
| 3 | 3 | * Give Shortcodes |
| 4 | 4 | * |
| 5 | 5 | * @package Give |
| 6 | 6 | * @subpackage Shortcodes |
| 7 | - * @copyright Copyright (c) 2016, WordImpress | |
| 7 | + * @copyright Copyright (c) 2016, GiveWP | |
| 8 | 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | +use Give\DonationForms\DonationQuery; | |
| 14 | +use Give\Helpers\Form\Template\Utils\Frontend as FrontendFormTemplateUtils; | |
| 15 | +use Give\Helpers\Form\Utils as FormUtils; | |
| 16 | +use Give\Helpers\Frontend\ConfirmDonation; | |
| 17 | +use Give\Helpers\Frontend\Shortcode as ShortcodeUtils; | |
| 18 | +use Give\Views\IframeView; | |
| 19 | + | |
| 13 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 21 | exit; |
| 15 | 22 | } |
| 16 | 23 | |
| @@ -18,8 +25,10 @@ | ||
| 18 | 25 | * Donation History Shortcode |
| 19 | 26 | * |
| 20 | 27 | * Displays a user's donation history. |
| 21 | 28 | * |
| 29 | + * @since 3.7.0 Sanitize attributes | |
| 30 | + * @since 3.1.0 pass form id by reference in give_totals shortcode. | |
| 22 | 31 | * @since 1.0 |
| 23 | 32 | * |
| 24 | 33 | * @param array $atts |
| 25 | 34 | * @param string|bool $content |
| @@ -26,18 +35,22 @@ | ||
| 26 | 35 | * |
| 27 | 36 | * @return string|bool |
| 28 | 37 | */ |
| 29 | 38 | function give_donation_history( $atts, $content = false ) { |
| 39 | + $atts = give_clean($atts); | |
| 40 | + $donation_history_args = shortcode_atts( | |
| 41 | + [ | |
| 42 | + 'id' => true, | |
| 43 | + 'date' => true, | |
| 44 | + 'donor' => false, | |
| 45 | + 'amount' => true, | |
| 46 | + 'status' => false, | |
| 47 | + 'payment_method' => false, | |
| 48 | + ], | |
| 49 | + $atts, | |
| 50 | + 'donation_history' | |
| 51 | + ); | |
| 30 | 52 | |
| 31 | - $donation_history_args = shortcode_atts( array( | |
| 32 | - 'id' => true, | |
| 33 | - 'date' => true, | |
| 34 | - 'donor' => false, | |
| 35 | - 'amount' => true, | |
| 36 | - 'status' => false, | |
| 37 | - 'payment_method' => false, | |
| 38 | - ), $atts, 'donation_history' ); | |
| 39 | - | |
| 40 | 53 | // Always show receipt link. |
| 41 | 54 | $donation_history_args['details'] = true; |
| 42 | 55 | |
| 43 | 56 | // Set Donation History Shortcode Arguments in session variable. |
| @@ -42,19 +55,27 @@ | ||
| 42 | 55 | |
| 43 | 56 | // Set Donation History Shortcode Arguments in session variable. |
| 44 | 57 | Give()->session->set( 'give_donation_history_args', $donation_history_args ); |
| 45 | 58 | |
| 59 | + $get_data = give_clean( filter_input_array( INPUT_GET ) ); | |
| 60 | + | |
| 46 | 61 | // If payment_key query arg exists, return receipt instead of donation history. |
| 47 | - if ( isset( $_GET['payment_key'] ) ) { | |
| 62 | + if ( | |
| 63 | + ! empty( $get_data['donation_id'] ) || | |
| 64 | + ( | |
| 65 | + ! empty( $get_data['action'] ) && | |
| 66 | + 'view_in_browser' === $get_data['action'] | |
| 67 | + ) | |
| 68 | + ) { | |
| 48 | 69 | ob_start(); |
| 49 | 70 | |
| 50 | - echo give_receipt_shortcode( array() ); | |
| 71 | + echo do_shortcode( ShortcodeUtils::getReceiptShortcodeFromConfirmationPage() ); | |
| 51 | 72 | |
| 52 | 73 | // Display donation history link only if Receipt Access Session is available. |
| 53 | - if ( give_get_receipt_session() ) { | |
| 74 | + if ( give_get_receipt_session() || is_user_logged_in() ) { | |
| 54 | 75 | echo sprintf( |
| 55 | 76 | '<a href="%s">%s</a>', |
| 56 | - esc_url( give_get_history_page_uri() ), | |
| 77 | + esc_url($_SERVER['HTTP_REFERER'] ), | |
| 57 | 78 | __( '« Return to All Donations', 'give' ) |
| 58 | 79 | ); |
| 59 | 80 | } |
| 60 | 81 | |
| @@ -67,10 +88,10 @@ | ||
| 67 | 88 | |
| 68 | 89 | /** |
| 69 | 90 | * Determine access |
| 70 | 91 | * |
| 71 | - * a. Check if a user is logged in or does a session exists | |
| 72 | - * b. Does an email-access token exist? | |
| 92 | + * A. Check if a user is logged in or does a session exists. | |
| 93 | + * B. Does an email-access token exist? | |
| 73 | 94 | */ |
| 74 | 95 | if ( |
| 75 | 96 | is_user_logged_in() |
| 76 | 97 | || false !== Give()->session->get_session_expiration() |
| @@ -81,9 +102,8 @@ | ||
| 81 | 102 | |
| 82 | 103 | if ( ! empty( $content ) ) { |
| 83 | 104 | echo do_shortcode( $content ); |
| 84 | 105 | } |
| 85 | - | |
| 86 | 106 | } elseif ( give_is_setting_enabled( $email_access ) ) { |
| 87 | 107 | // Is Email-based access enabled? |
| 88 | 108 | give_get_template_part( 'email', 'login-form' ); |
| 89 | 109 | |
| @@ -88,9 +108,9 @@ | ||
| 88 | 108 | give_get_template_part( 'email', 'login-form' ); |
| 89 | 109 | |
| 90 | 110 | } else { |
| 91 | 111 | |
| 92 | - echo apply_filters( 'give_donation_history_nonuser_message', Give()->notices->print_frontend_notice( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) ); | |
| 112 | + echo apply_filters( 'give_donation_history_nonuser_message', Give_Notices::print_frontend_notice( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) ); | |
| 93 | 113 | echo do_shortcode( '[give_login]' ); |
| 94 | 114 | } |
| 95 | 115 | |
| 96 | 116 | /** |
| @@ -113,32 +133,76 @@ | ||
| 113 | 133 | * Donation Form Shortcode |
| 114 | 134 | * |
| 115 | 135 | * Show the Give donation form. |
| 116 | 136 | * |
| 137 | + * @since 3.7.0 Sanitize attributes | |
| 138 | + * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status. | |
| 139 | + * @since 2.30.0 Add short-circuit filter to allow for custom output. | |
| 117 | 140 | * @since 1.0 |
| 118 | 141 | * |
| 119 | - * @param array $atts Shortcode attributes | |
| 142 | + | |
| 143 | + * @param array $atts Shortcode attributes | |
| 120 | 144 | * |
| 121 | 145 | * @return string |
| 122 | 146 | */ |
| 123 | 147 | function give_form_shortcode( $atts ) { |
| 124 | - $atts = shortcode_atts( array( | |
| 125 | - 'id' => '', | |
| 126 | - 'show_title' => true, | |
| 127 | - 'show_goal' => true, | |
| 128 | - 'show_content' => '', | |
| 129 | - 'float_labels' => '', | |
| 130 | - 'display_style' => '', | |
| 131 | - 'continue_button_title' => '', | |
| 132 | - ), $atts, 'give_form' ); | |
| 148 | + $atts = give_clean($atts); | |
| 149 | + $atts = shortcode_atts( give_get_default_form_shortcode_args(), $atts, 'give_form' ); | |
| 133 | 150 | |
| 151 | + if('fullForm' === $atts['display_style']) { | |
| 152 | + $atts['display_style'] = 'onpage'; | |
| 153 | + } | |
| 154 | + | |
| 134 | 155 | // Convert string to bool. |
| 135 | 156 | $atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN ); |
| 136 | 157 | $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN ); |
| 137 | 158 | |
| 138 | - // get the Give Form | |
| 159 | + // Set form id. | |
| 160 | + $atts['id'] = $atts['id'] ?: FrontendFormTemplateUtils::getFormId(); | |
| 161 | + $formId = absint($atts['id']); | |
| 162 | + | |
| 163 | + if ( ! ShortcodeUtils::isValidForm($formId)) { | |
| 164 | + ob_start(); | |
| 165 | + Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'), | |
| 166 | + true); | |
| 167 | + | |
| 168 | + return ob_get_clean(); | |
| 169 | + } | |
| 170 | + | |
| 171 | + if ( ! ShortcodeUtils::isPublishedForm($formId)) { | |
| 172 | + ob_start(); | |
| 173 | + Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true); | |
| 174 | + | |
| 175 | + return ob_get_clean(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + _give_redirect_form_id($formId, $atts['id']); | |
| 179 | + | |
| 180 | + // Short-circuit the shortcode output if the filter returns a non-empty string. | |
| 181 | + $output = apply_filters('givewp_form_shortcode_output', '', $atts); | |
| 182 | + | |
| 183 | + if ($output) { | |
| 184 | + return $output; | |
| 185 | + } | |
| 186 | + | |
| 187 | + // Fetch the Give Form. | |
| 139 | 188 | ob_start(); |
| 140 | - give_get_donation_form( $atts ); | |
| 189 | + | |
| 190 | + if ( ! FormUtils::isLegacyForm( $formId ) ) { | |
| 191 | + $showIframeInModal = 'button' === $atts['display_style']; | |
| 192 | + $iframeView = new IframeView(); | |
| 193 | + | |
| 194 | + ConfirmDonation::storePostedDataInDonationSession(); | |
| 195 | + | |
| 196 | + echo $iframeView->setFormId( $formId ) | |
| 197 | + ->showInModal( $showIframeInModal ) | |
| 198 | + ->setButtonTitle( $atts['continue_button_title'] ) | |
| 199 | + ->setButtonColor( $atts['button_color'] ) | |
| 200 | + ->render(); | |
| 201 | + } else { | |
| 202 | + give_get_donation_form( $atts ); | |
| 203 | + } | |
| 204 | + | |
| 141 | 205 | $final_output = ob_get_clean(); |
| 142 | 206 | |
| 143 | 207 | return apply_filters( 'give_donate_form', $final_output, $atts ); |
| 144 | 208 | } |
| @@ -149,8 +213,11 @@ | ||
| 149 | 213 | * Donation Form Goal Shortcode. |
| 150 | 214 | * |
| 151 | 215 | * Show the Give donation form goals. |
| 152 | 216 | * |
| 217 | + * @since 3.12.0 add start_date and end_date attributes | |
| 218 | + * @since 3.7.0 Sanitize attributes | |
| 219 | + * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status. | |
| 153 | 220 | * @since 1.0 |
| 154 | 221 | * |
| 155 | 222 | * @param array $atts Shortcode attributes. |
| 156 | 223 | * |
| @@ -156,26 +223,40 @@ | ||
| 156 | 223 | * |
| 157 | 224 | * @return string |
| 158 | 225 | */ |
| 159 | 226 | function give_goal_shortcode( $atts ) { |
| 160 | - $atts = shortcode_atts( array( | |
| 161 | - 'id' => '', | |
| 162 | - 'show_text' => true, | |
| 163 | - 'show_bar' => true, | |
| 164 | - ), $atts, 'give_goal' ); | |
| 227 | + $atts = give_clean($atts); | |
| 228 | + $atts = shortcode_atts( | |
| 229 | + [ | |
| 230 | + 'id' => '', | |
| 231 | + 'show_text' => true, | |
| 232 | + 'show_bar' => true, | |
| 233 | + 'color' => '#66BB6A', | |
| 234 | + 'start_date' => '', | |
| 235 | + 'end_date' => '', | |
| 236 | + ], | |
| 237 | + $atts, | |
| 238 | + 'give_goal' | |
| 239 | + ); | |
| 165 | 240 | |
| 241 | + _give_redirect_form_id($atts['id']); | |
| 242 | + | |
| 166 | 243 | // get the Give Form. |
| 167 | 244 | ob_start(); |
| 168 | 245 | |
| 169 | - // Sanity check 1: ensure there is an ID Provided. | |
| 170 | - if ( empty( $atts['id'] ) ) { | |
| 171 | - Give()->notices->print_frontend_notice( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true ); | |
| 172 | - } | |
| 246 | + $formId = (int)$atts['id']; | |
| 173 | 247 | |
| 174 | - // Sanity check 2: Check the form even has Goals enabled. | |
| 175 | - if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) { | |
| 248 | + // Sanity check 1: ensure there is an ID Provided. | |
| 249 | + if ( ! ShortcodeUtils::isValidForm($formId)) { | |
| 250 | + Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'), | |
| 251 | + true); | |
| 252 | + } elseif // Sanity check 2: ensure the form is published. | |
| 253 | + ( ! ShortcodeUtils::isPublishedForm($formId)) { | |
| 254 | + Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true); | |
| 255 | + } elseif // Sanity check 3: Check the form even has Goals enabled. | |
| 256 | + ( ! give_is_setting_enabled(give_get_meta($atts['id'], '_give_goal_option', true))) { | |
| 176 | 257 | |
| 177 | - Give()->notices->print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true ); | |
| 258 | + Give_Notices::print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true ); | |
| 178 | 259 | } else { |
| 179 | 260 | // Passed all sanity checks: output Goal. |
| 180 | 261 | give_show_goal_progress( $atts['id'], $atts ); |
| 181 | 262 | } |
| @@ -193,8 +274,9 @@ | ||
| 193 | 274 | * |
| 194 | 275 | * Shows a login form allowing users to users to log in. This function simply |
| 195 | 276 | * calls the give_login_form function to display the login form. |
| 196 | 277 | * |
| 278 | + * @since 3.7.0 Sanitize attributes | |
| 197 | 279 | * @since 1.0 |
| 198 | 280 | * |
| 199 | 281 | * @param array $atts Shortcode attributes. |
| 200 | 282 | * |
| @@ -202,16 +284,20 @@ | ||
| 202 | 284 | * |
| 203 | 285 | * @return string |
| 204 | 286 | */ |
| 205 | 287 | function give_login_form_shortcode( $atts ) { |
| 288 | + $atts = give_clean($atts); | |
| 289 | + $atts = shortcode_atts( | |
| 290 | + [ | |
| 291 | + // Add backward compatibility for redirect attribute. | |
| 292 | + 'redirect' => '', | |
| 293 | + 'login-redirect' => '', | |
| 294 | + 'logout-redirect' => '', | |
| 295 | + ], | |
| 296 | + $atts, | |
| 297 | + 'give_login' | |
| 298 | + ); | |
| 206 | 299 | |
| 207 | - $atts = shortcode_atts( array( | |
| 208 | - // Add backward compatibility for redirect attribute. | |
| 209 | - 'redirect' => '', | |
| 210 | - 'login-redirect' => '', | |
| 211 | - 'logout-redirect' => '', | |
| 212 | - ), $atts, 'give_login' ); | |
| 213 | - | |
| 214 | 300 | // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute. |
| 215 | 301 | $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect'] ) ? $atts['redirect'] : '' ); |
| 216 | 302 | |
| 217 | 303 | return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] ); |
| @@ -223,8 +309,9 @@ | ||
| 223 | 309 | * Register Shortcode. |
| 224 | 310 | * |
| 225 | 311 | * Shows a registration form allowing users to users to register for the site. |
| 226 | 312 | * |
| 313 | + * @since 3.7.0 Sanitize attributes | |
| 227 | 314 | * @since 1.0 |
| 228 | 315 | * |
| 229 | 316 | * @param array $atts Shortcode attributes. |
| 230 | 317 | * |
| @@ -232,11 +319,16 @@ | ||
| 232 | 319 | * |
| 233 | 320 | * @return string |
| 234 | 321 | */ |
| 235 | 322 | function give_register_form_shortcode( $atts ) { |
| 236 | - $atts = shortcode_atts( array( | |
| 237 | - 'redirect' => '', | |
| 238 | - ), $atts, 'give_register' ); | |
| 323 | + $atts = give_clean($atts); | |
| 324 | + $atts = shortcode_atts( | |
| 325 | + [ | |
| 326 | + 'redirect' => '', | |
| 327 | + ], | |
| 328 | + $atts, | |
| 329 | + 'give_register' | |
| 330 | + ); | |
| 239 | 331 | |
| 240 | 332 | return give_register_form( $atts['redirect'] ); |
| 241 | 333 | } |
| 242 | 334 | |
| @@ -246,8 +338,10 @@ | ||
| 246 | 338 | * Receipt Shortcode. |
| 247 | 339 | * |
| 248 | 340 | * Shows a donation receipt. |
| 249 | 341 | * |
| 342 | + * @since 3.16.0 add give_donation_confirmation_page_enqueue_scripts | |
| 343 | + * @since 3.7.0 Sanitize and escape attributes | |
| 250 | 344 | * @since 1.0 |
| 251 | 345 | * |
| 252 | 346 | * @param array $atts Shortcode attributes. |
| 253 | 347 | * |
| @@ -255,111 +349,61 @@ | ||
| 255 | 349 | */ |
| 256 | 350 | function give_receipt_shortcode( $atts ) { |
| 257 | 351 | |
| 258 | 352 | global $give_receipt_args; |
| 259 | - $payment_key = ''; | |
| 260 | 353 | |
| 261 | - $give_receipt_args = shortcode_atts( array( | |
| 262 | - 'error' => __( 'You are missing the payment key to view this donation receipt.', 'give' ), | |
| 263 | - 'price' => true, | |
| 264 | - 'donor' => true, | |
| 265 | - 'date' => true, | |
| 266 | - 'payment_key' => false, | |
| 267 | - 'payment_method' => true, | |
| 268 | - 'payment_id' => true, | |
| 269 | - 'payment_status' => false, | |
| 270 | - 'company_name' => false, | |
| 271 | - 'status_notice' => true, | |
| 272 | - ), $atts, 'give_receipt' ); | |
| 354 | + $atts = give_clean($atts); | |
| 273 | 355 | |
| 274 | - // set $session var | |
| 275 | - $session = give_get_purchase_session(); | |
| 356 | + $give_receipt_args = shortcode_atts( | |
| 357 | + [ | |
| 358 | + 'error' => __( 'You are missing the donation id to view this donation receipt.', 'give' ), | |
| 359 | + 'price' => true, | |
| 360 | + 'donor' => true, | |
| 361 | + 'date' => true, | |
| 362 | + 'payment_method' => true, | |
| 363 | + 'payment_id' => true, | |
| 364 | + 'payment_status' => false, | |
| 365 | + 'company_name' => false, | |
| 366 | + 'status_notice' => true, | |
| 367 | + ], | |
| 368 | + $atts, | |
| 369 | + 'give_receipt' | |
| 370 | + ); | |
| 276 | 371 | |
| 277 | - // set payment key var | |
| 278 | - if ( isset( $_GET['payment_key'] ) ) { | |
| 279 | - $payment_key = urldecode( $_GET['payment_key'] ); | |
| 280 | - } elseif ( $session ) { | |
| 281 | - $payment_key = $session['purchase_key']; | |
| 282 | - } elseif ( $give_receipt_args['payment_key'] ) { | |
| 283 | - $payment_key = $give_receipt_args['payment_key']; | |
| 284 | - } | |
| 372 | + ob_start(); | |
| 285 | 373 | |
| 286 | - if( ! wp_doing_ajax() ) { | |
| 287 | - ob_start(); | |
| 288 | - give_get_template_part( 'receipt/placeholder' ); | |
| 289 | - $placeholder = ob_get_clean(); | |
| 374 | + $donation_id = false; | |
| 375 | + $receipt_type = false; | |
| 376 | + $get_data = give_clean( filter_input_array( INPUT_GET ) ); | |
| 377 | + $session = give_get_purchase_session(); | |
| 290 | 378 | |
| 291 | - return sprintf( | |
| 292 | - '<div id="give-receipt" data-shortcode="%s" data-donation-key="%s">%s</div>', | |
| 293 | - urlencode_deep( wp_json_encode( $atts ) ), | |
| 294 | - $payment_key, | |
| 295 | - $placeholder | |
| 296 | - ); | |
| 379 | + if ( ! empty( $get_data['donation_id'] ) ) { | |
| 380 | + $donation_id = $get_data['donation_id']; | |
| 381 | + } elseif ( ! empty( $get_data['action'] ) && 'view_in_browser' === $get_data['action'] ) { | |
| 382 | + $receipt_type = 'view_in_browser'; | |
| 383 | + $donation_id = $get_data['_give_hash']; | |
| 384 | + } elseif ( isset( $session['donation_id'] ) ) { | |
| 385 | + $donation_id = $session['donation_id']; | |
| 386 | + } elseif ( ! empty( $give_receipt_args['id'] ) ) { | |
| 387 | + $donation_id = $give_receipt_args['id']; | |
| 297 | 388 | } |
| 298 | 389 | |
| 299 | - $email_access = give_get_option( 'email_access' ); | |
| 390 | + // Display donation receipt placeholder while loading receipt via AJAX. | |
| 391 | + if ( ! wp_doing_ajax() ) { | |
| 392 | + give_get_template_part( 'receipt/placeholder' ); | |
| 300 | 393 | |
| 301 | - // No payment_key found & Email Access is Turned on. | |
| 302 | - if ( ! isset( $payment_key ) && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) { | |
| 394 | + do_action('give_donation_confirmation_page_enqueue_scripts'); | |
| 303 | 395 | |
| 304 | - ob_start(); | |
| 305 | - | |
| 306 | - give_get_template_part( 'email-login-form' ); | |
| 307 | - | |
| 308 | - return ob_get_clean(); | |
| 309 | - | |
| 310 | - } elseif ( ! isset( $payment_key ) ) { | |
| 311 | - | |
| 312 | - return Give()->notices->print_frontend_notice( $give_receipt_args['error'], false, 'error' ); | |
| 313 | - | |
| 396 | + return apply_filters('give_receipt_shortcode_output', sprintf( | |
| 397 | + '<div id="give-receipt" data-shortcode="%1$s" data-receipt-type="%2$s" data-donation-key="%3$s" >%4$s</div>', | |
| 398 | + htmlspecialchars( wp_json_encode( $give_receipt_args ) ), | |
| 399 | + esc_attr($receipt_type), | |
| 400 | + esc_attr($donation_id), | |
| 401 | + ob_get_clean() | |
| 402 | + )); | |
| 314 | 403 | } |
| 315 | 404 | |
| 316 | - $user_can_view = give_can_view_receipt( $payment_key ); | |
| 317 | - | |
| 318 | - // Key was provided, but user is logged out. Offer them the ability to login and view the receipt. | |
| 319 | - if ( ! $user_can_view && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) { | |
| 320 | - | |
| 321 | - ob_start(); | |
| 322 | - | |
| 323 | - give_get_template_part( 'email-login-form' ); | |
| 324 | - | |
| 325 | - return ob_get_clean(); | |
| 326 | - | |
| 327 | - } elseif ( ! $user_can_view ) { | |
| 328 | - | |
| 329 | - global $give_login_redirect; | |
| 330 | - | |
| 331 | - $give_login_redirect = give_get_current_page_url(); | |
| 332 | - | |
| 333 | - ob_start(); | |
| 334 | - | |
| 335 | - Give()->notices->print_frontend_notice( apply_filters( 'give_must_be_logged_in_error_message', __( 'You must be logged in to view this donation receipt.', 'give' ) ) ); | |
| 336 | - | |
| 337 | - give_get_template_part( 'shortcode', 'login' ); | |
| 338 | - | |
| 339 | - $login_form = ob_get_clean(); | |
| 340 | - | |
| 341 | - return $login_form; | |
| 342 | - } | |
| 343 | - | |
| 344 | - /** | |
| 345 | - * Check if the user has permission to view the receipt. | |
| 346 | - * | |
| 347 | - * If user is logged in, user ID is compared to user ID of ID stored in payment meta | |
| 348 | - * or if user is logged out and donation was made as a guest, the donation session is checked for | |
| 349 | - * or if user is logged in and the user can view sensitive shop data. | |
| 350 | - */ | |
| 351 | - if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) { | |
| 352 | - return Give()->notices->print_frontend_notice( $give_receipt_args['error'], false, 'error' ); | |
| 353 | - } | |
| 354 | - | |
| 355 | - ob_start(); | |
| 356 | - | |
| 357 | - give_get_template_part( 'shortcode', 'receipt' ); | |
| 358 | - | |
| 359 | - $display = ob_get_clean(); | |
| 360 | - | |
| 361 | - return $display; | |
| 405 | + return give_display_donation_receipt( $atts ); | |
| 362 | 406 | } |
| 363 | 407 | |
| 364 | 408 | add_shortcode( 'give_receipt', 'give_receipt_shortcode' ); |
| 365 | 409 | |
| @@ -368,13 +412,14 @@ | ||
| 368 | 412 | * |
| 369 | 413 | * Outputs the Give Profile Editor to allow users to amend their details from the |
| 370 | 414 | * front-end. This function uses the Give templating system allowing users to |
| 371 | 415 | * override the default profile editor template. The profile editor template is located |
| 372 | - * under templates/profile-editor.php, however, it can be altered by creating a | |
| 373 | - * file called profile-editor.php in the give_template directory in your active theme's | |
| 416 | + * under templates/shortcode-profile-editor.php, however, it can be altered by creating a | |
| 417 | + * file called shortcode-profile-editor.php in the give_template directory in your active theme's | |
| 374 | 418 | * folder. Please visit the Give Documentation for more information on how the |
| 375 | 419 | * templating system is used. |
| 376 | 420 | * |
| 421 | + * @since 3.7.0 Sanitize attributes | |
| 377 | 422 | * @since 1.0 |
| 378 | 423 | * |
| 379 | 424 | * @param array $atts Shortcode attributes. |
| 380 | 425 | * |
| @@ -381,14 +426,16 @@ | ||
| 381 | 426 | * @return string Output generated from the profile editor |
| 382 | 427 | */ |
| 383 | 428 | function give_profile_editor_shortcode( $atts ) { |
| 384 | 429 | |
| 430 | + $atts = give_clean($atts); | |
| 431 | + | |
| 385 | 432 | ob_start(); |
| 386 | 433 | |
| 387 | 434 | // Restrict access to donor profile, if donor and user are disconnected. |
| 388 | 435 | $is_donor_disconnected = get_user_meta( get_current_user_id(), '_give_is_donor_disconnected', true ); |
| 389 | 436 | if ( is_user_logged_in() && $is_donor_disconnected ) { |
| 390 | - Give()->notices->print_frontend_notice( __( 'Your Donor and User profile are no longer connected. Please contact the site administrator.', 'give' ), true, 'error' ); | |
| 437 | + Give_Notices::print_frontend_notice( __( 'Your Donor and User profile are no longer connected. Please contact the site administrator.', 'give' ), true, 'error' ); | |
| 391 | 438 | |
| 392 | 439 | return false; |
| 393 | 440 | } |
| 394 | 441 | |
| @@ -393,11 +440,9 @@ | ||
| 393 | 440 | } |
| 394 | 441 | |
| 395 | 442 | give_get_template_part( 'shortcode', 'profile-editor' ); |
| 396 | 443 | |
| 397 | - $display = ob_get_clean(); | |
| 398 | - | |
| 399 | - return $display; | |
| 444 | + return ob_get_clean(); | |
| 400 | 445 | } |
| 401 | 446 | |
| 402 | 447 | add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' ); |
| 403 | 448 | |
| @@ -437,9 +482,9 @@ | ||
| 437 | 482 | $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email; |
| 438 | 483 | $password = ! empty( $data['give_new_user_pass1'] ) ? $data['give_new_user_pass1'] : ''; |
| 439 | 484 | $confirm_password = ! empty( $data['give_new_user_pass2'] ) ? $data['give_new_user_pass2'] : ''; |
| 440 | 485 | |
| 441 | - $userdata = array( | |
| 486 | + $userdata = [ | |
| 442 | 487 | 'ID' => $user_id, |
| 443 | 488 | 'first_name' => $first_name, |
| 444 | 489 | 'last_name' => $last_name, |
| 445 | 490 | 'display_name' => $display_name, |
| @@ -445,9 +490,9 @@ | ||
| 445 | 490 | 'display_name' => $display_name, |
| 446 | 491 | 'user_email' => $email, |
| 447 | 492 | 'user_pass' => $password, |
| 448 | 493 | 'company_name' => $company_name, |
| 449 | - ); | |
| 494 | + ]; | |
| 450 | 495 | |
| 451 | 496 | /** |
| 452 | 497 | * Fires before updating user profile. |
| 453 | 498 | * |
| @@ -474,9 +519,9 @@ | ||
| 474 | 519 | } elseif ( ! is_email( $email ) ) { |
| 475 | 520 | // Make sure email should be valid. |
| 476 | 521 | give_set_error( 'email_not_valid', __( 'The email you entered is not valid. Please use another', 'give' ) ); |
| 477 | 522 | |
| 478 | - } elseif ( $email != $old_user_data->user_email ) { | |
| 523 | + } elseif ( $email !== $old_user_data->user_email ) { | |
| 479 | 524 | // Make sure the new email doesn't belong to another user. |
| 480 | 525 | if ( email_exists( $email ) ) { |
| 481 | 526 | give_set_error( 'user_email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) ); |
| 482 | 527 | } elseif ( Give()->donors->get_donor_by( 'email', $email ) ) { |
| @@ -494,11 +539,14 @@ | ||
| 494 | 539 | give_die(); |
| 495 | 540 | } |
| 496 | 541 | |
| 497 | 542 | // Update Donor First Name and Last Name. |
| 498 | - Give()->donors->update( $donor->id, array( | |
| 499 | - 'name' => trim( "{$first_name} {$last_name}" ), | |
| 500 | - ) ); | |
| 543 | + Give()->donors->update( | |
| 544 | + $donor->id, | |
| 545 | + [ | |
| 546 | + 'name' => trim( "{$first_name} {$last_name}" ), | |
| 547 | + ] | |
| 548 | + ); | |
| 501 | 549 | Give()->donor_meta->update_meta( $donor->id, '_give_donor_first_name', $first_name ); |
| 502 | 550 | Give()->donor_meta->update_meta( $donor->id, '_give_donor_last_name', $last_name ); |
| 503 | 551 | Give()->donor_meta->update_meta( $donor->id, '_give_donor_company', $company_name ); |
| 504 | 552 | |
| @@ -556,12 +604,12 @@ | ||
| 556 | 604 | * @param array $userdata User info, including ID, first name, last name, display name and email. |
| 557 | 605 | */ |
| 558 | 606 | do_action( 'give_user_profile_updated', $user_id, $userdata ); |
| 559 | 607 | |
| 560 | - $profile_edit_redirect_args = array( | |
| 608 | + $profile_edit_redirect_args = [ | |
| 561 | 609 | 'updated' => 'true', |
| 562 | 610 | 'update_code' => $update_code, |
| 563 | - ); | |
| 611 | + ]; | |
| 564 | 612 | |
| 565 | 613 | /** |
| 566 | 614 | * Update codes '2' and '3' indicate a password change. |
| 567 | 615 | * If the password is changed, then logout and redirect to the same page. |
| @@ -566,11 +614,11 @@ | ||
| 566 | 614 | * Update codes '2' and '3' indicate a password change. |
| 567 | 615 | * If the password is changed, then logout and redirect to the same page. |
| 568 | 616 | */ |
| 569 | 617 | if ( '2' === $update_code || '3' === $update_code ) { |
| 570 | - wp_logout( wp_redirect( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) ) ); | |
| 618 | + wp_logout(); | |
| 571 | 619 | } else { |
| 572 | - wp_redirect( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) ); | |
| 620 | + wp_redirect( esc_url_raw( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) ) ); | |
| 573 | 621 | } |
| 574 | 622 | |
| 575 | 623 | give_die(); |
| 576 | 624 | } |
| @@ -584,8 +632,10 @@ | ||
| 584 | 632 | * Give totals Shortcode. |
| 585 | 633 | * |
| 586 | 634 | * Shows a donation total. |
| 587 | 635 | * |
| 636 | + * @since 3.14.0 Replace "_give_form_earnings" form meta with $query->form($post)->sumAmount() | |
| 637 | + * @since 3.7.0 Sanitize attributes | |
| 588 | 638 | * @since 2.1 |
| 589 | 639 | * |
| 590 | 640 | * @param array $atts Shortcode attributes. |
| 591 | 641 | * |
| @@ -595,25 +645,32 @@ | ||
| 595 | 645 | $total = get_option( 'give_earnings_total', false ); |
| 596 | 646 | |
| 597 | 647 | $message = apply_filters( 'give_totals_message', __( 'Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give' ) ); |
| 598 | 648 | |
| 599 | - $atts = shortcode_atts( array( | |
| 600 | - 'total_goal' => 0, // integer | |
| 601 | - 'ids' => 0, // integer|array | |
| 602 | - 'cats' => 0, // integer|array | |
| 603 | - 'tags' => 0, // integer|array | |
| 604 | - 'message' => $message, | |
| 605 | - 'link' => '', // URL | |
| 606 | - 'link_text' => __( 'Donate Now', 'give' ), // string, | |
| 607 | - 'progress_bar' => true, // boolean | |
| 608 | - ), $atts, 'give_totals' ); | |
| 649 | + $atts = shortcode_atts( | |
| 650 | + [ | |
| 651 | + 'total_goal' => 0, // integer. | |
| 652 | + 'ids' => 0, // integer|array. | |
| 653 | + 'cats' => 0, // integer|array. | |
| 654 | + 'tags' => 0, // integer|array. | |
| 655 | + 'message' => $message, | |
| 656 | + 'link' => '', // URL. | |
| 657 | + 'link_text' => __( 'Donate Now', 'give' ), // string, | |
| 658 | + 'progress_bar' => true, // boolean. | |
| 659 | + ], | |
| 660 | + $atts, | |
| 661 | + 'give_totals' | |
| 662 | + ); | |
| 609 | 663 | |
| 610 | 664 | // Total Goal. |
| 611 | 665 | $total_goal = give_maybe_sanitize_amount( $atts['total_goal'] ); |
| 612 | 666 | |
| 667 | + $atts = give_clean($atts); | |
| 668 | + | |
| 613 | 669 | /** |
| 614 | 670 | * Give Action fire before the shortcode is rendering is started. |
| 615 | 671 | * |
| 672 | + * @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 | 673 | * @since 2.1.4 |
| 617 | 674 | * |
| 618 | 675 | * @param array $atts shortcode attribute. |
| 619 | 676 | */ |
| @@ -621,13 +678,22 @@ | ||
| 621 | 678 | |
| 622 | 679 | // Build query based on cat, tag and Form ids. |
| 623 | 680 | if ( ! empty( $atts['cats'] ) || ! empty( $atts['tags'] ) || ! empty( $atts['ids'] ) ) { |
| 624 | 681 | |
| 625 | - $form_ids = array(); | |
| 682 | + $form_ids = []; | |
| 626 | 683 | if ( ! empty( $atts['ids'] ) ) { |
| 627 | 684 | $form_ids = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ); |
| 628 | 685 | } |
| 629 | 686 | |
| 687 | + $form_ids = array_map( | |
| 688 | + static function ($id) { | |
| 689 | + _give_redirect_form_id($id); | |
| 690 | + | |
| 691 | + return $id; | |
| 692 | + }, | |
| 693 | + $form_ids | |
| 694 | + ); | |
| 695 | + | |
| 630 | 696 | /** |
| 631 | 697 | * Filter to modify WP Query for Total Goal. |
| 632 | 698 | * |
| 633 | 699 | * @since 2.1.4 |
| @@ -633,33 +699,33 @@ | ||
| 633 | 699 | * @since 2.1.4 |
| 634 | 700 | * |
| 635 | 701 | * @param array WP query argument for Total Goal. |
| 636 | 702 | */ |
| 637 | - $form_args = array( | |
| 638 | - 'post_type' => 'give_forms', | |
| 639 | - 'post_status' => 'publish', | |
| 640 | - 'post__in' => $form_ids, | |
| 641 | - 'posts_per_page' => - 1, | |
| 642 | - 'fields' => 'ids', | |
| 643 | - 'tax_query' => array( | |
| 703 | + $form_args = [ | |
| 704 | + 'post_type' => 'give_forms', | |
| 705 | + 'post_status' => 'publish', | |
| 706 | + 'post__in' => $form_ids, | |
| 707 | + 'posts_per_page' => - 1, | |
| 708 | + 'fields' => 'ids', | |
| 709 | + 'tax_query' => [ | |
| 644 | 710 | 'relation' => 'AND', |
| 645 | - ), | |
| 646 | - ); | |
| 711 | + ], | |
| 712 | + ]; | |
| 647 | 713 | |
| 648 | 714 | if ( ! empty( $atts['cats'] ) ) { |
| 649 | 715 | $cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) ); |
| 650 | - $form_args['tax_query'][] = array( | |
| 716 | + $form_args['tax_query'][] = [ | |
| 651 | 717 | 'taxonomy' => 'give_forms_category', |
| 652 | 718 | 'terms' => $cats, |
| 653 | - ); | |
| 719 | + ]; | |
| 654 | 720 | } |
| 655 | 721 | |
| 656 | 722 | if ( ! empty( $atts['tags'] ) ) { |
| 657 | 723 | $tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) ); |
| 658 | - $form_args['tax_query'][] = array( | |
| 724 | + $form_args['tax_query'][] = [ | |
| 659 | 725 | 'taxonomy' => 'give_forms_tag', |
| 660 | 726 | 'terms' => $tags, |
| 661 | - ); | |
| 727 | + ]; | |
| 662 | 728 | } |
| 663 | 729 | |
| 664 | 730 | /** |
| 665 | 731 | * Filter to modify WP Query for Total Goal. |
| @@ -676,9 +742,10 @@ | ||
| 676 | 742 | |
| 677 | 743 | if ( isset( $forms->posts ) ) { |
| 678 | 744 | $total = 0; |
| 679 | 745 | foreach ( $forms->posts as $post ) { |
| 680 | - $form_earning = give_get_meta( $post, '_give_form_earnings', true ); | |
| 746 | + $query = new DonationQuery(); | |
| 747 | + $form_earning = $query->form($post)->sumAmount(); | |
| 681 | 748 | $form_earning = ! empty( $form_earning ) ? $form_earning : 0; |
| 682 | 749 | |
| 683 | 750 | /** |
| 684 | 751 | * Update Form earnings. |
| @@ -684,17 +751,17 @@ | ||
| 684 | 751 | * Update Form earnings. |
| 685 | 752 | * |
| 686 | 753 | * @since 2.1 |
| 687 | 754 | * |
| 688 | - * @param int $post Form ID. | |
| 755 | + * @param int $post Form ID. | |
| 689 | 756 | * @param string $form_earning Total earning of Form. |
| 757 | + * @param array $atts shortcode attributes. | |
| 690 | 758 | */ |
| 691 | - $total += apply_filters( 'give_totals_form_earning', $form_earning, $post ); | |
| 759 | + $total += apply_filters( 'give_totals_form_earning', $form_earning, $post, $atts ); | |
| 692 | 760 | } |
| 693 | 761 | } |
| 762 | + } // End if(). | |
| 694 | 763 | |
| 695 | - } | |
| 696 | - | |
| 697 | 764 | // Append link with text. |
| 698 | 765 | $donate_link = ''; |
| 699 | 766 | if ( ! empty( $atts['link'] ) ) { |
| 700 | 767 | $donate_link = sprintf( ' <a class="give-totals-text-link" href="%1$s">%2$s</a>', esc_url( $atts['link'] ), esc_html( $atts['link_text'] ) ); |
| @@ -700,20 +767,30 @@ | ||
| 700 | 767 | $donate_link = sprintf( ' <a class="give-totals-text-link" href="%1$s">%2$s</a>', esc_url( $atts['link'] ), esc_html( $atts['link_text'] ) ); |
| 701 | 768 | } |
| 702 | 769 | |
| 703 | 770 | // Replace {total} in message. |
| 704 | - $message = str_replace( '{total}', give_currency_filter( | |
| 705 | - give_format_amount( $total, | |
| 706 | - array( 'sanitize' => false ) | |
| 707 | - ) | |
| 708 | - ), esc_html( $atts['message'] ) ); | |
| 771 | + $message = str_replace( | |
| 772 | + '{total}', | |
| 773 | + give_currency_filter( | |
| 774 | + give_format_amount( | |
| 775 | + $total, | |
| 776 | + [ 'sanitize' => false ] | |
| 777 | + ) | |
| 778 | + ), | |
| 779 | + esc_html( $atts['message'] ) | |
| 780 | + ); | |
| 709 | 781 | |
| 710 | 782 | // Replace {total_goal} in message. |
| 711 | - $message = str_replace( '{total_goal}', give_currency_filter( | |
| 712 | - give_format_amount( $total_goal, | |
| 713 | - array( 'sanitize' => true ) | |
| 714 | - ) | |
| 715 | - ), $message ); | |
| 783 | + $message = str_replace( | |
| 784 | + '{total_goal}', | |
| 785 | + give_currency_filter( | |
| 786 | + give_format_amount( | |
| 787 | + $total_goal, | |
| 788 | + [ 'sanitize' => true ] | |
| 789 | + ) | |
| 790 | + ), | |
| 791 | + $message | |
| 792 | + ); | |
| 716 | 793 | |
| 717 | 794 | /** |
| 718 | 795 | * Update Give totals shortcode output. |
| 719 | 796 | * |
| @@ -739,9 +816,8 @@ | ||
| 739 | 816 | </div> |
| 740 | 817 | <?php |
| 741 | 818 | $give_totals_output = ob_get_clean(); |
| 742 | 819 | |
| 743 | - | |
| 744 | 820 | /** |
| 745 | 821 | * Give Action fire after the total goal shortcode rendering is end. |
| 746 | 822 | * |
| 747 | 823 | * @since 2.1.4 |
| @@ -767,10 +843,22 @@ | ||
| 767 | 843 | |
| 768 | 844 | /** |
| 769 | 845 | * Displays donation forms in a grid layout. |
| 770 | 846 | * |
| 847 | + * @since 3.7.0 Sanitize attributes | |
| 771 | 848 | * @since 2.1.0 |
| 772 | 849 | * |
| 850 | + * @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 | |
| 851 | + * @since 2.23.1 Updated the default text color for the donate button, see #6591. | |
| 852 | + * @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868. | |
| 853 | + * change tag_text_color color to #333333. | |
| 854 | + * @since 2.20.0 $show_donate_button Option to show donate button | |
| 855 | + * @since 2.20.0 $donate_button_text Default Donate | |
| 856 | + * @since 2.20.0 $donate_button_background_color Default #66bb6a | |
| 857 | + * @since 2.20.0 $donate_button_text_color Default #fff | |
| 858 | + * @since 2.20.0 $show_bar Default false | |
| 859 | + * @since 2.22.2 remove $show_bar attribute in favor of show_goal | |
| 860 | + * | |
| 773 | 861 | * @param array $atts { |
| 774 | 862 | * Optional. Attributes of the form grid shortcode. |
| 775 | 863 | * |
| 776 | 864 | * @type int $forms_per_page Number of forms per page. Default '12'. |
| @@ -784,38 +872,49 @@ | ||
| 784 | 872 | * @type bool $show_title Whether to display form title. Default 'true'. |
| 785 | 873 | * @type bool $show_goal Whether to display form goal. Default 'true'. |
| 786 | 874 | * @type bool $show_excerpt Whether to display form excerpt. Default 'true'. |
| 787 | 875 | * @type bool $show_featured_image Whether to display featured image. Default 'true'. |
| 788 | - * @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes. | |
| 876 | + * @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes. | |
| 789 | 877 | * @type string $image_height Featured image height. Default 'auto'. Accepts valid CSS heights. |
| 790 | 878 | * @type int $excerpt_length Number of words before excerpt is truncated. Default '16'. |
| 791 | - * @type string $display_style How the form is displayed, either in new page or modal popup. | |
| 879 | + * @type string $display_style How the form is displayed, either in new page or modal popup. | |
| 792 | 880 | * Default 'redirect'. Accepts 'redirect', 'modal'. |
| 793 | - * } | |
| 881 | + * | |
| 794 | 882 | * @return string|bool The markup of the form grid or false. |
| 795 | 883 | */ |
| 796 | 884 | function give_form_grid_shortcode( $atts ) { |
| 797 | - | |
| 885 | + $atts = give_clean($atts); | |
| 798 | 886 | $give_settings = give_get_settings(); |
| 799 | 887 | |
| 800 | - $atts = shortcode_atts( array( | |
| 801 | - 'forms_per_page' => 12, | |
| 802 | - 'paged' => true, | |
| 803 | - 'ids' => '', | |
| 804 | - 'exclude' => '', | |
| 805 | - 'cats' => '', | |
| 806 | - 'tags' => '', | |
| 807 | - 'columns' => 'best-fit', | |
| 808 | - 'show_title' => true, | |
| 809 | - 'show_goal' => true, | |
| 810 | - 'show_excerpt' => true, | |
| 811 | - 'show_featured_image' => true, | |
| 812 | - 'image_size' => 'medium', | |
| 813 | - 'image_height' => 'auto', | |
| 814 | - 'excerpt_length' => 16, | |
| 815 | - 'display_style' => 'modal_reveal', | |
| 816 | - 'status' => '', // open or closed | |
| 817 | - ), $atts ); | |
| 888 | + $atts = shortcode_atts( | |
| 889 | + [ | |
| 890 | + 'forms_per_page' => 12, | |
| 891 | + 'paged' => true, | |
| 892 | + 'ids' => '', | |
| 893 | + 'exclude' => '', | |
| 894 | + 'orderby' => 'date', | |
| 895 | + 'order' => 'DESC', | |
| 896 | + 'cats' => '', | |
| 897 | + 'tags' => '', | |
| 898 | + 'columns' => '1', | |
| 899 | + 'show_title' => true, | |
| 900 | + 'show_goal' => true, | |
| 901 | + 'show_excerpt' => true, | |
| 902 | + 'show_featured_image' => true, | |
| 903 | + 'show_donate_button' => true, | |
| 904 | + 'donate_button_text' => '', | |
| 905 | + 'tag_background_color' => '#69b868', | |
| 906 | + 'tag_text_color' => '#333333', | |
| 907 | + 'donate_button_text_color' => '#000000', | |
| 908 | + 'image_size' => 'medium', | |
| 909 | + 'image_height' => 'auto', | |
| 910 | + 'excerpt_length' => 16, | |
| 911 | + 'display_style' => 'modal_reveal', | |
| 912 | + 'progress_bar_color' => '#69b868', | |
| 913 | + 'status' => '', // open or closed. | |
| 914 | + ], | |
| 915 | + $atts | |
| 916 | + ); | |
| 818 | 917 | |
| 819 | 918 | // Validate integer attributes. |
| 820 | 919 | $atts['forms_per_page'] = intval( $atts['forms_per_page'] ); |
| 821 | 920 | $atts['excerpt_length'] = intval( $atts['excerpt_length'] ); |
| @@ -820,15 +919,15 @@ | ||
| 820 | 919 | $atts['forms_per_page'] = intval( $atts['forms_per_page'] ); |
| 821 | 920 | $atts['excerpt_length'] = intval( $atts['excerpt_length'] ); |
| 822 | 921 | |
| 823 | 922 | // Validate boolean attributes. |
| 824 | - $boolean_attributes = array( | |
| 923 | + $boolean_attributes = [ | |
| 825 | 924 | 'paged', |
| 826 | 925 | 'show_title', |
| 827 | 926 | 'show_goal', |
| 828 | 927 | 'show_excerpt', |
| 829 | 928 | 'show_featured_image', |
| 830 | - ); | |
| 929 | + ]; | |
| 831 | 930 | |
| 832 | 931 | foreach ( $boolean_attributes as $att ) { |
| 833 | 932 | $atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN ); |
| 834 | 933 | } |
| @@ -833,27 +932,30 @@ | ||
| 833 | 932 | $atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN ); |
| 834 | 933 | } |
| 835 | 934 | |
| 836 | 935 | // Set default form query args. |
| 837 | - $form_args = array( | |
| 936 | + $form_args = [ | |
| 838 | 937 | 'post_type' => 'give_forms', |
| 839 | 938 | 'post_status' => 'publish', |
| 840 | 939 | 'posts_per_page' => $atts['forms_per_page'], |
| 841 | - 'tax_query' => array( | |
| 940 | + 'orderby' => $atts['orderby'], | |
| 941 | + 'order' => $atts['order'], | |
| 942 | + 'paged' => $atts['paged'], | |
| 943 | + 'tax_query' => [ | |
| 842 | 944 | 'relation' => 'AND', |
| 843 | - ), | |
| 844 | - ); | |
| 945 | + ], | |
| 946 | + ]; | |
| 845 | 947 | |
| 846 | 948 | // Filter results of form grid based on form status. |
| 847 | 949 | $form_closed_status = trim( $atts['status'] ); |
| 848 | 950 | |
| 849 | 951 | if ( ! empty( $form_closed_status ) ) { |
| 850 | - $form_args['meta_query'] = array( | |
| 851 | - array( | |
| 952 | + $form_args['meta_query'] = [ | |
| 953 | + [ | |
| 852 | 954 | 'key' => '_give_form_status', |
| 853 | 955 | 'value' => $form_closed_status, |
| 854 | - ), | |
| 855 | - ); | |
| 956 | + ], | |
| 957 | + ]; | |
| 856 | 958 | } |
| 857 | 959 | |
| 858 | 960 | // Maybe add pagination. |
| 859 | 961 | if ( true === $atts['paged'] ) { |
| @@ -861,38 +963,111 @@ | ||
| 861 | 963 | } |
| 862 | 964 | |
| 863 | 965 | // Maybe filter forms by IDs. |
| 864 | 966 | if ( ! empty( $atts['ids'] ) ) { |
| 865 | - $form_args['post__in'] = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ); | |
| 967 | + $form_args['post__in'] = array_map( | |
| 968 | + static function ($id) { | |
| 969 | + _give_redirect_form_id($id); | |
| 970 | + | |
| 971 | + return $id; | |
| 972 | + }, array_filter(array_map('trim', explode(',', $atts['ids']))) | |
| 973 | + ); | |
| 866 | 974 | } |
| 867 | 975 | |
| 868 | 976 | // Convert comma-separated form IDs into array. |
| 869 | 977 | if ( ! empty( $atts['exclude'] ) ) { |
| 870 | - $form_args['post__not_in'] = array_filter( array_map( function( $item ) { | |
| 871 | - return intval( trim( $item ) ); | |
| 872 | - }, explode( ',', $atts['exclude'] ) ) ); | |
| 978 | + $form_args['post__not_in'] = array_filter( | |
| 979 | + array_map( | |
| 980 | + function( $item ) { | |
| 981 | + return intval( trim( $item ) ); | |
| 982 | + }, | |
| 983 | + explode( ',', $atts['exclude'] ) | |
| 984 | + ) | |
| 985 | + ); | |
| 873 | 986 | } |
| 874 | 987 | |
| 875 | 988 | // Maybe filter by form category. |
| 876 | 989 | if ( ! empty( $atts['cats'] ) ) { |
| 877 | - $cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) ); | |
| 878 | - $tax_query = array( | |
| 879 | - 'taxonomy' => 'give_forms_category', | |
| 880 | - 'terms' => $cats, | |
| 881 | - ); | |
| 882 | - $form_args['tax_query'][] = $tax_query; | |
| 990 | + $cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) ); | |
| 991 | + | |
| 992 | + // Backward compatibility for term_ids. | |
| 993 | + $term_ids = array_unique( array_filter( $cats, 'is_numeric' ) ); | |
| 994 | + if ( $term_ids ) { | |
| 995 | + $form_args['tax_query'][] = [ | |
| 996 | + 'taxonomy' => 'give_forms_category', | |
| 997 | + 'terms' => $term_ids, | |
| 998 | + ]; | |
| 999 | + | |
| 1000 | + } | |
| 1001 | + | |
| 1002 | + $term_slug = array_unique( array_filter( array_diff( $cats, $term_ids ) ) ); | |
| 1003 | + if ( $term_slug ) { | |
| 1004 | + $form_args['tax_query'][] = [ | |
| 1005 | + 'taxonomy' => 'give_forms_category', | |
| 1006 | + 'field' => 'slug', | |
| 1007 | + 'terms' => $term_slug, | |
| 1008 | + ]; | |
| 1009 | + | |
| 1010 | + } | |
| 883 | 1011 | } |
| 884 | 1012 | |
| 885 | 1013 | // Maybe filter by form tag. |
| 886 | 1014 | if ( ! empty( $atts['tags'] ) ) { |
| 887 | - $tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) ); | |
| 888 | - $tax_query = array( | |
| 889 | - 'taxonomy' => 'give_forms_tag', | |
| 890 | - 'terms' => $tags, | |
| 891 | - ); | |
| 892 | - $form_args['tax_query'][] = $tax_query; | |
| 1015 | + $tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) ); | |
| 1016 | + | |
| 1017 | + // Backward compatibility for term_ids. | |
| 1018 | + $tag_ids = array_unique( array_filter( $tags, 'is_numeric' ) ); | |
| 1019 | + if ( $tag_ids ) { | |
| 1020 | + $form_args['tax_query'][] = [ | |
| 1021 | + 'taxonomy' => 'give_forms_tag', | |
| 1022 | + 'terms' => $tag_ids, | |
| 1023 | + ]; | |
| 1024 | + | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + $tag_slug = array_unique( array_filter( array_diff( $tags, $tag_ids ) ) ); | |
| 1028 | + if ( $tag_slug ) { | |
| 1029 | + $form_args['tax_query'][] = [ | |
| 1030 | + 'taxonomy' => 'give_forms_tag', | |
| 1031 | + 'field' => 'slug', | |
| 1032 | + 'terms' => $tag_slug, | |
| 1033 | + ]; | |
| 1034 | + | |
| 1035 | + } | |
| 893 | 1036 | } |
| 894 | 1037 | |
| 1038 | + /** | |
| 1039 | + * Filter to modify WP Query for Total Goal. | |
| 1040 | + * | |
| 1041 | + * @since 2.1.4 | |
| 1042 | + * | |
| 1043 | + * @param array $form_args WP query argument for Grid. | |
| 1044 | + * | |
| 1045 | + * @return array $form_args WP query argument for Grid. | |
| 1046 | + */ | |
| 1047 | + $form_args = (array) apply_filters( 'give_form_grid_shortcode_query_args', $form_args ); | |
| 1048 | + | |
| 1049 | + // Maybe filter by form Amount Donated or Number of Donations. | |
| 1050 | + switch ( $atts['orderby'] ) { | |
| 1051 | + case 'amount_donated': | |
| 1052 | + $form_args['meta_key'] = '_give_form_earnings'; | |
| 1053 | + $form_args['orderby'] = 'meta_value_num'; | |
| 1054 | + break; | |
| 1055 | + case 'number_donations': | |
| 1056 | + $form_args['meta_key'] = '_give_form_sales'; | |
| 1057 | + $form_args['orderby'] = 'meta_value_num'; | |
| 1058 | + break; | |
| 1059 | + case 'random': | |
| 1060 | + $form_args['orderby'] = 'rand'; | |
| 1061 | + break; | |
| 1062 | + case 'closest_to_goal': | |
| 1063 | + if ( give_has_upgrade_completed( 'v240_update_form_goal_progress' ) ) { | |
| 1064 | + $form_args['meta_key'] = '_give_form_goal_progress'; | |
| 1065 | + $form_args['orderby'] = 'meta_value_num'; | |
| 1066 | + } | |
| 1067 | + break; | |
| 1068 | + } | |
| 1069 | + | |
| 895 | 1070 | // Query to output donation forms. |
| 896 | 1071 | $form_query = new WP_Query( $form_args ); |
| 897 | 1072 | |
| 898 | 1073 | if ( $form_query->have_posts() ) { |
| @@ -909,9 +1084,9 @@ | ||
| 909 | 1084 | while ( $form_query->have_posts() ) { |
| 910 | 1085 | $form_query->the_post(); |
| 911 | 1086 | |
| 912 | 1087 | // Give/templates/shortcode-form-grid.php. |
| 913 | - give_get_template( 'shortcode-form-grid', array( $give_settings, $atts ) ); | |
| 1088 | + give_get_template( 'shortcode-form-grid', [ $give_settings, $atts ] ); | |
| 914 | 1089 | |
| 915 | 1090 | } |
| 916 | 1091 | |
| 917 | 1092 | wp_reset_postdata(); |
| @@ -923,9 +1098,9 @@ | ||
| 923 | 1098 | remove_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10 ); |
| 924 | 1099 | remove_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10 ); |
| 925 | 1100 | |
| 926 | 1101 | if ( false !== $atts['paged'] ) { |
| 927 | - $paginate_args = array( | |
| 1102 | + $paginate_args = [ | |
| 928 | 1103 | 'current' => max( 1, get_query_var( 'paged' ) ), |
| 929 | 1104 | 'total' => $form_query->max_num_pages, |
| 930 | 1105 | 'show_all' => false, |
| 931 | 1106 | 'end_size' => 1, |
| @@ -930,13 +1105,13 @@ | ||
| 930 | 1105 | 'show_all' => false, |
| 931 | 1106 | 'end_size' => 1, |
| 932 | 1107 | 'mid_size' => 2, |
| 933 | 1108 | 'prev_next' => true, |
| 934 | - 'prev_text' => __( '« Previous', 'give' ), | |
| 935 | - 'next_text' => __( 'Next »', 'give' ), | |
| 1109 | + 'prev_text' => __( '« Previous', 'give' ), | |
| 1110 | + 'next_text' => __( 'Next »', 'give' ), | |
| 936 | 1111 | 'type' => 'plain', |
| 937 | 1112 | 'add_args' => false, |
| 938 | - ); | |
| 1113 | + ]; | |
| 939 | 1114 | |
| 940 | 1115 | printf( |
| 941 | 1116 | '<div class="give-page-numbers">%s</div>', |
| 942 | 1117 | paginate_links( $paginate_args ) |
| @@ -944,8 +1119,9 @@ | ||
| 944 | 1119 | } |
| 945 | 1120 | echo '</div><!-- .give-wrap -->'; |
| 946 | 1121 | |
| 947 | 1122 | return ob_get_clean(); |
| 948 | - } | |
| 1123 | + } // End if(). | |
| 949 | 1124 | } |
| 950 | 1125 | |
| 951 | 1126 | add_shortcode( 'give_form_grid', 'give_form_grid_shortcode' ); |
| 1127 | + | |