Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/notifications/lib/notifications.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@

#ef-usergroup-users h4 {
margin-top: 0;
}

.misc-pub-follower-count span {
font-weight: bold;
}
48 changes: 47 additions & 1 deletion modules/notifications/lib/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jQuery(document).ready(function($) {
post_id: $('#post_ID').val(),
};

// Display the user/group follower count in the post submit box
ef_displayFollowerCountInSubmitBox();

$('.ef-post_following_list li input:checkbox, .ef-following_usergroups li input:checkbox').click(function() {
var user_group_ids = [];
var parent_this = $(this);
Expand All @@ -28,6 +31,8 @@ jQuery(document).ready(function($) {
url : (ajaxurl) ? ajaxurl : wpListL10n.url,
data : params,
success : function(x) {
// Update the user/group follower count in the post submit box
ef_displayFollowerCountInSubmitBox();
var backgroundColor = parent_this.css( 'background-color' );
$(parent_this.parent().parent())
.animate( { 'backgroundColor':'#CCEEBB' }, 200 )
Expand All @@ -38,4 +43,45 @@ jQuery(document).ready(function($) {
}
});
});
});
});

/**
* Count the users and user groups who will be notified of a status change
* Display the message in the submit box
*/
var ef_displayFollowerCountInSubmitBox = function() {
var checkedFollowers, checkedUserGroups, countDisplay, message = '', followerMessage = '', userGroupMessage = '',conjunction = '';

// Get checked checkboxes
checkedFollowers = jQuery('.ef-post_following_list li input:checkbox:checked');
checkedUserGroups = jQuery('#ef-following_usergroups li input:checkbox:checked');
// checkedFollowers includes user groups
userCount = checkedFollowers.length - checkedUserGroups.length;
userGroupCount = checkedUserGroups.length;

// The <span> within which the message will be displayed
countDisplay = jQuery('#post-follower-count-display');

// Create the individual messages
if (userCount > 0) {
followerMessage = userCount + ((userCount === 1) ? ' user' : ' users');
}
if (userGroupCount > 0) {
userGroupMessage = userGroupCount + ((userGroupCount === 1) ? ' user group' : ' user groups');
}

if (userCount > 0 && userGroupCount > 0) {
// Both will be displayed, so we need a conjunction
conjunction = ' & ';
message = (followerMessage + conjunction + userGroupMessage);
} else if (userCount > 0 || userGroupCount > 0) {
// Only one will be displayed, the other is an empty string
message = (followerMessage + userGroupMessage);
} else {
// Default message
message = 'none';
}

// Print the message
countDisplay.html(message);
};
15 changes: 15 additions & 0 deletions modules/notifications/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ 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( 'post_submitbox_misc_actions', array($this, 'submitbox_followers_message') );

add_action( 'admin_init', array( $this, 'register_settings' ) );

Expand Down Expand Up @@ -410,6 +411,20 @@ public function handle_user_post_subscription() {
$this->print_ajax_response( 'success', (object)$this->get_follow_action_parts( $post ) );
}

/**
* Set up the submit box for displaying the number of users/user groups following a page/post
*/
function submitbox_followers_message() {
?>
<hr>
<div class="misc-pub-section misc-pub-follower-count" id="follower-count"><?php _e('Followers', 'edit-flow'); ?>: <span id="post-follower-count-display"></span>
<a href="#edit-flow-notifications">
<span aria-hidden="true"><?php _e('Edit', 'edit-flow'); ?></span>
<span class="screen-reader-text"><?php _e('Edit followers', 'edit-flow'); ?></span>
</a>
</div>
<?php
}

/**
* Called when post is saved. Handles saving of user/usergroup followers
Expand Down