| @@ -3,273 +3,14 @@ | ||
| 3 | 3 | * Offline Donations Gateway |
| 4 | 4 | * |
| 5 | 5 | * @package Give |
| 6 | 6 | * @subpackage Gateways |
| 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 | /** |
| 13 | - * Register the payment gateway | |
| 14 | - * | |
| 15 | - * @since 1.0 | |
| 16 | - * | |
| 17 | - * @param array $gateways | |
| 18 | - * | |
| 19 | - * @return array | |
| 20 | - */ | |
| 21 | -function give_offline_register_gateway( $gateways ) { | |
| 22 | - // Format: ID => Name | |
| 23 | - $gateways['offline'] = array( | |
| 24 | - 'admin_label' => esc_attr__( 'Offline Donation', 'give' ), | |
| 25 | - 'checkout_label' => esc_attr__( 'Offline Donation', 'give' ), | |
| 26 | - ); | |
| 27 | - | |
| 28 | - return $gateways; | |
| 29 | -} | |
| 30 | - | |
| 31 | -add_filter( 'give_payment_gateways', 'give_offline_register_gateway', 1 ); | |
| 32 | - | |
| 33 | -/** | |
| 34 | - * Add our payment instructions to the checkout | |
| 35 | - * | |
| 36 | - * @since 1.0 | |
| 37 | - * | |
| 38 | - * @param int $form_id Give form id. | |
| 39 | - * | |
| 40 | - * @return void | |
| 41 | - */ | |
| 42 | -function give_offline_payment_cc_form( $form_id ) { | |
| 43 | - // Get offline payment instruction. | |
| 44 | - $offline_instructions = give_get_offline_payment_instruction( $form_id, true ); | |
| 45 | - | |
| 46 | - ob_start(); | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Fires before the offline info fields. | |
| 50 | - * | |
| 51 | - * @since 1.0 | |
| 52 | - * | |
| 53 | - * @param int $form_id Give form id. | |
| 54 | - */ | |
| 55 | - do_action( 'give_before_offline_info_fields', $form_id ); | |
| 56 | - ?> | |
| 57 | - <fieldset id="give_offline_payment_info"> | |
| 58 | - <?php echo stripslashes( $offline_instructions ); ?> | |
| 59 | - </fieldset> | |
| 60 | - <?php | |
| 61 | - /** | |
| 62 | - * Fires after the offline info fields. | |
| 63 | - * | |
| 64 | - * @since 1.0 | |
| 65 | - * | |
| 66 | - * @param int $form_id Give form id. | |
| 67 | - */ | |
| 68 | - do_action( 'give_after_offline_info_fields', $form_id ); | |
| 69 | - | |
| 70 | - echo ob_get_clean(); | |
| 71 | -} | |
| 72 | - | |
| 73 | -add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' ); | |
| 74 | - | |
| 75 | -/** | |
| 76 | - * Give Offline Billing Field | |
| 77 | - * | |
| 78 | - * @param $form_id | |
| 79 | - */ | |
| 80 | -function give_offline_billing_fields( $form_id ) { | |
| 81 | - //Enable Default CC fields (billing info) | |
| 82 | - $post_offline_cc_fields = give_get_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ); | |
| 83 | - $post_offline_customize_option = give_get_meta( $form_id, '_give_customize_offline_donations', true ); | |
| 84 | - | |
| 85 | - $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); | |
| 86 | - | |
| 87 | - //Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options | |
| 88 | - if ( | |
| 89 | - ( give_is_setting_enabled( $post_offline_customize_option, 'global' ) && give_is_setting_enabled( $global_offline_cc_fields ) ) | |
| 90 | - || ( give_is_setting_enabled( $post_offline_customize_option, 'enabled' ) && give_is_setting_enabled( $post_offline_cc_fields ) ) | |
| 91 | - ) { | |
| 92 | - give_default_cc_address_fields( $form_id ); | |
| 93 | - } | |
| 94 | -} | |
| 95 | - | |
| 96 | -add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 ); | |
| 97 | - | |
| 98 | -/** | |
| 99 | - * Process the payment | |
| 100 | - * | |
| 101 | - * @since 1.0 | |
| 102 | - * | |
| 103 | - * @param $purchase_data | |
| 104 | - * | |
| 105 | - * @return void | |
| 106 | - */ | |
| 107 | -function give_offline_process_payment( $purchase_data ) { | |
| 108 | - | |
| 109 | - // Setup the payment details. | |
| 110 | - $payment_data = array( | |
| 111 | - 'price' => $purchase_data['price'], | |
| 112 | - 'give_form_title' => $purchase_data['post_data']['give-form-title'], | |
| 113 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), | |
| 114 | - 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '', | |
| 115 | - 'date' => $purchase_data['date'], | |
| 116 | - 'user_email' => $purchase_data['user_email'], | |
| 117 | - 'purchase_key' => $purchase_data['purchase_key'], | |
| 118 | - 'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ), | |
| 119 | - 'user_info' => $purchase_data['user_info'], | |
| 120 | - 'status' => 'pending', | |
| 121 | - 'gateway' => 'offline', | |
| 122 | - ); | |
| 123 | - | |
| 124 | - | |
| 125 | - // record the pending payment | |
| 126 | - $payment = give_insert_payment( $payment_data ); | |
| 127 | - | |
| 128 | - if ( $payment ) { | |
| 129 | - give_send_to_success_page(); | |
| 130 | - } else { | |
| 131 | - // if errors are present, send the user back to the donation form so they can be corrected | |
| 132 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); | |
| 133 | - } | |
| 134 | - | |
| 135 | -} | |
| 136 | - | |
| 137 | -add_action( 'give_gateway_offline', 'give_offline_process_payment' ); | |
| 138 | - | |
| 139 | - | |
| 140 | -/** | |
| 141 | - * Send Offline Donation Instructions | |
| 142 | - * | |
| 143 | - * Sends a notice to the donor with offline instructions; can be customized per form | |
| 144 | - * | |
| 145 | - * @param int $payment_id | |
| 146 | - * | |
| 147 | - * @since 1.0 | |
| 148 | - * @return void | |
| 149 | - */ | |
| 150 | -function give_offline_send_donor_instructions( $payment_id = 0 ) { | |
| 151 | - | |
| 152 | - $payment_data = give_get_payment_meta( $payment_id ); | |
| 153 | - $post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true ); | |
| 154 | - | |
| 155 | - //Customize email content depending on whether the single form has been customized | |
| 156 | - $email_content = give_get_option( 'global_offline_donation_email' ); | |
| 157 | - | |
| 158 | - if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { | |
| 159 | - $email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true ); | |
| 160 | - } | |
| 161 | - | |
| 162 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); | |
| 163 | - | |
| 164 | - /** | |
| 165 | - * Filters the from name. | |
| 166 | - * | |
| 167 | - * @since 1.7 | |
| 168 | - */ | |
| 169 | - $from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data ); | |
| 170 | - | |
| 171 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); | |
| 172 | - | |
| 173 | - /** | |
| 174 | - * Filters the from email. | |
| 175 | - * | |
| 176 | - * @since 1.7 | |
| 177 | - */ | |
| 178 | - $from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data ); | |
| 179 | - | |
| 180 | - $to_email = give_get_payment_user_email( $payment_id ); | |
| 181 | - | |
| 182 | - $subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) ); | |
| 183 | - if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { | |
| 184 | - $subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true ); | |
| 185 | - } | |
| 186 | - | |
| 187 | - $subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id ); | |
| 188 | - $subject = give_do_email_tags( $subject, $payment_id ); | |
| 189 | - | |
| 190 | - $attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data ); | |
| 191 | - $message = give_do_email_tags( $email_content, $payment_id ); | |
| 192 | - | |
| 193 | - $emails = Give()->emails; | |
| 194 | - | |
| 195 | - $emails->__set( 'from_name', $from_name ); | |
| 196 | - $emails->__set( 'from_email', $from_email ); | |
| 197 | - $emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) ); | |
| 198 | - | |
| 199 | - $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data ); | |
| 200 | - $emails->__set( 'headers', $headers ); | |
| 201 | - | |
| 202 | - $emails->send( $to_email, $subject, $message, $attachments ); | |
| 203 | - | |
| 204 | -} | |
| 205 | - | |
| 206 | - | |
| 207 | -/** | |
| 208 | - * Send Offline Donation Admin Notice. | |
| 209 | - * | |
| 210 | - * Sends a notice to site admins about the pending donation. | |
| 211 | - * | |
| 212 | - * @since 1.0 | |
| 213 | - * | |
| 214 | - * @param int $payment_id | |
| 215 | - * | |
| 216 | - * @return void | |
| 217 | - * | |
| 218 | - */ | |
| 219 | -function give_offline_send_admin_notice( $payment_id = 0 ) { | |
| 220 | - | |
| 221 | - /* Send an email notification to the admin */ | |
| 222 | - $admin_email = give_get_admin_notice_emails(); | |
| 223 | - $user_info = give_get_payment_meta_user_info( $payment_id ); | |
| 224 | - | |
| 225 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { | |
| 226 | - $user_data = get_userdata( $user_info['id'] ); | |
| 227 | - $name = $user_data->display_name; | |
| 228 | - } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { | |
| 229 | - $name = $user_info['first_name'] . ' ' . $user_info['last_name']; | |
| 230 | - } else { | |
| 231 | - $name = $user_info['email']; | |
| 232 | - } | |
| 233 | - | |
| 234 | - $amount = give_donation_amount( $payment_id ); | |
| 235 | - | |
| 236 | - $admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id ); | |
| 237 | - | |
| 238 | - $admin_message = __( 'Dear Admin,', 'give' ) . "\n\n"; | |
| 239 | - $admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n"; | |
| 240 | - $admin_message .= __( 'The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n"; | |
| 241 | - | |
| 242 | - | |
| 243 | - $admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n"; | |
| 244 | - $admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n"; | |
| 245 | - | |
| 246 | - $admin_message .= sprintf( | |
| 247 | - '<a href="%1$s">%2$s</a>', | |
| 248 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ), | |
| 249 | - __( 'View Donation Details »', 'give' ) | |
| 250 | - ) . "\n\n"; | |
| 251 | - | |
| 252 | - $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id ); | |
| 253 | - $admin_message = give_do_email_tags( $admin_message, $payment_id ); | |
| 254 | - | |
| 255 | - $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id ); | |
| 256 | - $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id ); | |
| 257 | - | |
| 258 | - //Send Email | |
| 259 | - $emails = Give()->emails; | |
| 260 | - $emails->__set( 'heading', __( 'New Offline Donation', 'give' ) ); | |
| 261 | - | |
| 262 | - if ( ! empty( $admin_headers ) ) { | |
| 263 | - $emails->__set( 'headers', $admin_headers ); | |
| 264 | - } | |
| 265 | - | |
| 266 | - $emails->send( $admin_email, $admin_subject, $admin_message, $attachments ); | |
| 267 | - | |
| 268 | -} | |
| 269 | - | |
| 270 | - | |
| 271 | -/** | |
| 272 | 13 | * Register gateway settings. |
| 273 | 14 | * |
| 274 | 15 | * @param $settings |
| 275 | 16 | * |
| @@ -281,36 +22,38 @@ | ||
| 281 | 22 | if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) { |
| 282 | 23 | return $settings; |
| 283 | 24 | } |
| 284 | 25 | |
| 285 | - //Vars | |
| 26 | + // Vars | |
| 286 | 27 | $prefix = '_give_'; |
| 287 | 28 | |
| 288 | 29 | $is_gateway_active = give_is_gateway_active( 'offline' ); |
| 289 | 30 | |
| 290 | - //this gateway isn't active | |
| 31 | + // this gateway isn't active | |
| 291 | 32 | if ( ! $is_gateway_active ) { |
| 292 | - //return settings and bounce | |
| 33 | + // return settings and bounce | |
| 293 | 34 | return $settings; |
| 294 | 35 | } |
| 295 | 36 | |
| 296 | - //Fields | |
| 297 | - $check_settings = array( | |
| 37 | + // Fields | |
| 38 | + $check_settings = [ | |
| 298 | 39 | |
| 299 | - array( | |
| 40 | + [ | |
| 300 | 41 | 'name' => __( 'Offline Donations', 'give' ), |
| 301 | 42 | 'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ), |
| 302 | 43 | 'id' => $prefix . 'customize_offline_donations', |
| 303 | 44 | 'type' => 'radio_inline', |
| 304 | 45 | 'default' => 'global', |
| 305 | - 'options' => apply_filters( 'give_forms_content_options_select', array( | |
| 46 | + 'options' => apply_filters( | |
| 47 | + 'give_forms_content_options_select', | |
| 48 | + [ | |
| 306 | 49 | 'global' => __( 'Global Option', 'give' ), |
| 307 | 50 | 'enabled' => __( 'Customize', 'give' ), |
| 308 | 51 | 'disabled' => __( 'Disable', 'give' ), |
| 309 | - ) | |
| 52 | + ] | |
| 310 | 53 | ), |
| 311 | - ), | |
| 312 | - array( | |
| 54 | + ], | |
| 55 | + [ | |
| 313 | 56 | 'name' => __( 'Billing Fields', 'give' ), |
| 314 | 57 | 'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ), |
| 315 | 58 | 'id' => $prefix . 'offline_donation_enable_billing_fields_single', |
| 316 | 59 | 'row_classes' => 'give-subfield give-hidden', |
| @@ -315,14 +58,14 @@ | ||
| 315 | 58 | 'id' => $prefix . 'offline_donation_enable_billing_fields_single', |
| 316 | 59 | 'row_classes' => 'give-subfield give-hidden', |
| 317 | 60 | 'type' => 'radio_inline', |
| 318 | 61 | 'default' => 'disabled', |
| 319 | - 'options' => array( | |
| 62 | + 'options' => [ | |
| 320 | 63 | 'enabled' => __( 'Enabled', 'give' ), |
| 321 | 64 | 'disabled' => __( 'Disabled', 'give' ), |
| 322 | - ), | |
| 323 | - ), | |
| 324 | - array( | |
| 65 | + ], | |
| 66 | + ], | |
| 67 | + [ | |
| 325 | 68 | 'id' => $prefix . 'offline_checkout_notes', |
| 326 | 69 | 'name' => __( 'Donation Instructions', 'give' ), |
| 327 | 70 | 'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ), |
| 328 | 71 | 'default' => give_get_default_offline_donation_content(), |
| @@ -327,19 +70,19 @@ | ||
| 327 | 70 | 'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ), |
| 328 | 71 | 'default' => give_get_default_offline_donation_content(), |
| 329 | 72 | 'type' => 'wysiwyg', |
| 330 | 73 | 'row_classes' => 'give-subfield give-hidden', |
| 331 | - 'options' => array( | |
| 74 | + 'options' => [ | |
| 332 | 75 | 'textarea_rows' => 6, |
| 333 | - ) | |
| 334 | - ), | |
| 335 | - array( | |
| 76 | + ], | |
| 77 | + ], | |
| 78 | + [ | |
| 336 | 79 | 'name' => 'offline_docs', |
| 337 | 80 | 'type' => 'docs_link', |
| 338 | 81 | 'url' => 'http://docs.givewp.com/settings-gateway-offline-donations', |
| 339 | 82 | 'title' => __( 'Offline Donations', 'give' ), |
| 340 | - ), | |
| 341 | - ); | |
| 83 | + ], | |
| 84 | + ]; | |
| 342 | 85 | |
| 343 | 86 | return array_merge( $settings, $check_settings ); |
| 344 | 87 | } |
| 345 | 88 | |
| @@ -353,24 +96,26 @@ | ||
| 353 | 96 | * |
| 354 | 97 | * @return string |
| 355 | 98 | */ |
| 356 | 99 | function give_get_default_offline_donation_content() { |
| 357 | - $default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>'; | |
| 100 | + $default_text = '<p>' . __( 'To make an offline donation toward this cause, follow these steps:', 'give' ) . ' </p>'; | |
| 358 | 101 | $default_text .= '<ol>'; |
| 359 | 102 | $default_text .= '<li>'; |
| 360 | 103 | $default_text .= sprintf( |
| 361 | - /* translators: %s: site name */ | |
| 362 | - __( 'Make a check payable to "{sitename}"', 'give' ) ); | |
| 104 | + /* translators: %s: site name */ | |
| 105 | + __( 'Write a check payable to "{sitename}"', 'give' ) | |
| 106 | + ); | |
| 363 | 107 | $default_text .= '</li>'; |
| 364 | 108 | $default_text .= '<li>'; |
| 365 | 109 | $default_text .= sprintf( |
| 366 | - /* translators: %s: site name */ | |
| 367 | - __( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' ) ); | |
| 110 | + /* translators: %s: site name */ | |
| 111 | + __( 'On the memo line of the check, indicate that the donation is for "{sitename}"', 'give' ) | |
| 112 | + ); | |
| 368 | 113 | $default_text .= '</li>'; |
| 369 | - $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>'; | |
| 114 | + $default_text .= '<li>' . __( 'Mail your check to:', 'give' ) . '</li>'; | |
| 370 | 115 | $default_text .= '</ol>'; |
| 371 | 116 | $default_text .= '{offline_mailing_address}<br>'; |
| 372 | - $default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>'; | |
| 117 | + $default_text .= '<p>' . __( 'Your tax-deductible donation is greatly appreciated!', 'give' ) . '</p>'; | |
| 373 | 118 | |
| 374 | 119 | return apply_filters( 'give_default_offline_donation_content', $default_text ); |
| 375 | 120 | |
| 376 | 121 | } |
| @@ -379,43 +124,65 @@ | ||
| 379 | 124 | * Offline Donation Email Content |
| 380 | 125 | * |
| 381 | 126 | * Gets the default offline donation email content |
| 382 | 127 | * |
| 128 | + * @since 2.14.0 Remove unnecessary sprintf | |
| 129 | + * | |
| 383 | 130 | * @return string |
| 384 | 131 | */ |
| 385 | 132 | function give_get_default_offline_donation_email_content() { |
| 386 | - $default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>'; | |
| 387 | - $default_text .= '<p>' . __( 'Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give' ) . '</p>'; | |
| 133 | + $default_text = '<p>' . __( 'Hi {name},', 'give' ) . '</p>'; | |
| 134 | + $default_text .= '<p>' . __( 'Thank you for letting us know that you\'re mailing a check! Your generosity is greatly appreciated. Here are those steps again:', 'give' ) . '</p>'; | |
| 388 | 135 | $default_text .= '<ol>'; |
| 389 | 136 | $default_text .= '<li>'; |
| 390 | - $default_text .= sprintf( | |
| 391 | - /* translators: %s: site name */ | |
| 392 | - __( 'Make a check payable to "{sitename}"', 'give' ) | |
| 393 | - ); | |
| 137 | + $default_text .= esc_html__( 'Write a check payable to "{sitename}"', 'give' ); | |
| 394 | 138 | $default_text .= '</li>'; |
| 395 | 139 | $default_text .= '<li>'; |
| 396 | - $default_text .= sprintf( | |
| 397 | - __( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' ) | |
| 398 | - ); | |
| 140 | + $default_text .= esc_html__( 'On the memo line of the check, indicate that the donation is for "{form_title}"', 'give' ); | |
| 399 | 141 | $default_text .= '</li>'; |
| 400 | - $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>'; | |
| 142 | + $default_text .= '<li>' . __( 'Mail your check to:', 'give' ) . '</li>'; | |
| 401 | 143 | $default_text .= '</ol>'; |
| 402 | 144 | $default_text .= '{offline_mailing_address}<br>'; |
| 403 | - $default_text .= '<p>' . __( 'Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>'; | |
| 404 | - $default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>'; | |
| 145 | + $default_text .= '<p>' . esc_html__( 'Once we receive the check, we will mark it as complete in our system, which will generate an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>'; | |
| 146 | + $default_text .= '<p>' . esc_html__( 'Thanks in advance!', 'give' ) . '</p>'; | |
| 405 | 147 | $default_text .= '<p>{sitename}</p>'; |
| 406 | 148 | |
| 407 | 149 | return apply_filters( 'give_default_offline_donation_content', $default_text ); |
| 150 | +} | |
| 408 | 151 | |
| 152 | +/** | |
| 153 | + * Get formatted offline instructions | |
| 154 | + * | |
| 155 | + * @since 2.15.0 | |
| 156 | + * | |
| 157 | + * @param string $instructions | |
| 158 | + * @param int $form_id | |
| 159 | + * @param bool $wpautop | |
| 160 | + * | |
| 161 | + * @return string | |
| 162 | + */ | |
| 163 | +function get_formatted_offline_instructions( $instructions, $form_id, $wpautop = false ) { | |
| 164 | + $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' ); | |
| 165 | + | |
| 166 | + /* translators: %s: form settings url */ | |
| 167 | + $offline_instructions = ! empty( $instructions ) ? $instructions : sprintf( | |
| 168 | + __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), | |
| 169 | + $settings_url | |
| 170 | + ); | |
| 171 | + | |
| 172 | + $offline_instructions = give_do_email_tags($offline_instructions, ['form_id' => $form_id]); | |
| 173 | + | |
| 174 | + return $wpautop ? wpautop( do_shortcode( $offline_instructions ) ) : $offline_instructions; | |
| 409 | 175 | } |
| 410 | 176 | |
| 411 | 177 | /** |
| 412 | 178 | * Get offline payment instructions. |
| 413 | 179 | * |
| 180 | + * @since 2.15.0 - conditionally display instructions based on form settings | |
| 414 | 181 | * @since 1.7 |
| 415 | 182 | * |
| 416 | - * @param int $form_id | |
| 417 | - * @param bool $wpautop | |
| 183 | + * @param int $form_id | |
| 184 | + * @param bool $wpautop | |
| 418 | 185 | * |
| 419 | 186 | * @return string |
| 420 | 187 | */ |
| 421 | 188 | function give_get_offline_payment_instruction( $form_id, $wpautop = false ) { |
| @@ -424,47 +191,36 @@ | ||
| 424 | 191 | return ''; |
| 425 | 192 | } |
| 426 | 193 | |
| 427 | 194 | $post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true ); |
| 428 | - $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true ); | |
| 429 | - $global_offline_instruction = give_get_option( 'global_offline_donation_content' ); | |
| 430 | - $offline_instructions = $global_offline_instruction; | |
| 195 | + $post_offline_customization_option_enabled = give_is_setting_enabled( $post_offline_customization_option ); | |
| 431 | 196 | |
| 432 | - if ( give_is_setting_enabled( $post_offline_customization_option ) ) { | |
| 433 | - $offline_instructions = $post_offline_instructions; | |
| 197 | + if ( $post_offline_customization_option === 'disabled' ) { | |
| 198 | + return ''; | |
| 434 | 199 | } |
| 435 | 200 | |
| 436 | - $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' ); | |
| 201 | + $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true ); | |
| 202 | + $global_offline_instructions = give_get_option( 'global_offline_donation_content' ); | |
| 203 | + $offline_instructions_content = $post_offline_customization_option_enabled ? $post_offline_instructions : $global_offline_instructions; | |
| 437 | 204 | |
| 438 | - /* translators: %s: form settings url */ | |
| 439 | - $offline_instructions = ! empty( $offline_instructions ) | |
| 440 | - ? $offline_instructions | |
| 441 | - : sprintf( | |
| 442 | - __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), | |
| 443 | - $settings_url | |
| 444 | - ); | |
| 205 | + $formatted_offline_instructions = get_formatted_offline_instructions( | |
| 206 | + $offline_instructions_content, | |
| 207 | + $form_id, | |
| 208 | + $wpautop | |
| 209 | + ); | |
| 445 | 210 | |
| 446 | - $offline_instructions = give_do_email_tags( $offline_instructions, null ); | |
| 447 | - | |
| 448 | - $formmated_offline_instructions = $wpautop | |
| 449 | - ? wpautop( do_shortcode( $offline_instructions ) ) | |
| 450 | - : $offline_instructions; | |
| 451 | - | |
| 452 | 211 | /** |
| 453 | 212 | * Filter the offline instruction content |
| 454 | 213 | * |
| 455 | 214 | * @since 2.2.0 |
| 456 | - * | |
| 457 | 215 | */ |
| 458 | - $formmated_offline_instructions = apply_filters( | |
| 216 | + return apply_filters( | |
| 459 | 217 | 'give_the_offline_instructions_content', |
| 460 | - $formmated_offline_instructions, | |
| 461 | - $offline_instructions, | |
| 218 | + $formatted_offline_instructions, | |
| 219 | + $offline_instructions_content, | |
| 462 | 220 | $form_id, |
| 463 | 221 | $wpautop |
| 464 | 222 | ); |
| 465 | - | |
| 466 | - return $formmated_offline_instructions; | |
| 467 | 223 | } |
| 468 | 224 | |
| 469 | 225 | |
| 470 | 226 | /** |
| @@ -471,9 +227,9 @@ | ||
| 471 | 227 | * Remove offline gateway from gateway list of offline disable for form. |
| 472 | 228 | * |
| 473 | 229 | * @since 1.8 |
| 474 | 230 | * |
| 475 | - * @param array $gateway_list | |
| 231 | + * @param array $gateway_list | |
| 476 | 232 | * @param $form_id |
| 477 | 233 | * |
| 478 | 234 | * @return array |
| 479 | 235 | */ |
| @@ -481,9 +237,9 @@ | ||
| 481 | 237 | if ( |
| 482 | 238 | // Show offline payment gateway if enable for new donation form. |
| 483 | 239 | ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) ) |
| 484 | 240 | && $form_id |
| 485 | - && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true ), array( 'enabled', 'global' ) ) | |
| 241 | + && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true, 'global' ), [ 'enabled', 'global' ] ) | |
| 486 | 242 | ) { |
| 487 | 243 | unset( $gateway_list['offline'] ); |
| 488 | 244 | } |
| 489 | 245 | |
| @@ -506,9 +262,9 @@ | ||
| 506 | 262 | * @return void |
| 507 | 263 | */ |
| 508 | 264 | function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) { |
| 509 | 265 | if ( |
| 510 | - ! give_is_setting_enabled( $meta_value, array( 'global', 'enabled' ) ) | |
| 266 | + ! give_is_setting_enabled( $meta_value, [ 'global', 'enabled' ] ) | |
| 511 | 267 | && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) ) |
| 512 | 268 | ) { |
| 513 | 269 | give_update_meta( $postid, '_give_default_gateway', 'global' ); |
| 514 | 270 | } |