| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class to handle all custom post type definitions for Ultimate WP Mail |
| 4 |
*/ |
| 5 |
|
| 6 |
if ( !defined( 'ABSPATH' ) ) |
| 7 |
exit; |
| 8 |
|
| 9 |
if ( !class_exists( 'ewduwpmCustomPostTypes' ) ) { |
| 10 |
class ewduwpmCustomPostTypes { |
| 11 |
|
| 12 |
public $nonce; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
|
| 16 |
// Call when plugin is initialized on every page load |
| 17 |
add_action( 'admin_init', array( $this, 'create_nonce' ) ); |
| 18 |
add_action( 'init', array( $this, 'load_cpts' ) ); |
| 19 |
|
| 20 |
// Handle metaboxes |
| 21 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
| 22 |
add_action( 'save_post', array( $this, 'save_email_meta' ) ); |
| 23 |
add_action( 'save_post', array( $this, 'save_sms_meta' ) ); |
| 24 |
|
| 25 |
// Add columns and filters to the admin list of email logs |
| 26 |
add_filter( 'manage_uwpm_email_log_posts_columns', array( $this, 'register_email_log_table_columns' ) ); |
| 27 |
add_action( 'manage_uwpm_email_log_posts_custom_column', array( $this, 'display_email_log_columns_content' ), 10, 2 ); |
| 28 |
add_filter( 'manage_edit-uwpm_email_log_sortable_columns', array( $this, 'register_email_log_post_column_sortables' ) ); |
| 29 |
add_filter( 'request', array( $this, 'email_log_orderby_custom_columns' ) ); |
| 30 |
add_filter( 'post_row_actions', array( $this, 'remove_email_log_post_row_actions' ), 10, 2 ); |
| 31 |
|
| 32 |
add_filter( 'gettext', array( $this, 'change_post_page_translations' ), 10, 3 ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Initialize custom post types |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
public function load_cpts() { |
| 40 |
global $ewd_uwpm_controller; |
| 41 |
|
| 42 |
// Define the email custom post type |
| 43 |
$args = array( |
| 44 |
'labels' => array( |
| 45 |
'name' => __( 'Emails', 'ultimate-wp-mail' ), |
| 46 |
'singular_name' => __( 'Email', 'ultimate-wp-mail' ), |
| 47 |
'menu_name' => __( 'Emails', 'ultimate-wp-mail' ), |
| 48 |
'name_admin_bar' => __( 'Emails', 'ultimate-wp-mail' ), |
| 49 |
'add_new' => __( 'Add New', 'ultimate-wp-mail' ), |
| 50 |
'add_new_item' => __( 'Add New Email', 'ultimate-wp-mail' ), |
| 51 |
'edit_item' => __( 'Edit Email', 'ultimate-wp-mail' ), |
| 52 |
'new_item' => __( 'New Email', 'ultimate-wp-mail' ), |
| 53 |
'view_item' => __( 'View Email', 'ultimate-wp-mail' ), |
| 54 |
'search_items' => __( 'Search Emails', 'ultimate-wp-mail' ), |
| 55 |
'not_found' => __( 'No Emails found', 'ultimate-wp-mail' ), |
| 56 |
'not_found_in_trash' => __( 'No Emails found in trash', 'ultimate-wp-mail' ), |
| 57 |
'all_items' => __( 'All Emails', 'ultimate-wp-mail' ), |
| 58 |
), |
| 59 |
'public' => true, |
| 60 |
'publicly_queryable' => false, |
| 61 |
'exclude_from_search' => true, |
| 62 |
'has_archive' => true, |
| 63 |
'menu_icon' => 'dashicons-email', |
| 64 |
'capability_type' => 'post', |
| 65 |
'rewrite' => array( |
| 66 |
'slug' => 'email' |
| 67 |
), |
| 68 |
'supports' => array( |
| 69 |
'title', |
| 70 |
), |
| 71 |
'show_in_rest' => true, |
| 72 |
); |
| 73 |
|
| 74 |
// Create filter so addons can modify the arguments |
| 75 |
$args = apply_filters( 'ewd_uwpm_emails_args', $args ); |
| 76 |
|
| 77 |
// Add an action so addons can hook in before the post type is registered |
| 78 |
do_action( 'ewd_uwpm_emails_pre_register' ); |
| 79 |
|
| 80 |
// Register the post type |
| 81 |
register_post_type( EWD_UWPM_EMAIL_POST_TYPE, $args ); |
| 82 |
|
| 83 |
// Add an action so addons can hook in after the post type is registered |
| 84 |
do_action( 'ewd_uwpm_emails_post_register' ); |
| 85 |
|
| 86 |
// Define the email log custom post type |
| 87 |
$args = array( |
| 88 |
'labels' => array( |
| 89 |
'name' => __( 'Email Log', 'ultimate-wp-mail' ), |
| 90 |
'singular_name' => __( 'Email Log', 'ultimate-wp-mail' ), |
| 91 |
'menu_name' => __( 'Email Logs', 'ultimate-wp-mail' ), |
| 92 |
'name_admin_bar' => __( 'Email Logs', 'ultimate-wp-mail' ), |
| 93 |
'add_new' => __( 'Add NewLog', 'ultimate-wp-mail' ), |
| 94 |
'add_new_item' => __( 'Add New Log', 'ultimate-wp-mail' ), |
| 95 |
'edit_item' => __( 'Edit Email Log', 'ultimate-wp-mail' ), |
| 96 |
'new_item' => __( 'New Email Log', 'ultimate-wp-mail' ), |
| 97 |
'view_item' => __( 'View Email Log', 'ultimate-wp-mail' ), |
| 98 |
'search_items' => __( 'Search Email Logs', 'ultimate-wp-mail' ), |
| 99 |
'not_found' => __( 'No Email Logs found', 'ultimate-wp-mail' ), |
| 100 |
'not_found_in_trash' => __( 'No Email Logs found in trash', 'ultimate-wp-mail' ), |
| 101 |
'all_items' => __( 'All Email Logs', 'ultimate-wp-mail' ), |
| 102 |
), |
| 103 |
'public' => true, |
| 104 |
'publicly_queryable' => false, |
| 105 |
'exclude_from_search' => true, |
| 106 |
'has_archive' => false, |
| 107 |
'capability_type' => 'post', |
| 108 |
'capabilities' => array( |
| 109 |
'create_posts' => false, |
| 110 |
), |
| 111 |
'map_meta_cap' =>true, |
| 112 |
'supports' => array( |
| 113 |
'title', |
| 114 |
), |
| 115 |
'show_in_rest' => true, |
| 116 |
'show_in_menu' => 'edit.php?post_type=' . EWD_UWPM_EMAIL_POST_TYPE, |
| 117 |
); |
| 118 |
|
| 119 |
// Create filter so addons can modify the arguments |
| 120 |
$args = apply_filters( 'ewd_uwpm_email_logs_args', $args ); |
| 121 |
|
| 122 |
// Add an action so addons can hook in before the post type is registered |
| 123 |
do_action( 'ewd_uwpm_email_logs_pre_register' ); |
| 124 |
|
| 125 |
// Register the post type |
| 126 |
register_post_type( EWD_UWPM_EMAIL_LOG_POST_TYPE, $args ); |
| 127 |
|
| 128 |
// Add an action so addons can hook in after the post type is registered |
| 129 |
do_action( 'ewd_uwpm_email_logs_post_register' ); |
| 130 |
|
| 131 |
// Define the review category taxonomy |
| 132 |
$args = array( |
| 133 |
'labels' => array( |
| 134 |
'name' => __( 'Email Categories', 'ultimate-wp-mail' ), |
| 135 |
'singular_name' => __( 'Email Category', 'ultimate-wp-mail' ), |
| 136 |
'search_items' => __( 'Search Email Categories', 'ultimate-wp-mail' ), |
| 137 |
'all_items' => __( 'All Email Categories', 'ultimate-wp-mail' ), |
| 138 |
'parent_item' => __( 'Parent Email Category', 'ultimate-wp-mail' ), |
| 139 |
'parent_item_colon' => __( 'Parent Email Category:', 'ultimate-wp-mail' ), |
| 140 |
'edit_item' => __( 'Edit Email Category', 'ultimate-wp-mail' ), |
| 141 |
'update_item' => __( 'Update Email Category', 'ultimate-wp-mail' ), |
| 142 |
'add_new_item' => __( 'Add New Email Category', 'ultimate-wp-mail' ), |
| 143 |
'new_item_name' => __( 'New Email Category Name', 'ultimate-wp-mail' ), |
| 144 |
'menu_name' => __( 'Email Categories', 'ultimate-wp-mail' ), |
| 145 |
), |
| 146 |
'query_var' => false, |
| 147 |
); |
| 148 |
|
| 149 |
// Create filter so addons can modify the arguments |
| 150 |
$args = apply_filters( 'ewd_uwpm_category_args', $args ); |
| 151 |
|
| 152 |
register_taxonomy( EWD_UWPM_EMAIL_CATEGORY_TAXONOMY, EWD_UWPM_EMAIL_POST_TYPE, $args ); |
| 153 |
|
| 154 |
if ( ! $ewd_uwpm_controller->permissions->check_permission( 'sms' ) ) { return; } |
| 155 |
|
| 156 |
// Define the email custom post type |
| 157 |
$args = array( |
| 158 |
'labels' => array( |
| 159 |
'name' => __( 'SMS Messages', 'ultimate-wp-mail' ), |
| 160 |
'singular_name' => __( 'SMS', 'ultimate-wp-mail' ), |
| 161 |
'menu_name' => __( 'SMS Messages', 'ultimate-wp-mail' ), |
| 162 |
'name_admin_bar' => __( 'SMS Messages', 'ultimate-wp-mail' ), |
| 163 |
'add_new' => __( 'Add New', 'ultimate-wp-mail' ), |
| 164 |
'add_new_item' => __( 'Add New SMS', 'ultimate-wp-mail' ), |
| 165 |
'edit_item' => __( 'Edit SMS', 'ultimate-wp-mail' ), |
| 166 |
'new_item' => __( 'New SMS', 'ultimate-wp-mail' ), |
| 167 |
'view_item' => __( 'View SMS', 'ultimate-wp-mail' ), |
| 168 |
'search_items' => __( 'Search SMS Messages', 'ultimate-wp-mail' ), |
| 169 |
'not_found' => __( 'No SMS Messages found', 'ultimate-wp-mail' ), |
| 170 |
'not_found_in_trash' => __( 'No SMS Messages found in trash', 'ultimate-wp-mail' ), |
| 171 |
'all_items' => __( 'All SMS Messages', 'ultimate-wp-mail' ), |
| 172 |
), |
| 173 |
'public' => true, |
| 174 |
'publicly_queryable' => false, |
| 175 |
'exclude_from_search' => true, |
| 176 |
'has_archive' => true, |
| 177 |
'capability_type' => 'post', |
| 178 |
'supports' => array( |
| 179 |
'title', |
| 180 |
), |
| 181 |
'show_in_rest' => true, |
| 182 |
'show_in_menu' => 'edit.php?post_type=' . EWD_UWPM_EMAIL_POST_TYPE, |
| 183 |
); |
| 184 |
|
| 185 |
// Create filter so addons can modify the arguments |
| 186 |
$args = apply_filters( 'ewd_uwpm_sms_args', $args ); |
| 187 |
|
| 188 |
// Add an action so addons can hook in before the post type is registered |
| 189 |
do_action( 'ewd_uwpm_sms_pre_register' ); |
| 190 |
|
| 191 |
// Register the post type |
| 192 |
register_post_type( EWD_UWPM_SMS_POST_TYPE, $args ); |
| 193 |
|
| 194 |
// Add an action so addons can hook in after the post type is registered |
| 195 |
do_action( 'ewd_uwpm_smss_post_register' ); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Generate a nonce for secure saving of metadata |
| 200 |
* @since 1.0.0 |
| 201 |
*/ |
| 202 |
public function create_nonce() { |
| 203 |
|
| 204 |
$this->nonce = wp_create_nonce( basename( __FILE__ ) ); |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Add in new columns for the uwpm_email type |
| 209 |
* @since 1.0.0 |
| 210 |
*/ |
| 211 |
public function add_meta_boxes() { |
| 212 |
|
| 213 |
$meta_boxes = array( |
| 214 |
|
| 215 |
// Add in the Email builder |
| 216 |
'email_builder' => array ( |
| 217 |
'id' => 'ewd-uwpm-build-email', |
| 218 |
'title' => esc_html__( 'Build Email', 'ultimate-wp-mail' ), |
| 219 |
'callback' => array( $this, 'add_email_builder' ), |
| 220 |
'post_type' => EWD_UWPM_EMAIL_POST_TYPE, |
| 221 |
'context' => 'normal', |
| 222 |
'priority' => 'high' |
| 223 |
), |
| 224 |
|
| 225 |
// Add in the Email builder |
| 226 |
'send_events' => array ( |
| 227 |
'id' => 'ewd-uwpm-send-events', |
| 228 |
'title' => esc_html__( 'Send Events', 'ultimate-wp-mail' ), |
| 229 |
'callback' => array( $this, 'show_email_statistics' ), |
| 230 |
'post_type' => EWD_UWPM_EMAIL_POST_TYPE, |
| 231 |
'context' => 'normal', |
| 232 |
'priority' => 'high' |
| 233 |
), |
| 234 |
|
| 235 |
// Add in a link to the documentation for the plugin |
| 236 |
'ewd_uwpm_meta_need_help' => array ( |
| 237 |
'id' => 'ewd-uwpm-meta-need-help', |
| 238 |
'title' => esc_html__( 'Need Help?', 'ultimate-wp-mail' ), |
| 239 |
'callback' => array( $this, 'show_need_help_meta' ), |
| 240 |
'post_type' => EWD_UWPM_EMAIL_POST_TYPE, |
| 241 |
'context' => 'side', |
| 242 |
'priority' => 'high' |
| 243 |
), |
| 244 |
|
| 245 |
// Add in a box that allows the email to be sent |
| 246 |
'send_emails' => array ( |
| 247 |
'id' => 'ewd-uwpm-send-mail-meta-box', |
| 248 |
'title' => esc_html__( 'Send Email', 'ultimate-wp-mail' ), |
| 249 |
'callback' => array( $this, 'add_send_mail' ), |
| 250 |
'post_type' => EWD_UWPM_EMAIL_POST_TYPE, |
| 251 |
'context' => 'side', |
| 252 |
'priority' => 'high' |
| 253 |
), |
| 254 |
|
| 255 |
// Add in the SMS message content box |
| 256 |
'sms_builder' => array ( |
| 257 |
'id' => 'ewd-uwpm-sms-content', |
| 258 |
'title' => esc_html__( 'SMS Content', 'ultimate-wp-mail' ), |
| 259 |
'callback' => array( $this, 'sms_content_area' ), |
| 260 |
'post_type' => EWD_UWPM_SMS_POST_TYPE, |
| 261 |
'context' => 'normal', |
| 262 |
'priority' => 'high' |
| 263 |
), |
| 264 |
|
| 265 |
// Add in a box that allows the email to be sent |
| 266 |
'send_sms' => array ( |
| 267 |
'id' => 'ewd-uwpm-send-sms-meta-box', |
| 268 |
'title' => esc_html__( 'Send SMS', 'ultimate-wp-mail' ), |
| 269 |
'callback' => array( $this, 'add_send_sms' ), |
| 270 |
'post_type' => EWD_UWPM_SMS_POST_TYPE, |
| 271 |
'context' => 'side', |
| 272 |
'priority' => 'high' |
| 273 |
), |
| 274 |
); |
| 275 |
|
| 276 |
// Create filter so addons can modify the metaboxes |
| 277 |
$meta_boxes = apply_filters( 'ewd_uwpm_meta_boxes', $meta_boxes ); |
| 278 |
|
| 279 |
// Create the metaboxes |
| 280 |
foreach ( $meta_boxes as $meta_box ) { |
| 281 |
add_meta_box( |
| 282 |
$meta_box['id'], |
| 283 |
$meta_box['title'], |
| 284 |
$meta_box['callback'], |
| 285 |
$meta_box['post_type'], |
| 286 |
$meta_box['context'], |
| 287 |
$meta_box['priority'] |
| 288 |
); |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* Add in a link to the plugin documentation |
| 294 |
* @since 1.0.0 |
| 295 |
*/ |
| 296 |
public function add_email_builder( $post ) { |
| 297 |
global $ewd_uwpm_controller; |
| 298 |
|
| 299 |
ewd_uwpm_load_view_files(); |
| 300 |
|
| 301 |
$args = array( |
| 302 |
'post' => $post, |
| 303 |
'nonce' => $this->nonce |
| 304 |
); |
| 305 |
|
| 306 |
$email_builder_view = new ewduwpmAdminEmailBuilderView( $args ); |
| 307 |
|
| 308 |
echo $email_builder_view->render(); |
| 309 |
|
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* Shows statistics related to the number of times an email has been sent |
| 314 |
* @since 1.0.0 |
| 315 |
*/ |
| 316 |
public function show_email_statistics( $post ) { |
| 317 |
global $ewd_uwpm_controller; |
| 318 |
|
| 319 |
$previous_sends = is_array( get_post_meta( $post->ID, 'EWD_UWPM_Send_Events', true ) ) ? get_post_meta( $post->ID, 'EWD_UWPM_Send_Events', true ) : array(); |
| 320 |
|
| 321 |
?> |
| 322 |
|
| 323 |
<div class='ewd-uwpm-sent-events'> |
| 324 |
|
| 325 |
<h3><?php _e("Previous Email Sends", 'ultimate-wp-mail'); ?></h3> |
| 326 |
|
| 327 |
<table> |
| 328 |
|
| 329 |
<thead> |
| 330 |
|
| 331 |
<tr> |
| 332 |
<th><?php _e( 'Send Time', 'ultimate-wp-mail' ); ?></th> |
| 333 |
<th><?php _e( 'Send Type', 'ultimate-wp-mail' ); ?></th> |
| 334 |
<th><?php _e( 'Recipient(s)', 'ultimate-wp-mail' ); ?></th> |
| 335 |
<th><?php _e( 'Successful Sends', 'ultimate-wp-mail' ); ?></th> |
| 336 |
<?php if ( $ewd_uwpm_controller->settings->get_setting( 'track-opens' ) ) { ?> <th><?php _e( 'Number of Opens', 'ultimate-wp-mail' ); ?></th><?php } ?> |
| 337 |
<?php if ( $ewd_uwpm_controller->settings->get_setting( 'track-clicks' ) ) { ?> <th><?php _e( 'Number of Links Clicked', 'ultimate-wp-mail' ); ?></th><?php } ?> |
| 338 |
</tr> |
| 339 |
|
| 340 |
</thead> |
| 341 |
|
| 342 |
<tbody> |
| 343 |
|
| 344 |
<?php foreach ( $previous_sends as $previous_send ) { ?> |
| 345 |
|
| 346 |
<tr> |
| 347 |
<td><?php echo $previous_send['Send_Time']; ?></td> |
| 348 |
<td><?php echo $previous_send['Send_Type']; ?></td> |
| 349 |
<td> |
| 350 |
<?php |
| 351 |
if ( $previous_send['Send_Type'] == 'List' ) { echo esc_html( $this->get_list_name_from_id( $previous_send['List_ID'] ) ); } |
| 352 |
elseif ( $previous_send['Send_Type'] == 'User' ) { $user = get_userdata( $previous_send['User_ID'] ); echo esc_html( $user->display_name ); } |
| 353 |
else { _e( 'All Users', 'ultimate-wp-mail' ); } |
| 354 |
?> |
| 355 |
</td> |
| 356 |
<td><?php echo $previous_send['Emails_Sent']; ?></td> |
| 357 |
<?php if ( $ewd_uwpm_controller->settings->get_setting( 'track-opens' ) ) { ?><td><?php echo sizeOf( $ewd_uwpm_controller->database_manager->get_email_opens( array( 'email_send_id' => $previous_send['ID'] ) ) ); ?></td><?php } ?> |
| 358 |
<?php if ( $ewd_uwpm_controller->settings->get_setting( 'track-clicks' ) ) { ?><td><?php echo sizeOf( $ewd_uwpm_controller->database_manager->get_email_links_clicked( array( 'email_send_id' => $previous_send['ID'] ) ) ); ?></td><?php } ?> |
| 359 |
</tr> |
| 360 |
|
| 361 |
<?php } ?> |
| 362 |
|
| 363 |
</tbody> |
| 364 |
|
| 365 |
</table> |
| 366 |
|
| 367 |
</div> |
| 368 |
|
| 369 |
<?php |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Add in a link to the plugin documentation |
| 374 |
* @since 1.0.0 |
| 375 |
*/ |
| 376 |
public function show_need_help_meta() { ?> |
| 377 |
|
| 378 |
<div class='ewd-uwpm-need-help-box'> |
| 379 |
<div class='ewd-uwpm-need-help-text'>Visit our Support Center for documentation and tutorials</div> |
| 380 |
<a class='ewd-uwpm-need-help-button' href='https://www.etoilewebdesign.com/support-center/?Plugin=UWPM' target='_blank'>GET SUPPORT</a> |
| 381 |
</div> |
| 382 |
|
| 383 |
<?php } |
| 384 |
|
| 385 |
/** |
| 386 |
* Adds in the send email box |
| 387 |
* @since 1.0.0 |
| 388 |
*/ |
| 389 |
public function add_send_mail( $post ) { |
| 390 |
|
| 391 |
include( EWD_UWPM_PLUGIN_DIR . '/' . EWD_UWPM_TEMPLATE_DIR . '/admin-send-mail.php' ); |
| 392 |
} |
| 393 |
|
| 394 |
public function sms_content_area( $post ) { |
| 395 |
|
| 396 |
$sms_content = get_post_meta( $post->ID, 'EWD_UWPM_SMS_Content', true ); |
| 397 |
|
| 398 |
include( EWD_UWPM_PLUGIN_DIR . '/' . EWD_UWPM_TEMPLATE_DIR . '/admin-send-sms-results.php' ); |
| 399 |
|
| 400 |
?> |
| 401 |
|
| 402 |
<div class='ewd-uwpm-sms-content'> |
| 403 |
|
| 404 |
<input type='hidden' name='ewd_uwpm_nonce' value='<?php echo $this->nonce; ?>' /> |
| 405 |
|
| 406 |
<h3><?php _e( 'Message Content', 'ultimate-wp-mail'); ?></h3> |
| 407 |
|
| 408 |
<textarea name='ewd_uwpm_sms_content'><?php echo esc_html( $sms_content ); ?></textarea> |
| 409 |
|
| 410 |
</div> |
| 411 |
|
| 412 |
<?php |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Adds in the send SMS box |
| 417 |
* @since 1.2.0 |
| 418 |
*/ |
| 419 |
public function add_send_sms( $post ) { |
| 420 |
|
| 421 |
include( EWD_UWPM_PLUGIN_DIR . '/' . EWD_UWPM_TEMPLATE_DIR . '/admin-send-sms.php' ); |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Returns a user's selected phone number (if any) |
| 426 |
* @since 1.2.0 |
| 427 |
*/ |
| 428 |
public function get_user_phone_number( $user ) { |
| 429 |
global $ewd_uwpm_controller; |
| 430 |
|
| 431 |
return $ewd_uwpm_controller->notifications->get_user_phone_number( $user ); |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Save the metabox data for each email |
| 436 |
* @since 1.0.0 |
| 437 |
*/ |
| 438 |
public function save_email_meta( $post_id ) { |
| 439 |
global $ewd_uwpm_controller; |
| 440 |
|
| 441 |
// Verify nonce |
| 442 |
if ( ! isset( $_POST['ewd_uwpm_nonce'] ) || ! wp_verify_nonce( $_POST['ewd_uwpm_nonce'], basename( __FILE__ ) ) ) { |
| 443 |
|
| 444 |
return $post_id; |
| 445 |
} |
| 446 |
|
| 447 |
// Check autosave |
| 448 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 449 |
|
| 450 |
return $post_id; |
| 451 |
} |
| 452 |
|
| 453 |
if ( get_post_type( $post_id ) != EWD_UWPM_EMAIL_POST_TYPE ) { |
| 454 |
|
| 455 |
return $post_id; |
| 456 |
} |
| 457 |
|
| 458 |
// Check permissions |
| 459 |
if ( ! current_user_can( 'edit_page', $post_id ) ) { |
| 460 |
return $post_id; |
| 461 |
} elseif ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 462 |
return $post_id; |
| 463 |
} |
| 464 |
|
| 465 |
if ( isset( $_POST['ewd_uwpm_email_content'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Mail_Content', wp_kses_post( $_POST['ewd_uwpm_email_content'] ) ); } |
| 466 |
if ( isset( $_POST['ewd_uwpm_plain_text_email'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Plain_Text_Mail_Content', sanitize_text_field( $_POST['ewd_uwpm_plain_text_email'] ) ); } |
| 467 |
|
| 468 |
if ( isset( $_POST['ewd_uwpm_content_alignment'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Content_Alignment', sanitize_text_field( $_POST['ewd_uwpm_content_alignment'] ) ); } |
| 469 |
if ( isset( $_POST['ewd_uwpm_max_width'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Max_Width', sanitize_text_field( $_POST['ewd_uwpm_max_width'] ) ); } |
| 470 |
if ( isset( $_POST['ewd_uwpm_background_color'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Email_Background_Color', sanitize_text_field( $_POST['ewd_uwpm_background_color'] ) ); } |
| 471 |
if ( isset( $_POST['ewd_uwpm_body_background_color'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Body_Background_Color', sanitize_text_field( $_POST['ewd_uwpm_body_background_color'] ) ); } |
| 472 |
if ( isset( $_POST['ewd_uwpm_block_background_color'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Block_Background_Color', sanitize_text_field( $_POST['ewd_uwpm_block_background_color'] ) ); } |
| 473 |
if ( isset( $_POST['ewd_uwpm_block_border'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_Block_Border', sanitize_text_field( $_POST['ewd_uwpm_block_border'] ) ); } |
| 474 |
} |
| 475 |
|
| 476 |
/** |
| 477 |
* Save the metabox data for each SMS |
| 478 |
* @since 1.2.0 |
| 479 |
*/ |
| 480 |
public function save_sms_meta( $post_id ) { |
| 481 |
global $ewd_uwpm_controller; |
| 482 |
|
| 483 |
// Verify nonce |
| 484 |
if ( ! isset( $_POST['ewd_uwpm_nonce'] ) || ! wp_verify_nonce( $_POST['ewd_uwpm_nonce'], basename( __FILE__ ) ) ) { |
| 485 |
|
| 486 |
return $post_id; |
| 487 |
} |
| 488 |
|
| 489 |
// Check autosave |
| 490 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 491 |
|
| 492 |
return $post_id; |
| 493 |
} |
| 494 |
|
| 495 |
if ( get_post_type( $post_id ) != EWD_UWPM_SMS_POST_TYPE ) { |
| 496 |
|
| 497 |
return $post_id; |
| 498 |
} |
| 499 |
|
| 500 |
// Check permissions |
| 501 |
if ( ! current_user_can( 'edit_page', $post_id ) ) { |
| 502 |
return $post_id; |
| 503 |
} elseif ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 504 |
return $post_id; |
| 505 |
} |
| 506 |
|
| 507 |
if ( isset( $_POST['ewd_uwpm_sms_content'] ) ) { update_post_meta( $post_id, 'EWD_UWPM_SMS_Content', sanitize_textarea_field( $_POST['ewd_uwpm_sms_content'] ) ); } |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Add in new columns for the email log post type |
| 512 |
* @since 1.1.0 |
| 513 |
*/ |
| 514 |
public function register_email_log_table_columns( $defaults ) { |
| 515 |
global $ewd_ufaq_controller; |
| 516 |
|
| 517 |
$columns = array( |
| 518 |
'ewd_uwpm_status' => __( 'Status', 'ultimate-wp-mail' ), |
| 519 |
'ewd_uwpm_subject' => __( 'Subject', 'ultimate-wp-mail' ), |
| 520 |
'ewd_uwpm_recipient' => __( 'To', 'ultimate-wp-mail' ), |
| 521 |
'ewd_uwpm_send_datetime' => __( 'Send Date', 'ultimate-wp-mail' ), |
| 522 |
'ewd_uwpm_send_details' => __( 'Details', 'ultimate-wp-mail' ), |
| 523 |
); |
| 524 |
|
| 525 |
return $columns; |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
/** |
| 530 |
* Set the content for the custom columns for the email log post type |
| 531 |
* @since 1.1.0 |
| 532 |
*/ |
| 533 |
public function display_email_log_columns_content ( $column_name, $post_id ) { |
| 534 |
|
| 535 |
if ( $column_name == 'ewd_uwpm_status' ) { |
| 536 |
|
| 537 |
echo esc_html( get_post_meta( $post_id, 'status', true ) ); |
| 538 |
} |
| 539 |
|
| 540 |
if ( $column_name == 'ewd_uwpm_subject' ) { |
| 541 |
|
| 542 |
echo esc_html( get_the_title( $post_id ) ); |
| 543 |
} |
| 544 |
|
| 545 |
if ( $column_name == 'ewd_uwpm_recipient' ) { |
| 546 |
|
| 547 |
echo esc_html( get_post_meta( $post_id, 'recipient', true ) ); |
| 548 |
} |
| 549 |
|
| 550 |
if ( $column_name == 'ewd_uwpm_send_datetime' ) { |
| 551 |
|
| 552 |
echo get_the_date( 'Y-m-d H:i:s', $post_id ); |
| 553 |
} |
| 554 |
|
| 555 |
if ( $column_name == 'ewd_uwpm_send_details' ) { |
| 556 |
|
| 557 |
echo '<span class="ewd-uwpm-email-log-details dashicons dashicons-testimonial" data-post_id="' . esc_attr( $post_id ) . '"></span>'; |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* Register the sortable columns for the email log post type |
| 563 |
* @since 1.1.0 |
| 564 |
*/ |
| 565 |
public function register_email_log_post_column_sortables( $column ) { |
| 566 |
global $ewd_ufaq_controller; |
| 567 |
|
| 568 |
$column['ewd_uwpm_status'] = 'ewd_uwpm_status'; |
| 569 |
$column['ewd_uwpm_subject'] = 'title'; |
| 570 |
$column['ewd_uwpm_recipient'] = 'ewd_uwpm_recipient'; |
| 571 |
$column['ewd_uwpm_send_datetime'] = 'date'; |
| 572 |
|
| 573 |
return $column; |
| 574 |
} |
| 575 |
|
| 576 |
/** |
| 577 |
* Adjust the wp_query if the orderby clause is one of the custom ones |
| 578 |
* @since 1.1.0 |
| 579 |
*/ |
| 580 |
public function email_log_orderby_custom_columns( $vars ) { |
| 581 |
global $wpdb; |
| 582 |
|
| 583 |
if ( ! isset( $vars['orderby'] ) ) { return $vars; } |
| 584 |
|
| 585 |
if ( $vars['orderby'] == 'ewd_uwpm_status' or $vars['orderby'] == 'ewd_uwpm_recipient' ) { |
| 586 |
|
| 587 |
$vars = array_merge( |
| 588 |
$vars, |
| 589 |
array( |
| 590 |
'meta_key' => $vars['orderby'], |
| 591 |
'orderby' => 'meta_value' |
| 592 |
) |
| 593 |
); |
| 594 |
} |
| 595 |
|
| 596 |
return $vars; |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Removes all quick action links for email log posts |
| 601 |
* @since 1.1.0 |
| 602 |
*/ |
| 603 |
public function remove_email_log_post_row_actions( $actions, $post ) { |
| 604 |
|
| 605 |
if ( get_post_type( $post ) != EWD_UWPM_EMAIL_LOG_POST_TYPE ) { return $actions; } |
| 606 |
|
| 607 |
return array(); |
| 608 |
} |
| 609 |
|
| 610 |
/** |
| 611 |
* Returns the name of an email list given its ID |
| 612 |
* @since 1.0.0 |
| 613 |
*/ |
| 614 |
public function get_list_name_from_id( $list_id ) { |
| 615 |
global $ewd_uwpm_controller; |
| 616 |
|
| 617 |
$lists = ewd_uwpm_decode_infinite_table_setting( $ewd_uwpm_controller->settings->get_setting( 'lists' ) ); |
| 618 |
|
| 619 |
foreach ( $lists as $list ) { |
| 620 |
|
| 621 |
if ( $list->id == $list_id ) { return $list->name; } |
| 622 |
} |
| 623 |
|
| 624 |
return false; |
| 625 |
} |
| 626 |
|
| 627 |
/** |
| 628 |
* Replace 'Publish', 'Update' and 'Save' for the email post type |
| 629 |
* @since 1.0.0 |
| 630 |
*/ |
| 631 |
public function change_post_page_translations( $translated, $original, $domain ) { |
| 632 |
global $post_type; |
| 633 |
|
| 634 |
if ( empty( $post_type ) or $post_type != EWD_UWPM_EMAIL_POST_TYPE ) { return $translated; } |
| 635 |
|
| 636 |
$replacements = array( |
| 637 |
'Publish' => 'Save', |
| 638 |
'Published' => 'Saved', |
| 639 |
'Update' => 'Save' |
| 640 |
); |
| 641 |
|
| 642 |
return strtr( $original, $replacements ); |
| 643 |
} |
| 644 |
} |
| 645 |
} // endif; |
| 646 |
|