diff --git a/modules/notifications/notifications.php b/modules/notifications/notifications.php
index 9b05baa7..8fc963a9 100644
--- a/modules/notifications/notifications.php
+++ b/modules/notifications/notifications.php
@@ -10,21 +10,21 @@
if ( !class_exists('EF_Notifications') ) {
class EF_Notifications extends EF_Module {
-
+
// Taxonomy name used to store users following posts
var $following_users_taxonomy = 'following_users';
// Taxonomy name used to store user groups following posts
var $following_usergroups_taxonomy = EF_User_Groups::taxonomy_key;
-
+
var $module;
var $edit_post_subscriptions_cap = 'edit_post_subscriptions';
-
+
/**
* Register the module with Edit Flow but don't do anything else
*/
function __construct () {
-
+
// Register the module with Edit Flow
$this->module_url = $this->get_module_url( __FILE__ );
$args = array(
@@ -41,6 +41,8 @@ function __construct () {
'page' => 'on',
),
'always_notify_admin' => 'off',
+ 'send_to_slack' => 'off',
+ 'slack_webhook_url' => '',
),
'configure_page_cb' => 'print_configure_view',
'post_type_support' => 'ef_notification',
@@ -53,9 +55,9 @@ function __construct () {
'settings_help_sidebar' => __( '
For more information:
Notifications Documentation
Edit Flow Forum
Edit Flow on Github
', 'edit-flow' ),
);
$this->module = EditFlow()->register_module( 'notifications', $args );
-
+
}
-
+
/**
* Initialize the notifications class if the plugin is enabled
*/
@@ -66,13 +68,13 @@ function init() {
// Allow users to use a different user capability for editing post subscriptions
$this->edit_post_subscriptions_cap = apply_filters( 'ef_edit_post_subscriptions_cap', $this->edit_post_subscriptions_cap );
-
+
// Set up metabox and related actions
add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
// Add "access badge" to the subscribers list.
add_action( 'ef_user_subscribe_actions', array( $this, 'display_subscriber_warning_badges' ), 10, 2 );
-
+
// Saving post actions
// self::save_post_subscriptions() is hooked into transition_post_status so we can ensure usergroup data
// is properly saved before sending notifs
@@ -81,12 +83,12 @@ function init() {
add_action( 'ef_post_insert_editorial_comment', array( $this, 'notification_comment') );
add_action( 'delete_user', array($this, 'delete_user_action') );
add_action( 'ef_send_scheduled_email', array( $this, 'send_single_email' ), 10, 4 );
-
+
add_action( 'admin_init', array( $this, 'register_settings' ) );
-
+
// Javascript and CSS if we need it
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
// Add a "Follow" link to posts
if ( apply_filters( 'ef_notifications_show_follow_link', true ) ) {
@@ -103,9 +105,9 @@ function init() {
//Ajax for saving notifiction updates
add_action( 'wp_ajax_save_notifications', array( $this, 'ajax_save_post_subscriptions' ) );
add_action( 'wp_ajax_ef_notifications_user_post_subscription', array( $this, 'handle_user_post_subscription' ) );
-
+
}
-
+
/**
* Load the capabilities onto users the first time the module is run
*
@@ -123,7 +125,7 @@ function install() {
foreach ( $notifications_roles as $role => $caps ) {
$this->add_caps_to_role( $role, $caps );
}
-
+
}
/**
@@ -154,9 +156,9 @@ function upgrade( $previous_version ) {
// Technically we've run this code before so we don't want to auto-install new data
$edit_flow->update_module_option( $this->module->name, 'loaded_once', true );
}
-
+
}
-
+
/**
* Register the taxonomies we use to manage relationships
*
@@ -165,10 +167,10 @@ function upgrade( $previous_version ) {
* @uses register_taxonomy()
*/
function register_taxonomies() {
-
+
// Load the currently supported post types so we only register against those
$supported_post_types = $this->get_post_types_for_module( $this->module );
-
+
$args = array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
@@ -180,7 +182,7 @@ function register_taxonomies() {
);
register_taxonomy( $this->following_users_taxonomy, $supported_post_types, $args );
}
-
+
/**
* Enqueue necessary admin scripts
*
@@ -189,7 +191,7 @@ function register_taxonomies() {
* @uses wp_enqueue_script()
*/
function enqueue_admin_scripts() {
-
+
if ( $this->is_whitelisted_functional_view() ) {
wp_enqueue_script( 'jquery-listfilterizer' );
wp_enqueue_script( 'jquery-quicksearch' );
@@ -204,16 +206,16 @@ function enqueue_admin_scripts() {
);
}
}
-
+
/**
* Enqueue necessary admin styles, but only on the proper pages
*
* @since 0.7
*
- * @uses wp_enqueue_style()
+ * @uses wp_enqueue_style()
*/
function enqueue_admin_styles() {
-
+
if ( $this->is_whitelisted_functional_view() || $this->is_whitelisted_settings_view() ) {
wp_enqueue_style( 'jquery-listfilterizer' );
wp_enqueue_style( 'edit-flow-notifications-css', $this->module->module_url . 'lib/notifications.css', false, EDIT_FLOW_VERSION );
@@ -312,26 +314,26 @@ private function get_follow_action_parts( $post ) {
'link' => add_query_arg( $args, admin_url( 'admin-ajax.php' ) ),
);
}
-
+
/**
* Add the subscriptions meta box to relevant post types
*/
function add_post_meta_box() {
- if ( !current_user_can( $this->edit_post_subscriptions_cap ) )
- return;
-
+ if ( !current_user_can( $this->edit_post_subscriptions_cap ) )
+ return;
+
$usergroup_post_types = $this->get_post_types_for_module( $this->module );
foreach ( $usergroup_post_types as $post_type ) {
add_meta_box( 'edit-flow-notifications', __( 'Notifications', 'edit-flow'), array( $this, 'notifications_meta_box'), $post_type, 'advanced' );
}
}
-
+
/**
* Outputs box used to subscribe users and usergroups to Posts
*
* @todo add_cap to set subscribers for posts; default to Admin and editors
- */
+ */
function notifications_meta_box() {
global $post, $post_ID, $edit_flow;
?>
@@ -348,7 +350,7 @@ function notifications_meta_box() {
);
$this->users_select_form( $followers, $select_form_args ); ?>
-
+
module_enabled( 'user_groups' ) && in_array( $this->get_current_post_type(), $this->get_post_types_for_module( $edit_flow->user_groups->module ) ) ): ?>
@@ -361,7 +363,7 @@ function notifications_meta_box() {
-
+
user_can_be_notified( get_user_by( 'id', $user_id ), $post->ID )) {
// span.post_following_list-no_access is also added in notifications.js after AJAX that ticks/unticks a user
echo '' . esc_html__( 'No Access', 'edit-flow' ) . '';
}
-
+
// Add No Email span if they have no email
$user_object = get_user_by( 'id', $user_id );
if ( !is_a( $user_object, 'WP_User') OR empty( $user_object->user_email ) ) {
@@ -394,7 +396,7 @@ function display_subscriber_warning_badges( $user_id, $checked ) {
echo '' . esc_html__( 'No Email', 'edit-flow' ) . '';
}
}
-
+
/**
* Called when a notification editorial metadata checkbox is checked. Handles saving of a user/usergroup to a post.
*/
@@ -423,15 +425,15 @@ function ajax_save_post_subscriptions() {
// Prevent auto-subscribing users that have opted out of notifications.
add_filter( 'ef_notification_auto_subscribe_current_user', '__return_false', PHP_INT_MAX );
$this->save_post_following_users( $post, $user_group_ids );
-
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['post_id'] ) ) {
-
+
// Determine if any of the selected users won't have notification access
$subscribers_with_no_access = array_filter( $user_group_ids, function( $user_id ) {
return ! $this->user_can_be_notified( get_user_by( 'id', $user_id ), $_POST['post_id'] );
} );
- // Determine if any of the selected users are missing their emails
+ // Determine if any of the selected users are missing their emails
$subscribers_with_no_email = array();
foreach ( $user_group_ids AS $user_id ) {
$user_object = get_user_by( 'id', $user_id );
@@ -439,19 +441,19 @@ function ajax_save_post_subscriptions() {
$subscribers_with_no_email[] = $user_id;
}
}
-
+
// Assemble the json reply with various lists of problematic users
- $json_success = array(
+ $json_success = array(
'subscribers_with_no_access' => array_values( $subscribers_with_no_access ),
'subscribers_with_no_email' => array_values( $subscribers_with_no_email ),
);
-
+
wp_send_json_success( $json_success );
}
// Remove auto-subscribe prevention behavior from earlier.
remove_filter( 'ef_notification_auto_subscribe_current_user', '__return_false', PHP_INT_MAX );
}
-
+
$groups_enabled = $this->module_enabled( 'user_groups' ) && in_array( get_post_type( $post_id ), $this->get_post_types_for_module( $edit_flow->user_groups->module ) );
if ( 'following_usergroups[]' === $_POST['ef_notifications_name'] && $groups_enabled ) {
$this->save_post_following_usergroups( $post, $user_group_ids );
@@ -505,9 +507,9 @@ function save_post_subscriptions( $new_status, $old_status, $post ) {
if ( $this->module_enabled( 'user_groups' ) && in_array( $this->get_current_post_type(), $this->get_post_types_for_module( $edit_flow->user_groups->module ) ) )
$this->save_post_following_usergroups( $post, $usergroups );
}
-
+
}
-
+
/**
* Sets users to follow specified post
*
@@ -516,7 +518,7 @@ function save_post_subscriptions( $new_status, $old_status, $post ) {
function save_post_following_users( $post, $users = null ) {
if( !is_array( $users ) )
$users = array();
-
+
// Add current user to following users
$user = wp_get_current_user();
if ( $user && apply_filters( 'ef_notification_auto_subscribe_current_user', true, 'subscription_action' ) )
@@ -525,13 +527,13 @@ function save_post_following_users( $post, $users = null ) {
// Add post author to following users
if ( apply_filters( 'ef_notification_auto_subscribe_post_author', true, 'subscription_action' ) )
$users[] = $post->post_author;
-
+
$users = array_unique( array_map( 'intval', $users ) );
$follow = $this->follow_post_user( $post, $users, false );
-
+
}
-
+
/**
* Sets usergroups to follow specified post
*
@@ -539,13 +541,13 @@ function save_post_following_users( $post, $users = null ) {
* @param array $usergroups Usergroups to follow posts
*/
function save_post_following_usergroups( $post, $usergroups = null ) {
-
+
if( !is_array($usergroups) ) $usergroups = array();
$usergroups = array_map( 'intval', $usergroups );
$follow = $this->follow_post_usergroups($post, $usergroups, false);
- }
-
+ }
+
/**
* Set up and send post status change notification email
*/
@@ -555,26 +557,26 @@ function notification_status_change( $new_status, $old_status, $post ) {
// Kill switch for notification
if ( ! apply_filters( 'ef_notification_status_change', $new_status, $old_status, $post ) || ! apply_filters( "ef_notification_{$post->post_type}_status_change", $new_status, $old_status, $post ) )
return false;
-
+
$supported_post_types = $this->get_post_types_for_module( $this->module );
if ( !in_array( $post->post_type, $supported_post_types ) )
return;
-
+
// No need to notify if it's a revision, auto-draft, or if post status wasn't changed
$ignored_statuses = apply_filters( 'ef_notification_ignored_statuses', array( $old_status, 'inherit', 'auto-draft' ), $post->post_type );
-
+
if ( !in_array( $new_status, $ignored_statuses ) ) {
-
+
// Get current user
$current_user = wp_get_current_user();
-
+
$post_author = get_userdata( $post->post_author );
//$duedate = $edit_flow->post_metadata->get_post_meta($post->ID, 'duedate', true);
-
+
$blogname = get_option('blogname');
-
+
$body = '';
-
+
$post_id = $post->ID;
$post_title = ef_draft_or_post_title( $post_id );
$post_type = get_post_type_object( $post->post_type )->labels->singular_name;
@@ -594,23 +596,23 @@ function notification_status_change( $new_status, $old_status, $post ) {
/**
* get_post_status_object will return null for certain statuses (i.e., 'new')
- * The mega if/else block below should catch all cases, but just in case, we
+ * The mega if/else block below should catch all cases, but just in case, we
* make sure to at least set $old_status_friendly_name and $new_status_friendly_name
* to an empty string to ensure they're at least set.
- *
+ *
* Then, we attempt to set them to a sensible default before we start the
* mega if/else block
*/
if ( ! is_null( $old_status_post_obj ) ) {
$old_status_friendly_name = $old_status_post_obj->label;
}
-
+
if ( ! is_null( $new_status_post_obj ) ) {
$new_status_friendly_name = $new_status_post_obj->label;
}
-
- // Email subject and first line of body
- // Set message subjects according to what action is being taken on the Post
+
+ // Email subject and first line of body
+ // Set message subjects according to what action is being taken on the Post
if ( $old_status == 'new' || $old_status == 'auto-draft' ) {
$old_status_friendly_name = "New";
/* translators: 1: site name, 2: post type, 3. post title */
@@ -648,25 +650,25 @@ function notification_status_change( $new_status, $old_status, $post ) {
/* translators: 1: post type, 2: post id, 3. post title, 4. user name, 5. user email */
$body .= sprintf( __( 'Status was changed for %1$s #%2$s "%3$s" by %4$s %5$s', 'edit-flow'), $post_type, $post_id, $post_title, $current_user_display_name, $current_user_email ) . "\r\n";
}
-
+
/* translators: 1: date, 2: time, 3: timezone */
$body .= sprintf( __( 'This action was taken on %1$s at %2$s %3$s', 'edit-flow' ), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ), get_option( 'timezone_string' ) ) . "\r\n";
-
+
// Email body
$body .= "\r\n";
/* translators: 1: old status, 2: new status */
$body .= sprintf( __( '%1$s => %2$s', 'edit-flow' ), $old_status_friendly_name, $new_status_friendly_name );
$body .= "\r\n\r\n";
-
+
$body .= "--------------------\r\n\r\n";
-
+
$body .= sprintf( __( '== %s Details ==', 'edit-flow' ), $post_type ) . "\r\n";
$body .= sprintf( __( 'Title: %s', 'edit-flow' ), $post_title ) . "\r\n";
if ( ! empty( $post_author ) ) {
/* translators: 1: author name, 2: author email */
$body .= sprintf( __( 'Author: %1$s (%2$s)', 'edit-flow' ), $post_author->display_name, $post_author->user_email ) . "\r\n";
}
-
+
$edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) );
if ( $new_status != 'publish' ) {
$view_link = add_query_arg( array( 'preview' => 'true' ), wp_get_shortlink( $post_id ) );
@@ -678,35 +680,38 @@ function notification_status_change( $new_status, $old_status, $post ) {
$body .= sprintf( __( 'Add editorial comment: %s', 'edit-flow' ), $edit_link . '#editorialcomments/add' ) . "\r\n";
$body .= sprintf( __( 'Edit: %s', 'edit-flow' ), $edit_link ) . "\r\n";
$body .= sprintf( __( 'View: %s', 'edit-flow' ), $view_link ) . "\r\n";
-
+
$body .= $this->get_notification_footer($post);
-
+
$this->send_email( 'status-change', $post, $subject, $body );
+
+ if ( 'on' === $this->module->options->send_to_slack )
+ $this->send_to_slack( $body );
}
-
+
}
-
+
/**
* Set up and set editorial comment notification email
- *
+ *
* @param WP_Comment $comment
* @return boolean|null|void
*/
function notification_comment( $comment ) {
-
+
$post = get_post($comment->comment_post_ID);
-
+
$supported_post_types = $this->get_post_types_for_module( $this->module );
if ( !in_array( $post->post_type, $supported_post_types ) )
- return;
-
+ return;
+
// Kill switch for notification
if ( ! apply_filters( 'ef_notification_editorial_comment', $comment, $post ) )
return false;
-
+
$user = get_userdata( $post->post_author );
$current_user = wp_get_current_user();
-
+
$post_id = $post->ID;
$post_type = get_post_type_object( $post->post_type )->labels->singular_name;
$post_title = ef_draft_or_post_title( $post_id );
@@ -717,7 +722,7 @@ function notification_comment( $comment ) {
// Check if this a reply
//$parent_ID = isset( $comment->comment_parent_ID ) ? $comment->comment_parent_ID : 0;
//if($parent_ID) $parent = get_comment($parent_ID);
-
+
// Set user to follow post, but make it filterable
if ( apply_filters( 'ef_notification_auto_subscribe_current_user', true, 'comment' ) )
$this->follow_post_user($post, (int) $current_user->ID);
@@ -725,9 +730,9 @@ function notification_comment( $comment ) {
// Set the post author to follow the post but make it filterable
if ( apply_filters( 'ef_notification_auto_subscribe_post_author', true, 'comment' ) )
$this->follow_post_user( $post, (int) $post->post_author );
-
+
$blogname = get_option('blogname');
-
+
/* translators: 1: blog name, 2: post title */
$subject = sprintf( __( '[%1$s] New Editorial Comment: "%2$s"', 'edit-flow' ), $blogname, $post_title );
@@ -740,35 +745,41 @@ function notification_comment( $comment ) {
// @TODO: mention if it was a reply
/*
if($parent) {
-
+
}
*/
-
-
+
+
$body .= "\r\n--------------------\r\n";
// Insert the notification list from comment meta @see EF_Editorial_Comments->maybe_output_comment_meta()
if ($notification_list) {
$body .= esc_html__( 'Notified', 'edit-flow' ) . ": " . esc_html( $notification_list ) . "\n";
}
-
+
$edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) );
$view_link = htmlspecialchars_decode( get_permalink( $post_id ) );
-
+
$body .= "\r\n";
$body .= __( '== Actions ==', 'edit-flow' ) . "\r\n";
$body .= sprintf( __( 'Reply: %s', 'edit-flow' ), $edit_link . '#editorialcomments/reply/' . $comment->comment_ID ) . "\r\n";
$body .= sprintf( __( 'Add editorial comment: %s', 'edit-flow' ), $edit_link . '#editorialcomments/add' ) . "\r\n";
$body .= sprintf( __( 'Edit: %s', 'edit-flow' ), $edit_link ) . "\r\n";
$body .= sprintf( __( 'View: %s', 'edit-flow' ), $view_link ) . "\r\n";
-
- $body .= "\r\n" . sprintf( __( 'You can see all editorial comments on this %s here: ', 'edit-flow' ), $post_type ). "\r\n";
+
+ $body .= "\r\n" . sprintf( __( 'You can see all editorial comments on this %s here: ', 'edit-flow' ), $post_type ). "\r\n";
$body .= $edit_link . "#editorialcomments" . "\r\n\r\n";
-
+
$body .= $this->get_notification_footer($post);
-
+
$this->send_email( 'comment', $post, $subject, $body );
+
+ $format = "*%s* left a comment on *%s #%s - %s*\n\n %s";
+ $text = sprintf( $format, $comment->comment_author, $post_type, $post_id, $post_title, $comment->comment_content );
+
+ if ( 'on' === $this->module->options->send_to_slack )
+ $this->send_to_slack( $body );
}
-
+
function get_notification_footer( $post ) {
$body = "";
$body .= "\r\n--------------------\r\n";
@@ -778,23 +789,23 @@ function get_notification_footer( $post ) {
$body .= "\r\n \r\n";
$body .= get_option('blogname') ." | ". get_bloginfo('url') . " | " . admin_url('/') . "\r\n";
return $body;
- }
-
+ }
+
/**
* send_email()
*/
function send_email( $action, $post, $subject, $message, $message_headers = '' ) {
-
- // Get list of email recipients -- set them CC
+
+ // Get list of email recipients -- set them CC
$recipients = $this->_get_notification_recipients( $post, true );
-
+
if( $recipients && ! is_array( $recipients ) )
$recipients = explode( ',', $recipients );
$subject = apply_filters( 'ef_notification_send_email_subject', $subject, $action, $post );
$message = apply_filters( 'ef_notification_send_email_message', $message, $action, $post );
$message_headers = apply_filters( 'ef_notification_send_email_message_headers', $message_headers, $action, $post );
-
+
if( EF_NOTIFICATION_USE_CRON ) {
$this->schedule_emails( $recipients, $subject, $message, $message_headers );
} else if ( !empty( $recipients ) ) {
@@ -803,10 +814,33 @@ function send_email( $action, $post, $subject, $message, $message_headers = '' )
}
}
}
-
+
+ /**
+ * Send notifications to Slack
+ */
+ function send_to_slack( $message ) {
+ $slack_webhook_url = $this->module->options->slack_webhook_url;
+
+ // Bail if the webhook URL is not set
+ if ( empty( $slack_webhook_url ) ) {
+ return;
+ }
+
+ // Set up the payload
+ $payload = array(
+ 'text' => $message,
+ );
+
+ // Send the notification
+ $response = wp_remote_post( $slack_webhook_url, array(
+ 'body' => json_encode( $payload ),
+ 'headers' => array( 'Content-Type' => 'application/json' ),
+ ) );
+ }
+
/**
* Schedules emails to be sent in succession
- *
+ *
* @param mixed $recipients Individual email or array of emails
* @param string $subject Subject of the email
* @param string $message Body of the email
@@ -815,19 +849,19 @@ function send_email( $action, $post, $subject, $message, $message_headers = '' )
*/
function schedule_emails( $recipients, $subject, $message, $message_headers = '', $time_offset = 1 ) {
$recipients = (array) $recipients;
-
+
$send_time = time();
-
+
foreach( $recipients as $recipient ) {
wp_schedule_single_event( $send_time, 'ef_send_scheduled_email', array( $recipient, $subject, $message, $message_headers ) );
$send_time += $time_offset;
}
-
+
}
-
+
/**
* Sends an individual email
- *
+ *
* @param mixed $to Email to send to
* @param string $subject Subject of the email
* @param string $message Body of the email
@@ -911,7 +945,7 @@ private function _get_notification_recipients( $post, $string = false ) {
/**
* Check if a user can be notified.
* This is based off of the ability to edit the post/page by default.
- *
+ *
* @since 0.8.3
* @param WP_User $user
* @param int $post_id
@@ -956,7 +990,7 @@ function follow_post_user( $post, $users, $append = true ) {
$user_terms = array();
foreach( $users as $user ) {
- if ( is_int( $user ) )
+ if ( is_int( $user ) )
$user = get_user_by( 'id', $user );
elseif ( is_string( $user ) )
$user = get_user_by( 'login', $user );
@@ -968,7 +1002,7 @@ function follow_post_user( $post, $users, $append = true ) {
// Add user as a term if they don't exist
$term = $this->add_term_if_not_exists( $name, $this->following_users_taxonomy );
-
+
if ( ! is_wp_error( $term ) ) {
$user_terms[] = $name;
}
@@ -982,7 +1016,7 @@ function follow_post_user( $post, $users, $append = true ) {
}
/**
- * Removes user from following_users taxonomy for the given Post,
+ * Removes user from following_users taxonomy for the given Post,
* so they no longer receive future notifications.
*
* @param object $post Post object or ID
@@ -1005,7 +1039,7 @@ function unfollow_post_user( $post, $users ) {
$user_terms = wp_list_pluck( $terms, 'slug' );
foreach( $users as $user ) {
- if ( is_int( $user ) )
+ if ( is_int( $user ) )
$user = get_user_by( 'id', $user );
elseif ( is_string( $user ) )
$user = get_user_by( 'login', $user );
@@ -1025,7 +1059,7 @@ function unfollow_post_user( $post, $users ) {
return true;
}
- /**
+ /**
* follow_post_usergroups()
*
*/
@@ -1045,7 +1079,7 @@ function follow_post_usergroups( $post, $usergroups = 0, $append = true ) {
wp_set_object_terms( $post_id, $usergroups, $this->following_usergroups_taxonomy, $append );
return;
}
-
+
/**
* Removes users that are deleted from receiving future notifications (i.e. makes them unfollow posts FOREVER!)
*
@@ -1053,10 +1087,10 @@ function follow_post_usergroups( $post, $usergroups = 0, $append = true ) {
*/
function delete_user_action( $id ) {
if( !$id ) return;
-
+
// get user data
$user = get_userdata($id);
-
+
if( $user ) {
// Delete term from the following_users taxonomy
$user_following_term = get_term_by('name', $user->user_login, $this->following_users_taxonomy);
@@ -1064,7 +1098,7 @@ function delete_user_action( $id ) {
}
return;
}
-
+
/**
* Add user as a term if they aren't already
* @param $term string term to be added
@@ -1073,16 +1107,16 @@ function delete_user_action( $id ) {
*/
function add_term_if_not_exists( $term, $taxonomy ) {
if ( !term_exists($term, $taxonomy) ) {
- $args = array( 'slug' => sanitize_title($term) );
+ $args = array( 'slug' => sanitize_title($term) );
return wp_insert_term( $term, $taxonomy, $args );
}
return true;
}
-
+
/**
* Gets a list of the users following the specified post
*
- * @param int $post_id The ID of the post
+ * @param int $post_id The ID of the post
* @param string $return The field to return
* @return array $users Users following the specified posts
*/
@@ -1125,7 +1159,7 @@ function get_following_users( $post_id, $return = 'user_login' ) {
break;
case 'user_email':
$users[$key] = $new_user->user_email;
- break;
+ break;
}
}
if( !$users || is_wp_error($users) )
@@ -1133,11 +1167,11 @@ function get_following_users( $post_id, $return = 'user_login' ) {
return $users;
}
-
+
/**
* Gets a list of the usergroups that are following specified post
*
- * @param int $post_id
+ * @param int $post_id
* @return array $usergroups All of the usergroup slugs
*/
function get_following_usergroups( $post_id, $return = 'all' ) {
@@ -1154,18 +1188,18 @@ function get_following_usergroups( $post_id, $return = 'all' ) {
if( $return == 'slugs' ) {
$slugs = array();
foreach($usergroups as $usergroup) {
- $slugs[] = $usergroup->slug;
+ $slugs[] = $usergroup->slug;
}
$usergroups = $slugs;
}
return $usergroups;
}
-
+
/**
* Gets a list of posts that a user is following
*
* @param string|int $user user_login or id of user
- * @param array $args
+ * @param array $args
* @return array $posts Posts a user is following
*/
function get_user_following_posts( $user = 0, $args = null ) {
@@ -1193,19 +1227,21 @@ function get_user_following_posts( $user = 0, $args = null ) {
return $posts;
}
-
+
/**
* Register settings for notifications so we can partially use the Settings API
* (We use the Settings API for form generation, but not saving)
- *
+ *
* @since 0.7
*/
function register_settings() {
add_settings_section( $this->module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name );
add_settings_field( 'post_types', __( 'Post types for notifications:', 'edit-flow' ), array( $this, 'settings_post_types_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' );
add_settings_field( 'always_notify_admin', __( 'Always notify blog admin', 'edit-flow' ), array( $this, 'settings_always_notify_admin_option'), $this->module->options_group_name, $this->module->options_group_name . '_general' );
+ add_settings_field( 'send_to_slack', __( 'Send to Slack', 'edit-flow' ), array( $this, 'settings_send_to_slack'), $this->module->options_group_name, $this->module->options_group_name . '_general' );
+ add_settings_field( 'slack_webhook_url', __( 'Slack Webhook URL', 'edit-flow' ), array( $this, 'settings_slack_webhook_url'), $this->module->options_group_name, $this->module->options_group_name . '_general' );
}
-
+
/**
* Chose the post types for notifications
*
@@ -1213,7 +1249,7 @@ function register_settings() {
*/
function settings_post_types_option() {
global $edit_flow;
- $edit_flow->settings->helper_option_custom_post_type( $this->module );
+ $edit_flow->settings->helper_option_custom_post_type( $this->module );
}
/**
@@ -1223,25 +1259,53 @@ function settings_post_types_option() {
*/
function settings_always_notify_admin_option() {
$options = array(
- 'off' => __( 'Disabled', 'edit-flow' ),
+ 'off' => __( 'Disabled', 'edit-flow' ),
'on' => __( 'Enabled', 'edit-flow' ),
);
echo '';
+ }
+
+ /**
+ * Option to enable sending notifications to Slack
+ *
+ * @since 0.9.9
+ */
+ function settings_send_to_slack() {
+ $options = array(
+ 'off' => __( 'Disabled', 'edit-flow' ),
+ 'on' => __( 'Enabled', 'edit-flow' ),
+ );
+ echo '';
}
+ /**
+ * Option to set the Slack webhook URL
+ *
+ * @since 0.9.9
+ */
+ function settings_slack_webhook_url() {
+ echo '';
+ }
+
/**
* Validate our user input as the settings are being saved
*
* @since 0.7
*/
function settings_validate( $new_options ) {
-
+
// Whitelist validation for the post type options
if ( !isset( $new_options['post_types'] ) )
$new_options['post_types'] = array();
@@ -1250,15 +1314,23 @@ function settings_validate( $new_options ) {
// Whitelist validation for the 'always_notify_admin' options
if ( !isset( $new_options['always_notify_admin'] ) || $new_options['always_notify_admin'] != 'on' )
$new_options['always_notify_admin'] = 'off';
-
+
+ // White list validation for the 'send_to_slack' option
+ if ( !isset( $new_options['send_to_slack'] ) || $new_options['send_to_slack'] != 'on' )
+ $new_options['send_to_slack'] = 'off';
+
+ // White list validation for the 'slack_webhook_url' option
+ if ( !isset( $new_options['slack_webhook_url'] ) )
+ $new_options['slack_webhook_url'] = '';
+
return $new_options;
- }
+ }
/**
* Settings page for notifications
*
- * @since 0.7
+ * @since 0.7
*/
function print_configure_view() {
?>
@@ -1266,23 +1338,23 @@ function print_configure_view() {
module->options_group_name ); ?>
module->options_group_name ); ?>
module->name ) . '" />';
+ echo '';
?>
post_date );
$date = date_i18n( get_option( 'date_format' ), $scheduled_ts );