← All changes
|
includes/admin/emails/class-offline-donation-instruction-email.php
+49
-33
2.3.0
→
4.18.0
View file →
| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * This class handles all email notification settings. |
| 6 | 6 | * |
| 7 | 7 | * @package Give |
| 8 | 8 | * @subpackage Classes/Emails |
| 9 | - * @copyright Copyright (c) 2016, WordImpress | |
| 9 | + * @copyright Copyright (c) 2016, GiveWP | |
| 10 | 10 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 11 | 11 | * @since 2.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| @@ -37,30 +37,32 @@ | ||
| 37 | 37 | public function init() { |
| 38 | 38 | // Initialize empty payment. |
| 39 | 39 | $this->payment = new Give_Payment( 0 ); |
| 40 | 40 | |
| 41 | - $this->load( array( | |
| 42 | - 'id' => 'offline-donation-instruction', | |
| 43 | - 'label' => __( 'Offline Donation Instructions', 'give' ), | |
| 44 | - 'description' => __( 'Sent to the donor when they submit an offline donation.', 'give' ), | |
| 45 | - 'notification_status' => give_is_gateway_active( 'offline' ) ? 'enabled' : 'disabled', | |
| 46 | - 'form_metabox_setting' => true, | |
| 47 | - 'notification_status_editable' => false, | |
| 48 | - 'preview_email_tag_values' => array( | |
| 49 | - 'payment_method' => esc_html__( 'Offline', 'give' ), | |
| 50 | - ), | |
| 51 | - 'default_email_subject' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), | |
| 52 | - 'default_email_message' => give_get_default_offline_donation_email_content(), | |
| 53 | - 'default_email_header' => __( 'Offline Donation Instructions', 'give' ), | |
| 54 | - 'notices' => array( | |
| 55 | - 'non-notification-status-editable' => sprintf( | |
| 56 | - '%1$s <a href="%2$s">%3$s »</a>', | |
| 57 | - __( 'This notification is automatically toggled based on whether the gateway is enabled or not.', 'give' ), | |
| 58 | - esc_url( admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=offline-donations') ), | |
| 59 | - __( 'Edit Setting', 'give' ) | |
| 60 | - ) | |
| 61 | - ), | |
| 62 | - ) ); | |
| 41 | + $this->load( | |
| 42 | + array( | |
| 43 | + 'id' => 'offline-donation-instruction', | |
| 44 | + 'label' => __( 'Offline Donation Instructions', 'give' ), | |
| 45 | + 'description' => __( 'Sent to the donor when they submit an offline donation.', 'give' ), | |
| 46 | + 'notification_status' => give_is_gateway_active( 'offline' ) ? 'enabled' : 'disabled', | |
| 47 | + 'form_metabox_setting' => true, | |
| 48 | + 'notification_status_editable' => false, | |
| 49 | + 'preview_email_tag_values' => array( | |
| 50 | + 'payment_method' => esc_html__( 'Offline', 'give' ), | |
| 51 | + ), | |
| 52 | + 'default_email_subject' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), | |
| 53 | + 'default_email_message' => give_get_default_offline_donation_email_content(), | |
| 54 | + 'default_email_header' => __( 'Offline Donation Instructions', 'give' ), | |
| 55 | + 'notices' => array( | |
| 56 | + 'non-notification-status-editable' => sprintf( | |
| 57 | + '%1$s <a href="%2$s">%3$s »</a>', | |
| 58 | + __( 'This notification is automatically toggled based on whether the gateway is enabled or not.', 'give' ), | |
| 59 | + esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=offline-donations' ) ), | |
| 60 | + __( 'Edit Setting', 'give' ) | |
| 61 | + ), | |
| 62 | + ), | |
| 63 | + ) | |
| 64 | + ); | |
| 63 | 65 | |
| 64 | 66 | add_action( 'give_insert_payment', array( $this, 'setup_email_notification' ) ); |
| 65 | 67 | add_action( 'give_save_settings_give_settings', array( $this, 'set_notification_status' ), 10, 2 ); |
| 66 | 68 | } |
| @@ -209,8 +211,9 @@ | ||
| 209 | 211 | |
| 210 | 212 | /** |
| 211 | 213 | * Setup email notification. |
| 212 | 214 | * |
| 215 | + * @since 4.18.0 Check the gateway from meta before loading the legacy payment object. | |
| 213 | 216 | * @since 2.0 |
| 214 | 217 | * @access public |
| 215 | 218 | * |
| 216 | 219 | * @param int $payment_id |
| @@ -215,13 +218,24 @@ | ||
| 215 | 218 | * |
| 216 | 219 | * @param int $payment_id |
| 217 | 220 | */ |
| 218 | 221 | public function setup_email_notification( $payment_id ) { |
| 222 | + // Exit if not donation was not with offline donation. Checked from meta first so every | |
| 223 | + // non-offline donation does not pay for building a Give_Payment on insert. | |
| 224 | + if ( 'offline' !== give_get_payment_gateway( $payment_id ) ) { | |
| 225 | + return; | |
| 226 | + } | |
| 227 | + | |
| 219 | 228 | $this->payment = new Give_Payment( $payment_id ); |
| 220 | 229 | |
| 221 | - // Exit if not donation was not with offline donation. | |
| 222 | - if ( 'offline' !== $this->payment->gateway ) { | |
| 223 | - return; | |
| 230 | + if ( ! $this->payment->ID ) { | |
| 231 | + wp_die( | |
| 232 | + esc_html__( 'Cheatin’ uh?', 'give' ), | |
| 233 | + esc_html__( 'Error', 'give' ), | |
| 234 | + array( | |
| 235 | + 'response' => 400, | |
| 236 | + ) | |
| 237 | + ); | |
| 224 | 238 | } |
| 225 | 239 | |
| 226 | 240 | // Set email data. |
| 227 | 241 | $this->setup_email_data(); |
| @@ -226,11 +240,13 @@ | ||
| 226 | 240 | // Set email data. |
| 227 | 241 | $this->setup_email_data(); |
| 228 | 242 | |
| 229 | 243 | // Send email. |
| 230 | - $this->send_email_notification( array( | |
| 231 | - 'payment_id' => $this->payment->ID, | |
| 232 | - ) ); | |
| 244 | + $this->send_email_notification( | |
| 245 | + array( | |
| 246 | + 'payment_id' => $this->payment->ID, | |
| 247 | + ) | |
| 248 | + ); | |
| 233 | 249 | } |
| 234 | 250 | |
| 235 | 251 | /** |
| 236 | 252 | * Set notification status |
| @@ -247,12 +263,12 @@ | ||
| 247 | 263 | |
| 248 | 264 | $notification_status = isset( $update_options['gateways']['offline'] ) ? 'enabled' : 'disabled'; |
| 249 | 265 | |
| 250 | 266 | if ( |
| 251 | - empty( $update_options["{$this->config['id']}_notification"] ) | |
| 252 | - || $notification_status !== $update_options["{$this->config['id']}_notification"] | |
| 267 | + empty( $update_options[ "{$this->config['id']}_notification" ] ) | |
| 268 | + || $notification_status !== $update_options[ "{$this->config['id']}_notification" ] | |
| 253 | 269 | ) { |
| 254 | - $update_options["{$this->config['id']}_notification"] = $notification_status; | |
| 270 | + $update_options[ "{$this->config['id']}_notification" ] = $notification_status; | |
| 255 | 271 | update_option( $option_name, $update_options, false ); |
| 256 | 272 | } |
| 257 | 273 | } |
| 258 | 274 | |
| @@ -268,9 +284,9 @@ | ||
| 268 | 284 | * |
| 269 | 285 | * @return array |
| 270 | 286 | */ |
| 271 | 287 | public function add_metabox_setting_field( $settings, $form_id ) { |
| 272 | - if ( in_array( 'offline', array_keys( give_get_enabled_payment_gateways($form_id) ) ) ) { | |
| 288 | + if ( in_array( 'offline', array_keys( give_get_enabled_payment_gateways( $form_id ) ) ) ) { | |
| 273 | 289 | $settings[] = array( |
| 274 | 290 | 'id' => $this->config['id'], |
| 275 | 291 | 'title' => $this->config['label'], |
| 276 | 292 | 'fields' => $this->get_setting_fields( $form_id ), |