/** * The metabox contents for an existing post * * This should probably use WP_Users_List_Table eventually * * @since 0.1.0 */ function wp_user_alerts_metabox_existing_post() { // Get users $user_ids = wp_user_alerts_get_user_ids(); $users = get_users(array('include' => $user_ids)); // Users were alerted if (empty($user_ids) || empty($users)) { ?> <p><?php esc_html_e('No users were alerted at the time this was published.', 'wp-user-alerts'); ?> </p><?php // Users were alerted } else { // Get post alert properties $post_id = get_the_ID(); $post_priority = wp_user_alerts_get_alert_priority($post_id); // Methods $post_methods = wp_user_alerts_get_post_methods($post_id); if (!empty($post_methods)) { $all_methods = wp_user_alerts_get_alert_methods(); $method_keys = array_keys($all_methods); $methods = array(); foreach ($post_methods as $post_method) { if (in_array($post_method, $method_keys, true)) { $methods[] = $all_methods[$post_method]->name; } } $methods = implode(', ', $methods); } else { $methods = esc_html__('None', 'wp-user-alerts'); } // Message $post_message = wp_user_alerts_get_alert_message_body($post_id, 'sms'); $post_message = !empty($post_message) ? $post_message : esc_html__('No message', 'wp-user-alerts'); ?> <div class="wp-user-alerts-alerted"> <div class="wp-user-alerts-properties"> <table> <tr> <th><?php esc_html_e('Priority', 'wp-user-alerts'); ?> </th> <td><span class="alert-priority-<?php echo $post_priority->id; ?> "><?php echo esc_html($post_priority->name); ?> </td> <th><?php esc_html_e('Users', 'wp-user-alerts'); ?> </th> <td><?php echo number_format_i18n(count($user_ids)); ?> </td> </tr> <tr> <th><?php esc_html_e('Alert Methods', 'wp-user-alerts'); ?> </th> <td><?php echo $methods; ?> </td> <th><?php esc_html_e('Short Message', 'wp-user-alerts'); ?> </th> <td><?php echo $post_message; ?> </td> </tr> </table> </div> <table class="wp-list-table widefat fixed striped users"> <thead> <tr class="wp-user-alerts-post-header"> <th class="column-primary"><?php esc_html_e('People', 'wp-user-alerts'); ?> </th> <th><?php esc_html_e('Name', 'wp-user-alerts'); ?> </th> <th><?php esc_html_e('Email', 'wp-user-alerts'); ?> </th> <th><?php esc_html_e('Acknowledged', 'wp-user-alerts'); ?> </th> </tr> </thead> <tbody><?php // Loop through users foreach ($users as $user) { // Dismissed $dismissed = wp_user_alert_is_dismissed(get_the_ID(), $user->ID) ? esc_html__('Yes', 'wp-user-alerts') : esc_html__('No', 'wp-user-alerts'); // Output some basic user info ?> <tr id="user-1"> <td class="username column-username has-row-actions column-primary" data-colname="<?php esc_html_e('Username', 'wp-user-alerts'); ?> "><?php echo get_avatar($user->ID, 36); ?> <strong><?php echo esc_html($user->user_login); ?> </strong> <div class="row-actions"><?php if (current_user_can('edit_user', $user->ID)) { ?> <a href="<?php echo get_edit_user_link($user->ID); ?> "><?php esc_html_e('Edit', 'wp-user-alerts'); ?> </a><?php } ?> </div> </td> <td class="name column-name" data-colname="<?php esc_html_e('Name', 'wp-user-alerts'); ?> "><?php printf('%s %s', $user->first_name, $user->last_name); ?> </td> <td class="email column-email" data-colname="<?php esc_html_e('Email', 'wp-user-alerts'); ?> "><?php echo make_clickable($user->user_email); ?> </td> <td class="dismissed column-dismissed" data-colname="<?php esc_html_e('Acknowledged', 'wp-user-alerts'); ?> "><?php echo esc_html($dismissed); ?> </td> </tr><?php } ?> </tbody></table></div><?php } }
/** * Send all of the alerts * * @since 0.1.0 * * @param string $new_status * @param string $old_status * @param WP_Post $post */ function wp_user_alerts_maybe_do_all_alerts($new_status, $old_status, $post = null) { // Allowed Statuses $allowed_statuses = wp_user_alerts_get_allowed_post_statuses(); // Bail if already published if (in_array($old_status, $allowed_statuses, true)) { return; } // Bail if new status is not publish if (!in_array($new_status, $allowed_statuses, true)) { return; } // Bail on autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Bail if not supported if (!post_type_supports($post->post_type, 'alerts')) { return; } // Bail if not publishing if (!in_array(get_post_status($post->ID), $allowed_statuses, true)) { return; } // Get the priority, methods, and user IDs $user_ids = wp_user_alerts_get_alerted_user_ids($post->ID); $methods = wp_user_alerts_get_post_methods($post->ID); // Append priority label to subject $subject = wp_user_alerts_get_alert_message_subject($post); // Save user IDs to postmeta, or delete if empty !empty($user_ids) ? update_post_meta($post->ID, 'wp_user_alerts_user_ids', $user_ids) : delete_post_meta($post->ID, 'wp_user_alerts_user_ids'); // Do the alerts foreach ($methods as $method) { // Strip tags from post content $message = wp_user_alerts_get_alert_message_body($post, $method); // Standard action do_action('wp_user_alerts_send_alerts', $method, $user_ids, $subject, $message); // Dynamic action do_action("wp_user_alerts_send_{$method}", array('user_ids' => $user_ids, 'subject' => $subject, 'message' => $message)); } }