← All changes
|
includes/admin/emails/class-email-notifications.php
+30
-46
2.3.1
→
4.18.0
View file →
| @@ -12,8 +12,11 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Class Give_Email_Notifications |
| 16 | + * | |
| 17 | + * @since 2.17.1 Remove validate_settings function. | |
| 18 | + * Email recipient option value validation logic move to src/EmailGlobalSettingValidator. | |
| 16 | 19 | */ |
| 17 | 20 | class Give_Email_Notifications { |
| 18 | 21 | /** |
| 19 | 22 | * Instance. |
| @@ -21,17 +24,17 @@ | ||
| 21 | 24 | * @since 2.0 |
| 22 | 25 | * @access static |
| 23 | 26 | * @var |
| 24 | 27 | */ |
| 25 | - static private $instance; | |
| 28 | + private static $instance; | |
| 26 | 29 | |
| 27 | 30 | /** |
| 28 | - * Array of email notifications. | |
| 29 | - * | |
| 30 | - * @since 2.0 | |
| 31 | - * @access private | |
| 32 | - * @var array | |
| 33 | - */ | |
| 31 | + * Array of email notifications. | |
| 32 | + * | |
| 33 | + * @since 2.0 | |
| 34 | + * @access private | |
| 35 | + * @var Give_Email_Notification[] | |
| 36 | + */ | |
| 34 | 37 | private $emails = array(); |
| 35 | 38 | |
| 36 | 39 | /** |
| 37 | 40 | * Singleton pattern. |
| @@ -37,9 +40,9 @@ | ||
| 37 | 40 | * Singleton pattern. |
| 38 | 41 | * |
| 39 | 42 | * @since 2.0 |
| 40 | 43 | * @access private |
| 41 | - * Give_Payumoney_API constructor. | |
| 44 | + * Give_Email_Notifications constructor. | |
| 42 | 45 | */ |
| 43 | 46 | private function __construct() { |
| 44 | 47 | } |
| 45 | 48 | |
| @@ -75,14 +78,13 @@ | ||
| 75 | 78 | |
| 76 | 79 | add_filter( 'give_metabox_form_data_settings', array( $this, 'add_metabox_setting_fields' ), 10, 2 ); |
| 77 | 80 | add_action( 'init', array( $this, 'preview_email' ) ); |
| 78 | 81 | add_action( 'init', array( $this, 'send_preview_email' ) ); |
| 79 | - add_action( 'init', array( $this, 'validate_settings' ) ); | |
| 80 | 82 | |
| 81 | 83 | /* @var Give_Email_Notification $email */ |
| 82 | 84 | foreach ( $this->get_email_notifications() as $email ) { |
| 83 | 85 | // Setup email section. |
| 84 | - if( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email ) ) { | |
| 86 | + if ( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email ) ) { | |
| 85 | 87 | add_filter( 'give_get_sections_emails', array( $email, 'add_section' ) ); |
| 86 | 88 | add_filter( "give_hide_section_{$email->config['id']}_on_emails_page", array( $email, 'hide_section' ) ); |
| 87 | 89 | } |
| 88 | 90 | |
| @@ -118,18 +120,18 @@ | ||
| 118 | 120 | // Email notification setting. |
| 119 | 121 | $settings['email_notification_options'] = array( |
| 120 | 122 | 'id' => 'email_notification_options', |
| 121 | 123 | 'title' => __( 'Email Notifications', 'give' ), |
| 122 | - 'icon-html' => '<span class="dashicons dashicons-email-alt"></span>', | |
| 124 | + 'icon-html' => '<i class="fas fa-envelope"></i>', | |
| 123 | 125 | 'fields' => array( |
| 124 | 126 | array( |
| 125 | - 'name' => __( 'Email Options', 'give' ), | |
| 126 | - 'id' => '_give_email_options', | |
| 127 | - 'type' => 'radio_inline', | |
| 128 | - 'default' => 'global', | |
| 129 | - 'options' => array( | |
| 130 | - 'global' => __( 'Global Options' ), | |
| 131 | - 'enabled' => __( 'Customize', 'give' ), | |
| 127 | + 'name' => __( 'Email Options', 'give' ), | |
| 128 | + 'id' => '_give_email_options', | |
| 129 | + 'type' => 'radio_inline', | |
| 130 | + 'default' => 'global', | |
| 131 | + 'options' => array( | |
| 132 | + 'global' => __( 'Global Options', 'give' ), | |
| 133 | + 'enabled' => __( 'Customize', 'give' ), | |
| 132 | 134 | ), |
| 133 | 135 | ), |
| 134 | 136 | array( |
| 135 | 137 | 'id' => '_give_email_template', |
| @@ -147,9 +149,9 @@ | ||
| 147 | 149 | ), |
| 148 | 150 | array( |
| 149 | 151 | 'id' => '_give_from_name', |
| 150 | 152 | 'name' => esc_html__( 'From Name', 'give' ), |
| 151 | - 'desc' => esc_html__( 'The name which appears in the "From" field in all Give donation emails.', 'give' ), | |
| 153 | + 'desc' => esc_html__( 'The name which appears in the "From" field in all GiveWP donation emails.', 'give' ), | |
| 152 | 154 | 'default' => get_bloginfo( 'name' ), |
| 153 | 155 | 'type' => 'text', |
| 154 | 156 | ), |
| 155 | 157 | array( |
| @@ -154,9 +156,9 @@ | ||
| 154 | 156 | ), |
| 155 | 157 | array( |
| 156 | 158 | 'id' => '_give_from_email', |
| 157 | 159 | 'name' => esc_html__( 'From Email', 'give' ), |
| 158 | - 'desc' => esc_html__( 'Email address from which all Give emails are sent from. This will act as the "from" and "reply-to" email address.', 'give' ), | |
| 160 | + 'desc' => esc_html__( 'Email address from which all GiveWP emails are sent from. This will act as the "from" and "reply-to" email address.', 'give' ), | |
| 159 | 161 | 'default' => get_bloginfo( 'admin_email' ), |
| 160 | 162 | 'type' => 'text', |
| 161 | 163 | ), |
| 162 | 164 | array( |
| @@ -180,8 +182,9 @@ | ||
| 180 | 182 | |
| 181 | 183 | /** |
| 182 | 184 | * Add email notifications |
| 183 | 185 | * |
| 186 | + * @since 4.14.0 Add failed donation email. | |
| 184 | 187 | * @since 2.0 |
| 185 | 188 | * @access private |
| 186 | 189 | */ |
| 187 | 190 | private function add_emails_notifications() { |
| @@ -186,8 +189,9 @@ | ||
| 186 | 189 | */ |
| 187 | 190 | private function add_emails_notifications() { |
| 188 | 191 | $this->emails = array( |
| 189 | 192 | include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donation-email.php', |
| 193 | + include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-failed-donation-email.php', | |
| 190 | 194 | include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-donation-receipt-email.php', |
| 191 | 195 | include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-offline-donation-email.php', |
| 192 | 196 | include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-offline-donation-instruction-email.php', |
| 193 | 197 | include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donor-register-email.php', |
| @@ -309,13 +313,18 @@ | ||
| 309 | 313 | /** |
| 310 | 314 | * Add header to donation receipt email preview |
| 311 | 315 | * |
| 312 | 316 | * @since 2.0 |
| 317 | + * @since 4.16.6 Re-check capability/nonce here, since this callback is also reachable via a direct action dispatch that bypasses the check normally done in preview_email(). | |
| 313 | 318 | * @access public |
| 314 | 319 | * |
| 315 | 320 | * @param Give_Email_Notification $email |
| 316 | 321 | */ |
| 317 | 322 | public function email_preview_header( $email ) { |
| 323 | + if ( ! Give_Email_Notification_Util::can_preview_email() ) { | |
| 324 | + return; | |
| 325 | + } | |
| 326 | + | |
| 318 | 327 | /** |
| 319 | 328 | * Filter the all email preview headers. |
| 320 | 329 | * |
| 321 | 330 | * @since 2.0 |
| @@ -393,9 +402,9 @@ | ||
| 393 | 402 | } |
| 394 | 403 | } |
| 395 | 404 | |
| 396 | 405 | // Remove the test email query arg. |
| 397 | - wp_redirect( remove_query_arg( 'give_action' ) ); | |
| 406 | + wp_redirect( esc_url_raw( remove_query_arg( 'give_action' ) ) ); | |
| 398 | 407 | exit; |
| 399 | 408 | } |
| 400 | 409 | |
| 401 | 410 | |
| @@ -406,33 +415,8 @@ | ||
| 406 | 415 | * @access public |
| 407 | 416 | */ |
| 408 | 417 | public function load() { |
| 409 | 418 | add_action( 'init', array( $this, 'init' ), -1 ); |
| 410 | - } | |
| 411 | - | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * Verify email setting before saving | |
| 415 | - * | |
| 416 | - * @since 2.0 | |
| 417 | - * @access public | |
| 418 | - */ | |
| 419 | - public function validate_settings() { | |
| 420 | - // Bailout. | |
| 421 | - if ( | |
| 422 | - ! Give_Admin_Settings::is_saving_settings() || | |
| 423 | - 'emails' !== give_get_current_setting_tab() || | |
| 424 | - ! isset( $_GET['section'] ) | |
| 425 | - ) { | |
| 426 | - return; | |
| 427 | - } | |
| 428 | - | |
| 429 | - // Get email type. | |
| 430 | - $email_type = give_get_current_setting_section(); | |
| 431 | - | |
| 432 | - if ( ! empty( $_POST["{$email_type}_recipient"] ) ) { | |
| 433 | - $_POST["{$email_type}_recipient"] = array_unique( array_filter( $_POST["{$email_type}_recipient"] ) ); | |
| 434 | - } | |
| 435 | 419 | } |
| 436 | 420 | } |
| 437 | 421 | |
| 438 | 422 | // Helper class. |