abstract-email-notification.php
6 years ago
ajax-handler.php
6 years ago
backward-compatibility.php
6 years ago
class-donation-receipt-email.php
6 years ago
class-donor-note-email.php
6 years ago
class-donor-register-email.php
6 years ago
class-email-access-email.php
6 years ago
class-email-notification-table.php
6 years ago
class-email-notification-util.php
6 years ago
class-email-notifications.php
6 years ago
class-email-setting-field.php
6 years ago
class-new-donation-email.php
6 years ago
class-new-donor-register-email.php
6 years ago
class-new-offline-donation-email.php
6 years ago
class-offline-donation-instruction-email.php
6 years ago
filters.php
6 years ago
class-email-notification-table.php
315 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Email Notification |
| 5 | * |
| 6 | * This class handles table html for email notifications listing. |
| 7 | * |
| 8 | * @package Give |
| 9 | * @subpackage Classes/Emails |
| 10 | * @copyright Copyright (c) 2016, GiveWP |
| 11 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 12 | * @since 2.0 |
| 13 | */ |
| 14 | class Give_Email_Notification_Table extends WP_List_Table { |
| 15 | /** |
| 16 | * @var Give_Email_Notifications $email_notifications |
| 17 | * @since 2.0 |
| 18 | * @access private |
| 19 | */ |
| 20 | private $email_notifications; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Number of email notifications per page |
| 25 | * |
| 26 | * @since 2.0 |
| 27 | * @access private |
| 28 | * @var int |
| 29 | */ |
| 30 | private $per_page = - 1; |
| 31 | |
| 32 | /** |
| 33 | * Give_Email_Notification_Table constructor. |
| 34 | * |
| 35 | * @since 2.0 |
| 36 | * @access public |
| 37 | */ |
| 38 | public function __construct() { |
| 39 | parent::__construct( |
| 40 | array( |
| 41 | 'singular' => 'giveemailnotification', |
| 42 | 'plural' => 'giveemailnotifications', |
| 43 | ) |
| 44 | ); |
| 45 | |
| 46 | $this->email_notifications = Give_Email_Notifications::get_instance(); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * Get table columns. |
| 52 | * |
| 53 | * @since 2.0 |
| 54 | * @access public |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function get_columns() { |
| 59 | /** |
| 60 | * Filter the table columns |
| 61 | * |
| 62 | * @since 2.0 |
| 63 | */ |
| 64 | return apply_filters( |
| 65 | 'give_email_notification_setting_columns', |
| 66 | array( |
| 67 | 'cb' => __( 'Email Status', 'give' ), |
| 68 | 'name' => __( 'Email', 'give' ), |
| 69 | 'email_type' => __( 'Content Type', 'give' ), |
| 70 | 'recipient' => __( 'Recipient(s)', 'give' ), |
| 71 | 'setting' => __( 'Edit Email', 'give' ), |
| 72 | ) |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get name column. |
| 78 | * |
| 79 | * @since 2.0 |
| 80 | * @access public |
| 81 | * |
| 82 | * @param Give_Email_Notification $email |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | public function column_name( $email ) { |
| 87 | $edit_url = esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ); |
| 88 | $actions = $this->get_row_actions( $email ); |
| 89 | |
| 90 | ob_start(); |
| 91 | ?> |
| 92 | <a class="row-title" href="<?php echo $edit_url; ?>"><?php echo $email->config['label']; ?></a> |
| 93 | |
| 94 | <?php if ( $desc = $email->config['description'] ) : ?> |
| 95 | <?php echo Give()->tooltips->render_help( esc_attr( $desc ) ); ?> |
| 96 | <?php endif; ?> |
| 97 | |
| 98 | <?php echo $this->row_actions( $actions ); ?> |
| 99 | <?php |
| 100 | return ob_get_clean(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get recipient column. |
| 105 | * |
| 106 | * @since 2.0 |
| 107 | * @access public |
| 108 | * |
| 109 | * @param Give_Email_Notification $email |
| 110 | * |
| 111 | * @return string |
| 112 | */ |
| 113 | public function column_recipient( $email ) { |
| 114 | ob_start(); |
| 115 | |
| 116 | if ( Give_Email_Notification_Util::has_recipient_field( $email ) ) { |
| 117 | $recipients = $email->get_recipient(); |
| 118 | if ( is_array( $recipients ) ) { |
| 119 | $recipients = implode( '<br>', $recipients ); |
| 120 | } |
| 121 | |
| 122 | echo $recipients; |
| 123 | |
| 124 | } elseif ( ! empty( $email->config['recipient_group_name'] ) ) { |
| 125 | echo $email->config['recipient_group_name']; |
| 126 | } |
| 127 | |
| 128 | return ob_get_clean(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get status column. |
| 133 | * |
| 134 | * @since 2.0 |
| 135 | * @access public |
| 136 | * |
| 137 | * @param Give_Email_Notification $email |
| 138 | * |
| 139 | * @return string |
| 140 | */ |
| 141 | public function column_cb( $email ) { |
| 142 | $notification_status = $email->get_notification_status(); |
| 143 | $user_can_edit_status = (int) Give_Email_Notification_Util::is_notification_status_editable( $email ); |
| 144 | $icon_classes = Give_Email_Notification_Util::is_email_notification_active( $email ) |
| 145 | ? 'dashicons dashicons-yes' |
| 146 | : 'dashicons dashicons-no-alt'; |
| 147 | $attributes = array( |
| 148 | 'class' => "give-email-notification-status give-email-notification-{$notification_status}", |
| 149 | 'data-id' => $email->config['id'], |
| 150 | 'data-status' => $email->get_notification_status(), |
| 151 | 'data-edit' => $user_can_edit_status, |
| 152 | ); |
| 153 | |
| 154 | if ( ! $user_can_edit_status ) { |
| 155 | $icon_classes = 'dashicons dashicons-lock'; |
| 156 | |
| 157 | $attributes['data-notice'] = esc_attr( $email->config['notices']['non-notification-status-editable'] ); |
| 158 | } |
| 159 | |
| 160 | $html = sprintf( |
| 161 | '<span %1$s><i class="%2$s"></i></span></span><span class="spinner"></span>', |
| 162 | give_get_attribute_str( $attributes ), |
| 163 | $icon_classes |
| 164 | ); |
| 165 | |
| 166 | return $html; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /** |
| 171 | * Get email_type column. |
| 172 | * |
| 173 | * @since 2.0 |
| 174 | * @access public |
| 175 | * |
| 176 | * @param Give_Email_Notification $email |
| 177 | * |
| 178 | * @return string |
| 179 | */ |
| 180 | public function column_email_type( Give_Email_Notification $email ) { |
| 181 | $email_content_type_label = apply_filters( |
| 182 | "give_email_list_render_{$email->config['id']}_email_content_type", |
| 183 | Give_Email_Notification_Util::get_formatted_email_type( $email->config['content_type'] ), |
| 184 | |
| 185 | ); |
| 186 | |
| 187 | return $email_content_type_label; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Get setting column. |
| 192 | * |
| 193 | * @since 2.0 |
| 194 | * @access public |
| 195 | * |
| 196 | * @param Give_Email_Notification $email |
| 197 | * |
| 198 | * @return string |
| 199 | */ |
| 200 | public function column_setting( Give_Email_Notification $email ) { |
| 201 | return Give()->tooltips->render_link( |
| 202 | array( |
| 203 | 'label' => __( 'Edit', 'give' ) . " {$email->config['label']}", |
| 204 | 'tag_content' => '<span class="dashicons dashicons-admin-generic"></span>', |
| 205 | 'link' => esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ), |
| 206 | 'attributes' => array( |
| 207 | 'class' => 'button button-small', |
| 208 | ), |
| 209 | ) |
| 210 | ); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /** |
| 215 | * Print row actions. |
| 216 | * |
| 217 | * @since 2.0 |
| 218 | * @access private |
| 219 | * |
| 220 | * @param Give_Email_Notification $email |
| 221 | * |
| 222 | * @return array |
| 223 | */ |
| 224 | private function get_row_actions( $email ) { |
| 225 | $edit_url = esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ); |
| 226 | |
| 227 | /** |
| 228 | * Filter the row actions |
| 229 | * |
| 230 | * @since 2.0 |
| 231 | * |
| 232 | * @param array $row_actions |
| 233 | */ |
| 234 | $row_actions = apply_filters( |
| 235 | 'give_email_notification_row_actions', |
| 236 | array( |
| 237 | 'edit' => "<a href=\"{$edit_url}\">" . __( 'Edit', 'give' ) . '</a>', |
| 238 | ), |
| 239 | |
| 240 | ); |
| 241 | |
| 242 | return $row_actions; |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /** |
| 247 | * Prepare email notifications |
| 248 | * |
| 249 | * @since 2.0 |
| 250 | * @access public |
| 251 | */ |
| 252 | public function prepare_items() { |
| 253 | // Set columns. |
| 254 | $columns = $this->get_columns(); |
| 255 | $hidden = array(); |
| 256 | $email_notifications = array(); |
| 257 | $sortable = $this->get_sortable_columns(); |
| 258 | $this->_column_headers = array( $columns, $hidden, $sortable, $this->get_primary_column_name() ); |
| 259 | |
| 260 | // Get email section |
| 261 | $current_section = give_get_current_setting_section(); |
| 262 | |
| 263 | // Set email notifications. |
| 264 | /* @var Give_Email_Notification $email_notification */ |
| 265 | foreach ( $this->email_notifications->get_email_notifications() as $email_notification ) { |
| 266 | if ( ! Give_Email_Notification_Util::is_show_on_emails_setting_page( $email_notification ) ) { |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | if ( 'donor-email' === $current_section ) { |
| 271 | // Add donor emails to email array list. |
| 272 | if ( empty( $email_notification->config['has_recipient_field'] ) ) { |
| 273 | $email_notifications[] = $email_notification; |
| 274 | } |
| 275 | } elseif ( 'admin-email' === $current_section ) { |
| 276 | // Add admin emails to email array list. |
| 277 | if ( ! empty( $email_notification->config['has_recipient_field'] ) ) { |
| 278 | $email_notifications[] = $email_notification; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | $total_items = count( $email_notifications ); |
| 284 | $this->items = $email_notifications; |
| 285 | $this->set_pagination_args( |
| 286 | array( |
| 287 | 'total_items' => $total_items, |
| 288 | 'per_page' => $this->per_page, |
| 289 | ) |
| 290 | ); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Message to be displayed when there are no items |
| 295 | * |
| 296 | * @since 2.0 |
| 297 | * @access public |
| 298 | */ |
| 299 | public function no_items() { |
| 300 | _e( 'No give email notification found.', 'give' ); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Get primary column. |
| 305 | * |
| 306 | * @since 2,0 |
| 307 | * @access public |
| 308 | * |
| 309 | * @return string Name of the default primary column. |
| 310 | */ |
| 311 | public function get_primary_column_name() { |
| 312 | return 'name'; |
| 313 | } |
| 314 | } |
| 315 |