Changeset 1843103
- Timestamp:
- 03/19/2018 09:48:46 PM (8 years ago)
- Location:
- publishpress/trunk
- Files:
-
- 9 added
- 7 edited
-
composer.json (modified) (1 diff)
-
includes.php (modified) (1 diff)
-
modules/async-notifications/library/Queue/WPCron.php (modified) (1 diff)
-
modules/notifications/notifications.php (modified) (51 diffs)
-
modules/roles (added)
-
modules/roles/assets (added)
-
modules/roles/assets/css (added)
-
modules/roles/assets/css/admin.css (added)
-
modules/roles/lib (added)
-
modules/roles/lib/list_table.php (added)
-
modules/roles/roles.php (added)
-
modules/roles/twig (added)
-
modules/roles/twig/settings-tab-roles.twig.html (added)
-
modules/user-groups/user-groups.php (modified) (6 diffs)
-
publishpress.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
publishpress/trunk/composer.json
r1839780 r1843103 13 13 "repositories": [ 14 14 { 15 "type": " vcs",15 "type": "git", 16 16 "url": "https://github.com/OSTraining/WordPress-Plugin-Builder" 17 17 } -
publishpress/trunk/includes.php
r1839780 r1843103 42 42 43 43 // Define contants 44 define('PUBLISHPRESS_VERSION', '1.1 0.0');44 define('PUBLISHPRESS_VERSION', '1.11.2'); 45 45 define('PUBLISHPRESS_ROOT', dirname(__FILE__)); 46 46 define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_ROOT . '/' . basename(__FILE__)); -
publishpress/trunk/modules/async-notifications/library/Queue/WPCron.php
r1839780 r1843103 84 84 { 85 85 wp_schedule_single_event( 86 time() ,86 time() + 4, 87 87 'publishpress_cron_notify', 88 88 $data -
publishpress/trunk/modules/notifications/notifications.php
r1839780 r1843103 43 43 { 44 44 45 // Taxonomy name used to store users following posts46 public $ following_users_taxonomy = 'following_users';47 48 // Taxonomy name used to store user groups following posts49 public $ following_usergroups_taxonomy = PP_User_Groups::taxonomy_key;45 // Taxonomy name used to store users which will be notified for changes in the posts. 46 public $notify_user_taxonomy = 'pp_notify_user'; 47 48 // Taxonomy name used to store roles which will be notified for changes in the posts. 49 public $notify_role_taxonomy = 'pp_notify_role'; 50 50 51 51 public $module; … … 64 64 'title' => __('Default Notifications', 'publishpress'), 65 65 'short_description' => __('With notifications, you can keep everyone updated about what’s happening with your content.', 'publishpress'), 66 'extended_description' => __('With notifications, you can keep everyone updated about what’s happening with a given content. Each status change or editorial comment sends out a message to users subscribed to a post. User groups can be used to manage who receives notifications on what.', 'publishpress'),66 'extended_description' => __('With notifications, you can keep everyone updated about what’s happening with a given content. Each status change or editorial comment sends out a message to users subscribed to a post. Roles can be used to manage who receives notifications on what.', 'publishpress'), 67 67 'module_url' => $this->module_url, 68 68 'icon_class' => 'dashicons dashicons-email', … … 83 83 'id' => 'pp-notifications-overview', 84 84 'title' => __('Overview', 'publishpress'), 85 'content' => __('<p>Notifications ensure you keep up to date with progress your most important content. Users can be subscribed to notifications on a post one by one or by selecting user groups.</p><p>When enabled, notifications can be sent when a post changes status or an editorial comment is left by a writer or an editor.</p>', 'publishpress'),85 'content' => __('<p>Notifications ensure you keep up to date with progress your most important content. Users can be subscribed to notifications on a post one by one or by selecting roles.</p><p>When enabled, notifications can be sent when a post changes status or an editorial comment is left by a writer or an editor.</p>', 'publishpress'), 86 86 ), 87 87 'settings_help_sidebar' => __('<p><strong>For more information:</strong></p><p><a href="https://publishpress.com/features/notifications/">Notifications Documentation</a></p><p><a href="https://github.com/ostraining/PublishPress">PublishPress on Github</a></p>', 'publishpress'), … … 107 107 108 108 // Saving post actions 109 // self::save_post_subscriptions() is hooked into transition_post_status so we can ensure usergroupdata109 // self::save_post_subscriptions() is hooked into transition_post_status so we can ensure role data 110 110 // is properly saved before sending notifs 111 add_action('transition_post_status', array($this, 'save_post_subscriptions'), 0, 3);112 111 add_action('transition_post_status', array($this, 'notification_status_change'), PP_NOTIFICATION_PRIORITY_STATUS_CHANGE, 3); 113 112 add_action('pp_post_insert_editorial_comment', array($this, 'notification_comment')); … … 121 120 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles')); 122 121 123 // Add a " Follow" link to posts124 if (apply_filters('pp_notifications_show_ follow_link', true))125 { 126 // A little extra JS for the followbutton127 add_action('admin_head', array($this, 'action_admin_head_ follow_js'));122 // Add a "Notify" link to posts 123 if (apply_filters('pp_notifications_show_notify_link', true)) 124 { 125 // A little extra JS for the Notify button 126 add_action('admin_head', array($this, 'action_admin_head_notify_js')); 128 127 // Manage Posts 129 128 add_filter('post_row_actions', array($this, 'filter_post_row_actions'), 10, 2); … … 137 136 add_filter('pp_notification_auto_subscribe_current_user', array($this, 'filter_pp_notification_auto_subscribe_current_user'), 10, 2); 138 137 138 add_action('save_post', array($this, 'action_save_post'), 10); 139 139 140 // Ajax for saving notification updates 140 add_action('wp_ajax_save_notifications', array($this, 'ajax_save_post_subscriptions'));141 141 add_action('wp_ajax_pp_notifications_user_post_subscription', array($this, 'handle_user_post_subscription')); 142 142 … … 152 152 public function install() 153 153 { 154 154 // Considering we could be moving from Edit Flow, we need to migrate the following users. 155 $this->migrateLegacyFollowingTerms(); 155 156 } 156 157 … … 192 193 $publishpress->update_module_option($this->module->name, 'loaded_once', true); 193 194 } 195 196 if (version_compare($previous_version, '1.10', '<=')) { 197 $this->migrateLegacyFollowingTerms(); 198 } 199 } 200 201 202 protected function migrateLegacyFollowingTerms() 203 { 204 global $wpdb; 205 206 // Migrate Following Users 207 $query = "UPDATE {$wpdb->prefix}term_taxonomy SET taxonomy = '{$this->notify_user_taxonomy}' WHERE taxonomy = 'following_users'"; 208 $wpdb->query($query); 194 209 } 195 210 … … 216 231 ); 217 232 218 register_taxonomy($this->following_users_taxonomy, $supported_post_types, $args); 233 register_taxonomy($this->notify_user_taxonomy, $supported_post_types, $args); 234 register_taxonomy($this->notify_role_taxonomy, $supported_post_types, $args); 219 235 } 220 236 … … 230 246 if ($this->is_whitelisted_functional_view()) 231 247 { 232 wp_enqueue_script('jquery-listfilterizer');233 wp_enqueue_script('jquery-quicksearch');234 248 wp_enqueue_script( 235 249 'publishpress-notifications-js', … … 237 251 array( 238 252 'jquery', 239 'jquery-listfilterizer',240 'jquery-quicksearch',241 253 ), 242 254 PUBLISHPRESS_VERSION, 243 255 true 244 256 ); 257 258 wp_enqueue_script('publishpress-chosen-js', PUBLISHPRESS_URL . '/common/libs/chosen/chosen.jquery.js', 259 ['jquery'], PUBLISHPRESS_VERSION); 245 260 } 246 261 } … … 264 279 PUBLISHPRESS_VERSION 265 280 ); 266 } 267 } 268 269 /** 270 * JS required for the Follow link to work 281 282 wp_enqueue_style('publishpress-chosen-css', PUBLISHPRESS_URL . '/common/libs/chosen/chosen.css', false, 283 PUBLISHPRESS_VERSION); 284 } 285 } 286 287 /** 288 * JS required for the Notify link to work 271 289 * 272 290 * @since 0.8 273 291 */ 274 public function action_admin_head_ follow_js()292 public function action_admin_head_notify_js() 275 293 { 276 294 ?> … … 279 297 $(document).ready(function ($) { 280 298 /** 281 * Action to Follow / Unfollowposts on the manage posts screen299 * Action to Notify / Stop Notifying posts on the manage posts screen 282 300 */ 283 $('.wp-list-table, #pp-calendar-view, #pp-story-budget-wrap').on('click', '.pp_ follow_link a', function (e) {301 $('.wp-list-table, #pp-calendar-view, #pp-story-budget-wrap').on('click', '.pp_notify_link a', function (e) { 284 302 285 303 e.preventDefault(); … … 309 327 310 328 /** 311 * Add a " Follow" link to supported post types Manage Posts view329 * Add a "Notify" link to supported post types Manage Posts view 312 330 * 313 331 * @since 0.8 … … 331 349 } 332 350 333 $parts = $this->get_ follow_action_parts($post);334 $actions['pp_ follow_link'] = '<a title="' . esc_attr($parts['title']) . '" href="' . esc_url($parts['link']) . '">' . $parts['text'] . '</a>';351 $parts = $this->get_notify_action_parts($post); 352 $actions['pp_notify_link'] = '<a title="' . esc_attr($parts['title']) . '" href="' . esc_url($parts['link']) . '">' . $parts['text'] . '</a>'; 335 353 336 354 return $actions; … … 338 356 339 357 /** 340 * Get an action parts for a user to follow or unfollowa post358 * Get an action parts for a user to set Notify or Stop Notify for a post 341 359 * 342 360 * @since 0.8 343 361 */ 344 private function get_ follow_action_parts($post)362 private function get_notify_action_parts($post) 345 363 { 346 364 $args = array( … … 349 367 ); 350 368 351 $ following_users = $this->get_following_users($post->ID);352 353 if (in_array(wp_get_current_user()->user_login, $ following_users))354 { 355 $args['method'] = ' unfollow';369 $user_to_notify = $this->get_users_to_notify($post->ID); 370 371 if (in_array(wp_get_current_user()->user_login, $user_to_notify)) 372 { 373 $args['method'] = 'stop_notifying'; 356 374 $title_text = __('Click to stop being notified on updates for this post', 'publishpress'); 357 $ follow_text= __('Stop notifying me', 'publishpress');375 $link_text = __('Stop notifying me', 'publishpress'); 358 376 } else 359 377 { 360 $args['method'] = ' follow';378 $args['method'] = 'start_notifying'; 361 379 $title_text = __('Click to start being notified on updates for this post', 'publishpress'); 362 $ follow_text= __('Notify me', 'publishpress');380 $link_text = __('Notify me', 'publishpress'); 363 381 } 364 382 … … 368 386 return array( 369 387 'title' => $title_text, 370 'text' => $ follow_text,388 'text' => $link_text, 371 389 'link' => add_query_arg($args, admin_url('admin-ajax.php')), 372 390 ); … … 383 401 } 384 402 385 $ usergroup_post_types = $this->get_post_types_for_module($this->module);386 foreach ($ usergroup_post_types as $post_type)403 $role_post_types = $this->get_post_types_for_module($this->module); 404 foreach ($role_post_types as $post_type) 387 405 { 388 406 add_meta_box( … … 391 409 array($this, 'notifications_meta_box'), 392 410 $post_type, 393 'advanced' 411 'side', 412 'high' 394 413 ); 395 414 } … … 397 416 398 417 /** 399 * Outputs box used to subscribe users and usergroups to Posts418 * Outputs box used to subscribe users and roles to Posts 400 419 * 401 420 * @todo add_cap to set subscribers for posts; default to Admin and editors … … 406 425 407 426 ?> 408 <div id="pp -post_following_box">427 <div id="pp_post_notify_box"> 409 428 <a name="subscriptions"></a> 410 429 411 <p><?php _e('Select the users and user groups that should receive notifications when the status of this post is updated or when an editorial comment is added.', 'publishpress'); ?> 430 <p> 431 <?php _e('Select the users and roles that should receive notifications from workflows.', 'publishpress'); ?> 412 432 </p> 413 <div id="pp-post_following_users_box"> 414 <h4><?php _e('Users', 'publishpress'); ?></h4>433 434 <div id="pp_post_notify_users_box"> 415 435 <?php 416 $followers = $this->get_following_users($post->ID, 'id'); 436 $users_to_notify = $this->get_users_to_notify($post->ID, 'id'); 437 $roles_to_notify = $this->get_roles_to_notify($post->ID, 'slugs'); 438 439 $selected = array_merge($users_to_notify, $roles_to_notify); 440 417 441 $select_form_args = array( 418 'list_class' => 'pp -post_following_list',442 'list_class' => 'pp_post_notify_list', 419 443 ); 420 $this->users_select_form($ followers, $select_form_args);444 $this->users_select_form($selected , $select_form_args); 421 445 ?> 446 447 422 448 </div> 423 449 424 <?php if ($this->module_enabled('user_groups') && in_array($this->get_current_post_type(), $this->get_post_types_for_module($publishpress->user_groups->module))): ?> 425 <div id="pp-post_following_usergroups_box"> 426 <h4><?php _e('User Groups', 'publishpress') ?></h4> 427 <?php 428 $following_usergroups = $this->get_following_usergroups($post->ID, 'ids'); 429 $publishpress->user_groups->usergroups_select_form($following_usergroups); 430 ?> 431 </div> 432 <?php endif; ?> 450 <p> 451 <a href="https://publishpress.com/docs/notifications/"><?php _e('Click to read more about notifications', 'publishpress'); ?></a> 452 </p> 433 453 434 454 <div class="clear"></div> 435 455 436 <input type="hidden" name="pp -save_followers" value="1"/> <?php // Extra protection against autosaves456 <input type="hidden" name="pp_save_notify" value="1"/> <?php // Extra protection against autosaves 437 457 ?> 438 458 439 <?php wp_nonce_field('save_ user_usergroups', 'pp_notifications_nonce', false); ?>459 <?php wp_nonce_field('save_roles', 'pp_notifications_nonce', false); ?> 440 460 </div> 441 461 … … 443 463 } 444 464 445 /** 446 * Called when a notification editorial metadata checkbox is checked. Handles saving of a user/usergroup to a post. 447 */ 448 public function ajax_save_post_subscriptions() 449 { 450 global $publishpress; 451 452 // Verify nonce 453 if (!wp_verify_nonce($_POST['_nonce'], 'save_user_usergroups')) 454 { 455 die(__("Nonce check failed. Please ensure you can add users or user groups to a post.", 'publishpress')); 456 } 457 458 $post_id = (int )$_POST['post_id']; 459 $post = get_post($post_id); 460 $user_usergroup_ids = array_map('intval', $_POST['user_group_ids']); 461 if ((!wp_is_post_revision($post_id) && !wp_is_post_autosave($post_id)) && current_user_can($this->edit_post_subscriptions_cap)) 462 { 463 if ($_POST['pp_notifications_name'] === 'pp-selected-users[]') 464 { 465 $this->save_post_following_users($post, $user_usergroup_ids); 466 } else if ($_POST['pp_notifications_name'] == 'following_usergroups[]') 467 { 468 if ($this->module_enabled('user_groups') && in_array(get_post_type($post_id), $this->get_post_types_for_module($publishpress->user_groups->module))) 469 { 470 $this->save_post_following_usergroups($post, $user_usergroup_ids); 465 public function action_save_post($postId) 466 { 467 if (!isset($_POST['pp_notifications_nonce']) || !wp_verify_nonce($_POST['pp_notifications_nonce'], 'save_roles')) { 468 return; 469 } 470 471 if (isset($_POST['to_notify'])) { 472 // Remove current users 473 $terms = get_the_terms($postId, $this->notify_user_taxonomy); 474 $users = array(); 475 if (!empty($terms)) { 476 foreach ($terms as $term) { 477 $users[] = $term->term_id; 471 478 } 472 479 } 473 } 474 die(); 480 wp_remove_object_terms($postId, $users, $this->notify_user_taxonomy); 481 482 // Remove current roles 483 $terms = get_the_terms($postId, $this->notify_role_taxonomy); 484 $roles = array(); 485 if (!empty($terms)) { 486 foreach ($terms as $term) { 487 $roles[] = $term->term_id; 488 } 489 } 490 wp_remove_object_terms($postId, $roles, $this->notify_role_taxonomy); 491 492 foreach ($_POST['to_notify'] as $id) { 493 if (is_numeric($id)) { 494 // User id 495 $this->post_set_users_to_notify($postId, (int)$id, true); 496 } else { 497 // Role name 498 $this->post_set_roles_to_notify($postId, $id, true); 499 } 500 } 501 } 475 502 } 476 503 … … 499 526 } 500 527 501 if (' follow'== $_GET['method'])502 { 503 $retval = $this-> follow_post_user($post, get_current_user_id());528 if ('start_notifying' === $_GET['method']) 529 { 530 $retval = $this->post_set_users_to_notify($post, get_current_user_id()); 504 531 } else 505 532 { 506 $retval = $this-> unfollow_post_user($post, get_current_user_id());533 $retval = $this->post_set_users_stop_notify($post, get_current_user_id()); 507 534 } 508 535 … … 512 539 } 513 540 514 $this->print_ajax_response('success', (object )$this->get_ follow_action_parts($post));541 $this->print_ajax_response('success', (object )$this->get_notify_action_parts($post)); 515 542 } 516 543 … … 545 572 } 546 573 547 548 /** 549 * Called when post is saved. Handles saving of user/usergroup followers 574 /** 575 * Sets users to be notified for the specified post 550 576 * 551 577 * @param int $post ID of the post 552 578 */ 553 public function save_post_subscriptions($new_status, $old_status, $post) 554 { 555 global $publishpress; 556 // only if has edit_post_subscriptions cap 557 if ((!wp_is_post_revision($post) && !wp_is_post_autosave($post)) && isset($_POST['pp-save_followers']) && current_user_can($this->edit_post_subscriptions_cap)) 558 { 559 $users = isset($_POST['pp-selected-users']) ? $_POST['pp-selected-users'] : array(); 560 $usergroups = isset($_POST['following_usergroups']) ? $_POST['following_usergroups'] : array(); 561 $this->save_post_following_users($post, $users); 562 if ($this->module_enabled('user_groups') && in_array($this->get_current_post_type(), $this->get_post_types_for_module($publishpress->user_groups->module))) 563 { 564 $this->save_post_following_usergroups($post, $usergroups); 565 } 566 } 567 } 568 569 /** 570 * Sets users to follow specified post 571 * 572 * @param int $post ID of the post 573 */ 574 public function save_post_following_users($post, $users = null) 579 public function save_post_notify_users($post, $users = null) 575 580 { 576 581 if (!is_array($users)) … … 579 584 } 580 585 581 // Add current user to following users586 // Add current user to notify list 582 587 $user = wp_get_current_user(); 583 588 if ($user && apply_filters('pp_notification_auto_subscribe_current_user', true, 'subscription_action')) … … 586 591 } 587 592 588 // Add post author to following users593 // Add post author to notify list 589 594 if (apply_filters('pp_notification_auto_subscribe_post_author', true, 'subscription_action')) 590 595 { … … 594 599 $users = array_unique(array_map('intval', $users)); 595 600 596 $ follow = $this->follow_post_user($post, $users, false);597 } 598 599 /** 600 * Sets usergroups to followspecified post601 $this->post_set_users_to_notify($post, $users, false); 602 } 603 604 /** 605 * Sets roles to be notified for the specified post 601 606 * 602 607 * @param int $post ID of the post 603 * @param array $ usergroups Usergroups to followposts604 */ 605 public function save_post_ following_usergroups($post, $usergroups = null)606 { 607 if (!is_array($ usergroups))608 { 609 $ usergroups = array();610 } 611 $ usergroups = array_map('intval', $usergroups);612 613 $ follow = $this->follow_post_usergroups($post, $usergroups, false);608 * @param array $roles Roles to be notified for posts 609 */ 610 public function save_post_notify_roles($post, $roles = null) 611 { 612 if (!is_array($roles)) 613 { 614 $roles = array(); 615 } 616 $roles = array_map('intval', $roles); 617 618 $this->add_role_to_notify($post, $roles, false); 614 619 } 615 620 … … 620 625 { 621 626 global $publishpress; 627 622 628 623 629 // Kill switch for notification … … 678 684 //if( $parent_ID ) $parent = get_comment( $parent_ID ); 679 685 680 // Set user to followpost, but make it filterable686 // Set user to be notified for a post, but make it filterable 681 687 if (apply_filters('pp_notification_auto_subscribe_current_user', true, 'comment')) 682 688 { 683 $this-> follow_post_user($post, (int )$current_user->ID);684 } 685 686 // Set the post author to followthe post but make it filterable689 $this->post_set_users_to_notify($post, (int )$current_user->ID); 690 } 691 692 // Set the post author to be notified for the post but make it filterable 687 693 if (apply_filters('pp_notification_auto_subscribe_post_author', true, 'comment')) 688 694 { 689 $this-> follow_post_user($post, (int )$post->post_author);695 $this->post_set_users_to_notify($post, (int )$post->post_author); 690 696 } 691 697 … … 807 813 $recipients = array(); 808 814 809 $usergroup_users = array(); 810 if ($this->module_enabled('user_groups')) 811 { 812 // Get following users and usergroups 813 $usergroups = $this->get_following_usergroups($post_id, 'ids'); 814 foreach ((array )$usergroups as $usergroup_id) 815 { 816 $usergroup = $publishpress->user_groups->get_usergroup_by('id', $usergroup_id); 817 foreach ((array )$usergroup->user_ids as $user_id) 815 $role_users = array(); 816 817 // Get users and roles to notify 818 $roles = $this->get_roles_to_notify($post_id, 'slugs'); 819 foreach ((array )$roles as $role_id) 820 { 821 $users = get_users( 822 [ 823 'role' => $role_id, 824 ] 825 ); 826 827 if (!empty($users)) { 828 foreach ($users as $user) 818 829 { 819 $usergroup_user = get_user_by('id', $user_id); 820 if ($usergroup_user && is_user_member_of_blog($user_id)) 830 if (is_user_member_of_blog($user->ID)) 821 831 { 822 $ usergroup_users[] = $usergroup_user->user_email;832 $role_users[] = $user->user_email; 823 833 } 824 834 } … … 826 836 } 827 837 828 $users = $this->get_ following_users($post_id, 'user_email');838 $users = $this->get_users_to_notify($post_id, 'user_email'); 829 839 830 840 // Merge arrays and filter any duplicates 831 $recipients = array_merge($authors, $admins, $users, $ usergroup_users);841 $recipients = array_merge($authors, $admins, $users, $role_users); 832 842 $recipients = array_unique($recipients); 833 843 … … 841 851 } 842 852 // Don't send the email to the current user unless we've explicitly indicated they should receive it 843 if (false === apply_filters('p p_notification_email_current_user', false) && wp_get_current_user()->user_email == $user_email)853 if (false === apply_filters('publishpress_notify_current_user', false) && wp_get_current_user()->user_email == $user_email) 844 854 { 845 855 unset($recipients[$key]); … … 861 871 862 872 /** 863 * Set a user or users to followa post873 * Set a user or users to be notified for a post 864 874 * 865 875 * @param int|object $post Post object or ID 866 876 * @param string|array $users User or users to subscribe to post updates 867 * @param bool $append Whether users should be added to following_userslist or replace existing list877 * @param bool $append Whether users should be added to pp_notify_user list or replace existing list 868 878 * 869 879 * @return true|WP_Error $response True on success, WP_Error on failure 870 880 */ 871 public function follow_post_user($post, $users, $append = true)881 public function post_set_users_to_notify($post, $users, $append = true) 872 882 { 873 883 $post = get_post($post); … … 883 893 884 894 $user_terms = array(); 895 885 896 foreach ($users as $user) 886 897 { … … 901 912 902 913 // Add user as a term if they don't exist 903 $term = $this->add_term_if_not_exists($name, $this-> following_users_taxonomy);914 $term = $this->add_term_if_not_exists($name, $this->notify_user_taxonomy); 904 915 905 916 if (!is_wp_error($term)) … … 908 919 } 909 920 } 910 $set = wp_set_object_terms($post->ID, $user_terms, $this->following_users_taxonomy, $append); 921 922 $set = wp_set_object_terms($post->ID, $user_terms, $this->notify_user_taxonomy, $append); 911 923 912 924 if (is_wp_error($set)) … … 920 932 921 933 /** 922 * Removes user from following_users taxonomy for the given Post, 923 * so they no longer receive future notifications. 924 * 925 * @param object $post Post object or ID 926 * @param int|string|array $users One or more users to unfollow from the post 934 * Set a role or roles to be notified for a post 935 * 936 * @param int|object $post Post object or ID 937 * @param string|array $roles Role or roles to subscribe to post updates 938 * @param bool $append Whether roles should be added to pp_notify_role list or replace existing list 939 * 927 940 * @return true|WP_Error $response True on success, WP_Error on failure 928 941 */ 929 public function unfollow_post_user($post, $users)942 public function post_set_roles_to_notify($post, $roles, $append = true) 930 943 { 931 944 $post = get_post($post); … … 935 948 } 936 949 950 if (!is_array($roles)) 951 { 952 $roles = array($roles); 953 } 954 955 $role_terms = array(); 956 957 foreach ($roles as $role) 958 { 959 $role = get_role($role); 960 961 if (!is_object($role)) 962 { 963 continue; 964 } 965 966 // Add user as a term if they don't exist 967 $term = $this->add_term_if_not_exists($role->name, $this->notify_role_taxonomy); 968 969 if (!is_wp_error($term)) 970 { 971 $role_terms[] = $role->name; 972 } 973 } 974 975 $set = wp_set_object_terms($post->ID, $role_terms, $this->notify_role_taxonomy, $append); 976 977 if (is_wp_error($set)) 978 { 979 return $set; 980 } else 981 { 982 return true; 983 } 984 } 985 986 /** 987 * Removes user from pp_notify_user taxonomy for the given Post, 988 * so they no longer receive future notifications. 989 * 990 * @param object $post Post object or ID 991 * @param int|string|array $users One or more users to stop being notified for the post 992 * @return true|WP_Error $response True on success, WP_Error on failure 993 */ 994 public function post_set_users_stop_notify($post, $users) 995 { 996 $post = get_post($post); 997 if (!$post) 998 { 999 return new WP_Error('missing-post', $this->module->messages['missing-post']); 1000 } 1001 937 1002 if (!is_array($users)) 938 1003 { … … 940 1005 } 941 1006 942 $terms = get_the_terms($post->ID, $this-> following_users_taxonomy);1007 $terms = get_the_terms($post->ID, $this->notify_user_taxonomy); 943 1008 if (is_wp_error($terms)) 944 1009 { … … 968 1033 } 969 1034 } 970 $set = wp_set_object_terms($post->ID, $user_terms, $this-> following_users_taxonomy, false);1035 $set = wp_set_object_terms($post->ID, $user_terms, $this->notify_user_taxonomy, false); 971 1036 972 1037 if (is_wp_error($set)) … … 980 1045 981 1046 /** 982 * follow_post_usergroups() 983 * 984 */ 985 public function follow_post_usergroups($post, $usergroups = 0, $append = true) 986 { 987 if (!$this->module_enabled('user_groups')) 988 { 989 return; 990 } 991 1047 * add_role_to_notify() 1048 * 1049 */ 1050 public function add_role_to_notify($post, $roles = 0, $append = true) 1051 { 992 1052 $post_id = (is_int($post)) ? $post : $post->ID; 993 if (!is_array($ usergroups))994 { 995 $ usergroups = array($usergroups);996 } 997 998 // make sure each usergroupid is an integer and not a number stored as a string999 foreach ($ usergroups as $key => $usergroup)1000 { 1001 $ usergroups[$key] = intval($usergroup);1002 } 1003 1004 wp_set_object_terms($post_id, $ usergroups, $this->following_usergroups_taxonomy, $append);1053 if (!is_array($roles)) 1054 { 1055 $roles = array($roles); 1056 } 1057 1058 // make sure each role id is an integer and not a number stored as a string 1059 foreach ($roles as $key => $role) 1060 { 1061 $roles[$key] = intval($role); 1062 } 1063 1064 wp_set_object_terms($post_id, $roles, $this->notify_role_taxonomy, $append); 1005 1065 1006 1066 return; … … 1008 1068 1009 1069 /** 1010 * Removes users that are deleted from receiving future notifications (i.e. makes them unfollowposts FOREVER! )1070 * Removes users that are deleted from receiving future notifications (i.e. makes them out of notify list for posts FOREVER! ) 1011 1071 * 1012 1072 * @param $id int ID of the user … … 1024 1084 if ($user) 1025 1085 { 1026 // Delete term from the following_userstaxonomy1027 $ user_following_term = get_term_by('name', $user->user_login, $this->following_users_taxonomy);1028 if ($ user_following_term)1029 { 1030 wp_delete_term($ user_following_term->term_id, $this->following_users_taxonomy);1086 // Delete term from the pp_notify_user taxonomy 1087 $notify_user_term = get_term_by('name', $user->user_login, $this->notify_user_taxonomy); 1088 if ($notify_user_term) 1089 { 1090 wp_delete_term($notify_user_term->term_id, $this->notify_user_taxonomy); 1031 1091 } 1032 1092 } … … 1055 1115 1056 1116 /** 1057 * Gets a list of the users followingthe specified post1117 * Gets a list of the users to be notified for the specified post 1058 1118 * 1059 1119 * @param int $post_id The ID of the post 1060 1120 * @param string $return The field to return 1061 * @return array $users Users following the specified posts 1062 */ 1063 public function get_following_users($post_id, $return = 'user_login') 1064 { 1065 1066 // Get following_users terms for the post 1067 $users = wp_get_object_terms($post_id, $this->following_users_taxonomy, array('fields' => 'names')); 1068 1069 // Don't have any following users 1121 * @return array $users Users to notify for the specified posts 1122 */ 1123 public function get_users_to_notify($post_id, $return = 'user_login') 1124 { 1125 // Get pp_notify_user terms for the post 1126 $users = wp_get_object_terms($post_id, $this->notify_user_taxonomy, array('fields' => 'names')); 1127 1128 // Don't have any users to notify 1070 1129 if (!$users || is_wp_error($users)) 1071 1130 { … … 1124 1183 1125 1184 /** 1126 * Gets a list of the usergroups that are followingspecified post1185 * Gets a list of the roles that should be notified for the specified post 1127 1186 * 1128 1187 * @param int $post_id 1129 * @return array $ usergroups All of the usergroupslugs1130 */ 1131 public function get_ following_usergroups($post_id, $return = 'all')1188 * @return array $roles All of the role slugs 1189 */ 1190 public function get_roles_to_notify($post_id, $return = 'all') 1132 1191 { 1133 1192 global $publishpress; … … 1142 1201 } 1143 1202 1144 $ usergroups = wp_get_object_terms($post_id, $this->following_usergroups_taxonomy, array('fields' => $fields));1203 $roles = wp_get_object_terms($post_id, $this->notify_role_taxonomy, array('fields' => $fields)); 1145 1204 1146 1205 if ($return == 'slugs') 1147 1206 { 1148 1207 $slugs = array(); 1149 foreach ($ usergroups as $usergroup)1150 { 1151 $slugs[] = $ usergroup->slug;1152 } 1153 $ usergroups = $slugs;1154 } 1155 1156 return $ usergroups;1157 } 1158 1159 /** 1160 * Gets a list of posts that a user is following1208 foreach ($roles as $role) 1209 { 1210 $slugs[] = $role->slug; 1211 } 1212 $roles = $slugs; 1213 } 1214 1215 return $roles; 1216 } 1217 1218 /** 1219 * Gets a list of posts that a user is selected to be notified 1161 1220 * 1162 1221 * @param string|int $user user_login or id of user 1163 1222 * @param array $args 1164 * @return array $posts Posts a user is following1165 */ 1166 public function get_user_ following_posts($user = 0, $args = null)1223 * @return array $posts Posts a user is selected to be notified 1224 */ 1225 public function get_user_to_notify_posts($user = 0, $args = null) 1167 1226 { 1168 1227 if (!$user) … … 1179 1238 'tax_query' => array( 1180 1239 array( 1181 'taxonomy' => $this-> following_users_taxonomy,1240 'taxonomy' => $this->notify_user_taxonomy, 1182 1241 'field' => 'slug', 1183 1242 'terms' => $user, … … 1189 1248 'post_status' => 'any', 1190 1249 ); 1191 $post_args = apply_filters('pp_user_ following_posts_query_args', $post_args);1250 $post_args = apply_filters('pp_user_to_notify_posts_query_args', $post_args); 1192 1251 $posts = get_posts($post_args); 1193 1252 … … 1528 1587 public function send_notification_comment($args) 1529 1588 { 1530 1531 1532 1589 /* translators: 1: blog name, 2: post title */ 1533 1590 $subject = sprintf(__('[%1$s] New Editorial Comment: "%2$s"', 'publishpress'), $args['blogname'], $args['post_title']); -
publishpress/trunk/modules/user-groups/user-groups.php
r1839780 r1843103 32 32 * class PP_User_Groups 33 33 * 34 * @todo all of them PHPdocs 35 * @todo Resolve whether the notifications component of this class should be moved to "subscriptions" 36 * @todo Decide whether it's functional to store user_ids in the term description array 37 * - Argument against: it's going to be expensive to look up usergroups for a user 38 * 34 * @todo Remove this module. It is deprecated. 39 35 */ 40 36 41 37 if (!class_exists('PP_User_Groups')) 42 38 { 39 /** 40 * Class PP_User_Groups 41 * 42 * @deprecated 43 */ 43 44 class PP_User_Groups extends PP_Module 44 45 { … … 97 98 ), 98 99 'settings_help_sidebar' => __('<p><strong>For more information:</strong></p><p><a href="https://publishpress.com/features/user-groups/">User Groups Documentation</a></p><p><a href="https://github.com/ostraining/PublishPress">PublishPress on Github</a></p>', 'publishpress'), 99 'options_page' => true,100 // 'options_page' => true, 100 101 ); 101 102 $this->module = PublishPress()->register_module('user_groups', $args); … … 593 594 <?php 594 595 $select_form_args = array( 595 'list_class' => 'pp -post_following_list',596 'list_class' => 'pp_post_notify_list', 596 597 'input_id' => 'usergroup_users', 597 598 ); … … 882 883 // before <tag>, after <tag>, class, id names? 883 884 $defaults = array( 884 'list_class' => 'pp -post_following_list',885 'list_class' => 'pp_post_notify_list', 885 886 'list_id' => 'pp-following_usergroups', 886 887 'input_id' => 'following_usergroups', … … 948 949 public function get_usergroups($args = array()) 949 950 { 950 951 951 // We want empty terms by default 952 952 if (!isset($args['hide_empty'])) … … 1259 1259 foreach ($all_usergroups as $usergroup) 1260 1260 { 1261 // Not in this usergroup, so keep going 1261 // Not in this user group, so keep going 1262 if (!isset($usergroup->user_ids) || false == ($usergroup->user_ids || !is_array($usergroup->user_ids))) { 1263 continue; 1264 } 1265 1262 1266 if (!in_array($user_id, $usergroup->user_ids)) 1263 1267 { -
publishpress/trunk/publishpress.php
r1839780 r1843103 6 6 * Author: PublishPress 7 7 * Author URI: https://publishpress.com 8 * Version: 1.1 0.08 * Version: 1.11.2 9 9 * Text Domain: publishpress 10 10 * Domain Path: /languages -
publishpress/trunk/readme.txt
r1839788 r1843103 7 7 Requires PHP: 5.4 8 8 Tested up to: 4.9.4 9 Stable tag: 1.1 0.09 Stable tag: 1.11.2 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 87 87 * [Click here for more on PublishPress Editorial Metadata](https://publishpress.com/docs/editorial-metadata/) 88 88 89 = USER GROUPS =90 91 For larger organizations with many people involved in the publishing process, user groups help keep your workflow organized and informed.92 93 To find the user settings, go to the PublishPress link in your WordPress admin area, and click the “User Groups” tab. By default, PublishPress provides four user groups: Copy Editors, Photographers, Reporters and Section Editors.94 95 * [Click here for more on PublishPress User Groups](https://publishpress.com/docs/user-groups/)89 = CUSTOM USER ROLES = 90 91 For larger organizations, user roles can keep your publishing workflows organized and make sure notifications are sent to the correct people. 92 93 To find the role settings, go to the PublishPress link in your WordPress admin area, and click the “Roles” link. 94 95 * [Click here for more on PublishPress Custom User Roles](https://publishpress.com/docs/roles/) 96 96 97 97 = IMPORTING FROM EDITFLOW = … … 133 133 The format is based on [Keep a Changelog](http://keepachangelog.com/) 134 134 and this project adheres to [Semantic Versioning](http://semver.org/). 135 136 = [1.11.2] - 2018-03-19 = 137 138 *Fixed:* 139 140 * Fixed migration of following users and user groups in notifications; 135 141 136 142 = [1.11.1] - 2018-03-13 =
Note: See TracChangeset
for help on using the changeset viewer.