abstract-email-notification.php
7 years ago
ajax-handler.php
7 years ago
backward-compatibility.php
7 years ago
class-donation-receipt-email.php
7 years ago
class-donor-register-email.php
7 years ago
class-email-access-email.php
7 years ago
class-email-notification-table.php
7 years ago
class-email-notification-util.php
7 years ago
class-email-notifications.php
7 years ago
class-email-setting-field.php
7 years ago
class-new-donation-email.php
7 years ago
class-new-donor-register-email.php
7 years ago
class-new-offline-donation-email.php
7 years ago
class-offline-donation-instruction-email.php
7 years ago
filters.php
7 years ago
class-email-setting-field.php
375 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Email Notification Setting Fields |
| 5 | * |
| 6 | * @package Give |
| 7 | * @subpackage Classes/Emails |
| 8 | * @copyright Copyright (c) 2016, WordImpress |
| 9 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 10 | * @since 2.0 |
| 11 | */ |
| 12 | class Give_Email_Setting_Field { |
| 13 | /** |
| 14 | * Get setting field. |
| 15 | * |
| 16 | * @since 2.0 |
| 17 | * @access public |
| 18 | * |
| 19 | * @param Give_Email_Notification $email |
| 20 | * @param int $form_id |
| 21 | * |
| 22 | * @return array |
| 23 | */ |
| 24 | public static function get_setting_fields( Give_Email_Notification $email, $form_id = null ) { |
| 25 | $setting_fields = self::get_default_setting_fields( $email, $form_id ); |
| 26 | |
| 27 | // Recipient field. |
| 28 | if ( Give_Email_Notification_Util::has_recipient_field( $email ) ) { |
| 29 | $setting_fields[] = self::get_recipient_setting_field( $email, $form_id ); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | // Add extra setting field. |
| 34 | if ( $extra_setting_field = $email->get_extra_setting_fields( $form_id ) ) { |
| 35 | $setting_fields = array_merge( $setting_fields, $extra_setting_field ); |
| 36 | } |
| 37 | |
| 38 | // Preview field. |
| 39 | if ( Give_Email_Notification_Util::has_preview( $email ) ) { |
| 40 | $setting_fields[] = self::get_preview_setting_field( $email, $form_id ); |
| 41 | } |
| 42 | |
| 43 | $setting_fields = self::add_section_end( $email, $setting_fields ); |
| 44 | |
| 45 | /** |
| 46 | * Filter the email notification settings. |
| 47 | * |
| 48 | * @since 2.0 |
| 49 | */ |
| 50 | return apply_filters( 'give_email_notification_setting_fields', $setting_fields, $email, $form_id ); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Check if email notification setting has section end or not. |
| 56 | * |
| 57 | * @since 2.0 |
| 58 | * @access private |
| 59 | * |
| 60 | * @param $setting |
| 61 | * |
| 62 | * @return bool |
| 63 | */ |
| 64 | public static function has_section_end( $setting ) { |
| 65 | $last_field = end( $setting ); |
| 66 | $has_section_end = false; |
| 67 | |
| 68 | if ( 'sectionend' === $last_field['type'] ) { |
| 69 | $has_section_end = true; |
| 70 | } |
| 71 | |
| 72 | return $has_section_end; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Check if email notification setting has section end or not. |
| 77 | * |
| 78 | * @since 2.0 |
| 79 | * @access private |
| 80 | * |
| 81 | * @param Give_Email_Notification $email |
| 82 | * @param int $form_id |
| 83 | * |
| 84 | * @return array |
| 85 | */ |
| 86 | public static function get_section_start( Give_Email_Notification $email, $form_id = null ) { |
| 87 | // Add section end field. |
| 88 | $setting = array( |
| 89 | 'id' => "give_title_email_settings_{$email->config['id']}", |
| 90 | 'type' => 'title', |
| 91 | 'title' => $email->config['label'], |
| 92 | ); |
| 93 | |
| 94 | return $setting; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Check if email notification setting has section end or not. |
| 99 | * |
| 100 | * @since 2.0 |
| 101 | * @access private |
| 102 | * |
| 103 | * @param array $setting |
| 104 | * @param Give_Email_Notification $email |
| 105 | * |
| 106 | * @return array |
| 107 | */ |
| 108 | public static function add_section_end( Give_Email_Notification $email, $setting ) { |
| 109 | if ( ! self::has_section_end( $setting ) ) { |
| 110 | // Add section end field. |
| 111 | $setting[] = array( |
| 112 | 'id' => "give_title_email_settings_{$email->config['id']}", |
| 113 | 'type' => 'sectionend', |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | return $setting; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get default setting field. |
| 122 | * |
| 123 | * @since 2.0 |
| 124 | * @access static |
| 125 | * |
| 126 | * @param Give_Email_Notification $email |
| 127 | * @param int $form_id |
| 128 | * |
| 129 | * @return array |
| 130 | */ |
| 131 | public static function get_default_setting_fields( Give_Email_Notification $email, $form_id = null ) { |
| 132 | $settings[] = self::get_section_start( $email, $form_id ); |
| 133 | $settings[] = self::get_notification_status_field( $email, $form_id ); |
| 134 | |
| 135 | if ( ! Give_Email_Notification_Util::is_notification_status_editable( $email ) ) { |
| 136 | if( $form_id || give_is_add_new_form_page() ){ |
| 137 | // Do not allow admin to disable notification on perform basis. |
| 138 | unset( $settings[1]['options']['disabled'] ); |
| 139 | } else{ |
| 140 | // Do not allow admin to edit notification status globally. |
| 141 | unset( $settings[1] ); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | $settings[] = self::get_email_subject_field( $email, $form_id ); |
| 146 | $settings[] = self::get_email_message_field( $email, $form_id ); |
| 147 | |
| 148 | if( Give_Email_Notification_Util::is_content_type_editable( $email ) ) { |
| 149 | $settings[] = self::get_email_content_type_field( $email, $form_id ); |
| 150 | } |
| 151 | |
| 152 | return $settings; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Get notification status setting field. |
| 157 | * |
| 158 | * @since 2.0 |
| 159 | * @access static |
| 160 | * |
| 161 | * @param Give_Email_Notification $email |
| 162 | * @param int $form_id |
| 163 | * |
| 164 | * @return array |
| 165 | */ |
| 166 | public static function get_notification_status_field( Give_Email_Notification $email, $form_id = null ) { |
| 167 | $option = array( |
| 168 | 'enabled' => __( 'Enabled', 'give' ), |
| 169 | 'disabled' => __( 'Disabled', 'give' ), |
| 170 | ); |
| 171 | |
| 172 | $default_value = $email->get_notification_status(); |
| 173 | |
| 174 | // Add global options. |
| 175 | if ( $form_id || give_is_add_new_form_page() ) { |
| 176 | $option = array( |
| 177 | 'global' => __( 'Global Options' ), |
| 178 | 'enabled' => __( 'Customize', 'give' ), |
| 179 | 'disabled' => __( 'Disabled', 'give' ), |
| 180 | ); |
| 181 | |
| 182 | $default_value = 'global'; |
| 183 | } |
| 184 | |
| 185 | $description = isset($_GET['page']) && 'give-settings' === $_GET['page'] ? __('Choose whether you want this email enabled or not.', 'give') : sprintf( __( 'Global Options are set <a href="%s">in Give settings</a>. You may override them for this form here.', 'give' ), admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails' ) ); |
| 186 | |
| 187 | return array( |
| 188 | 'name' => esc_html__( 'Notification', 'give' ), |
| 189 | 'desc' => $description, |
| 190 | 'id' => self::get_prefix( $email, $form_id ) . 'notification', |
| 191 | 'type' => 'radio_inline', |
| 192 | 'default' => $default_value, |
| 193 | 'options' => $option, |
| 194 | 'wrapper_class' => 'give_email_api_notification_status_setting', |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Get email subject setting field. |
| 200 | * |
| 201 | * @since 2.0 |
| 202 | * @access static |
| 203 | * |
| 204 | * @param Give_Email_Notification $email |
| 205 | * @param int $form_id |
| 206 | * |
| 207 | * @return array |
| 208 | */ |
| 209 | public static function get_email_subject_field( Give_Email_Notification $email, $form_id = null ) { |
| 210 | return array( |
| 211 | 'id' => self::get_prefix( $email, $form_id ) . 'email_subject', |
| 212 | 'name' => esc_html__( 'Email Subject', 'give' ), |
| 213 | 'desc' => esc_html__( 'Enter the email subject line.', 'give' ), |
| 214 | 'default' => $email->config['default_email_subject'], |
| 215 | 'type' => 'text', |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get email message setting field. |
| 221 | * |
| 222 | * @since 2.0 |
| 223 | * @access static |
| 224 | * |
| 225 | * @param Give_Email_Notification $email |
| 226 | * @param int $form_id |
| 227 | * |
| 228 | * @return array |
| 229 | */ |
| 230 | public static function get_email_message_field( Give_Email_Notification $email, $form_id = null ) { |
| 231 | $desc = esc_html__( 'Enter the email message.', 'give' ); |
| 232 | |
| 233 | if ( $email_tag_list = $email->get_allowed_email_tags( true ) ) { |
| 234 | $desc = sprintf( |
| 235 | '%1$s <br> %2$s: %3$s %4$s', |
| 236 | __( 'The email that is sent to users after completing a successful donation. HTML is accepted.', 'give' ), |
| 237 | __( 'Available template tags', 'give' ), |
| 238 | $email_tag_list, |
| 239 | sprintf( |
| 240 | '<br><a href="%1$s" target="_blank">%2$s</a> %3$s', |
| 241 | esc_url('http://docs.givewp.com/meta-email-tags'), |
| 242 | __( 'See our documentation', 'give' ), |
| 243 | __( 'for examples of how to use custom meta email tags to output additional donor or donation information in your Give emails.', 'give' ) |
| 244 | ) |
| 245 | ); |
| 246 | |
| 247 | } |
| 248 | |
| 249 | return array( |
| 250 | 'id' => self::get_prefix( $email, $form_id ) . 'email_message', |
| 251 | 'name' => esc_html__( 'Email message', 'give' ), |
| 252 | 'desc' => $desc, |
| 253 | 'type' => 'wysiwyg', |
| 254 | 'default' => $email->config['default_email_message'], |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Get email message setting field. |
| 260 | * |
| 261 | * @since 2.0 |
| 262 | * @access static |
| 263 | * |
| 264 | * @param Give_Email_Notification $email |
| 265 | * @param int $form_id |
| 266 | * |
| 267 | * @return array |
| 268 | */ |
| 269 | public static function get_email_content_type_field( Give_Email_Notification $email, $form_id = null ) { |
| 270 | return array( |
| 271 | 'id' => self::get_prefix( $email, $form_id ) . 'email_content_type', |
| 272 | 'name' => esc_html__( 'Email Content Type', 'give' ), |
| 273 | 'desc' => __( 'Choose email type.', 'give' ), |
| 274 | 'type' => 'select', |
| 275 | 'options' => array( |
| 276 | 'text/html' => Give_Email_Notification_Util::get_formatted_email_type( 'text/html' ), |
| 277 | 'text/plain' => Give_Email_Notification_Util::get_formatted_email_type( 'text/plain' ), |
| 278 | ), |
| 279 | 'default' => $email->config['content_type'], |
| 280 | ); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | /** |
| 285 | * Get recipient setting field. |
| 286 | * |
| 287 | * @since 2.0 |
| 288 | * @access static |
| 289 | * @todo check this field in form metabox setting after form api merge. |
| 290 | * |
| 291 | * @param Give_Email_Notification $email |
| 292 | * @param int $form_id |
| 293 | * |
| 294 | * @return array |
| 295 | */ |
| 296 | public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null ) { |
| 297 | $recipient = array( |
| 298 | 'id' => self::get_prefix( $email, $form_id ) . 'recipient', |
| 299 | 'name' => esc_html__( 'Email Recipients', 'give' ), |
| 300 | 'desc' => __( 'Enter the email address(es) that should receive a notification.', 'give' ), |
| 301 | 'type' => 'email', |
| 302 | 'default' => get_bloginfo( 'admin_email' ), |
| 303 | 'repeat' => true, |
| 304 | 'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ), |
| 305 | ); |
| 306 | |
| 307 | if ( $form_id || give_is_add_new_form_page() ) { |
| 308 | $recipient['name'] = __( 'Email', 'give' ); |
| 309 | $recipient['default'] = ''; |
| 310 | $recipient['id'] = 'email'; |
| 311 | $recipient['desc'] = __( 'Enter the email address that should receive a notification.', 'give' ); |
| 312 | |
| 313 | $recipient = array( |
| 314 | 'id' => self::get_prefix( $email, $form_id ) . 'recipient', |
| 315 | 'type' => 'group', |
| 316 | 'options' => array( |
| 317 | 'add_button' => __( 'Add Email', 'give' ), |
| 318 | 'header_title' => __( 'Email Recipient', 'give' ), |
| 319 | 'remove_button' => '<span class="dashicons dashicons-no"></span>', |
| 320 | ), |
| 321 | 'fields' => array( |
| 322 | $recipient, |
| 323 | ), |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | return $recipient; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Get preview setting field. |
| 332 | * |
| 333 | * @param Give_Email_Notification $email Email Type. |
| 334 | * @param int $form_id Form ID. |
| 335 | * |
| 336 | * @since 2.0 |
| 337 | * @access static |
| 338 | * |
| 339 | * @return array |
| 340 | */ |
| 341 | public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = null ) { |
| 342 | return array( |
| 343 | 'name' => __( 'Preview Email', 'give' ), |
| 344 | 'desc' => __( 'Click the "Preview Email" button to preview the email in your browser. Click the "Send Test Email" button to send a test email directly to your inbox.', |
| 345 | 'give' ), |
| 346 | 'id' => self::get_prefix( $email, $form_id ) . 'preview_buttons', |
| 347 | 'type' => 'email_preview_buttons', |
| 348 | ); |
| 349 | } |
| 350 | |
| 351 | |
| 352 | /** |
| 353 | * Get form metabox setting field prefix. |
| 354 | * |
| 355 | * @since 2.0 |
| 356 | * @access static |
| 357 | * |
| 358 | * @param Give_Email_Notification $email |
| 359 | * @param int $form_id |
| 360 | * |
| 361 | * @return string |
| 362 | */ |
| 363 | public static function get_prefix( Give_Email_Notification $email, $form_id = null ) { |
| 364 | $meta_key = "{$email->config['id']}_"; |
| 365 | |
| 366 | if( $form_id || give_is_add_new_form_page() ) { |
| 367 | $meta_key = "_give_{$email->config['id']}_"; |
| 368 | } |
| 369 | |
| 370 | return $meta_key; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // @todo: add per email sender options |
| 375 |