Plugin Directory

Changeset 1843103


Ignore:
Timestamp:
03/19/2018 09:48:46 PM (8 years ago)
Author:
pressshack
Message:

Releasing 1.11.2

Location:
publishpress/trunk
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • publishpress/trunk/composer.json

    r1839780 r1843103  
    1313  "repositories": [
    1414    {
    15       "type": "vcs",
     15      "type": "git",
    1616      "url": "https://github.com/OSTraining/WordPress-Plugin-Builder"
    1717    }
  • publishpress/trunk/includes.php

    r1839780 r1843103  
    4242
    4343    // Define contants
    44     define('PUBLISHPRESS_VERSION', '1.10.0');
     44    define('PUBLISHPRESS_VERSION', '1.11.2');
    4545    define('PUBLISHPRESS_ROOT', dirname(__FILE__));
    4646    define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_ROOT . '/' . basename(__FILE__));
  • publishpress/trunk/modules/async-notifications/library/Queue/WPCron.php

    r1839780 r1843103  
    8484    {
    8585        wp_schedule_single_event(
    86             time(),
     86            time() + 4,
    8787            'publishpress_cron_notify',
    8888            $data
  • publishpress/trunk/modules/notifications/notifications.php

    r1839780 r1843103  
    4343    {
    4444
    45         // Taxonomy name used to store users following posts
    46         public $following_users_taxonomy = 'following_users';
    47 
    48         // Taxonomy name used to store user groups following posts
    49         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';
    5050
    5151        public $module;
     
    6464                'title'                 => __('Default Notifications', 'publishpress'),
    6565                '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'),
    6767                'module_url'            => $this->module_url,
    6868                'icon_class'            => 'dashicons dashicons-email',
     
    8383                    'id'      => 'pp-notifications-overview',
    8484                    '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'),
    8686                ),
    8787                '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'),
     
    107107
    108108            // Saving post actions
    109             // self::save_post_subscriptions() is hooked into transition_post_status so we can ensure usergroup data
     109            // self::save_post_subscriptions() is hooked into transition_post_status so we can ensure role data
    110110            // is properly saved before sending notifs
    111             add_action('transition_post_status', array($this, 'save_post_subscriptions'), 0, 3);
    112111            add_action('transition_post_status', array($this, 'notification_status_change'), PP_NOTIFICATION_PRIORITY_STATUS_CHANGE, 3);
    113112            add_action('pp_post_insert_editorial_comment', array($this, 'notification_comment'));
     
    121120            add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
    122121
    123             // Add a "Follow" link to posts
    124             if (apply_filters('pp_notifications_show_follow_link', true))
    125             {
    126                 // A little extra JS for the follow button
    127                 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'));
    128127                // Manage Posts
    129128                add_filter('post_row_actions', array($this, 'filter_post_row_actions'), 10, 2);
     
    137136            add_filter('pp_notification_auto_subscribe_current_user', array($this, 'filter_pp_notification_auto_subscribe_current_user'), 10, 2);
    138137
     138            add_action('save_post', array($this, 'action_save_post'), 10);
     139
    139140            // Ajax for saving notification updates
    140             add_action('wp_ajax_save_notifications', array($this, 'ajax_save_post_subscriptions'));
    141141            add_action('wp_ajax_pp_notifications_user_post_subscription', array($this, 'handle_user_post_subscription'));
    142142
     
    152152        public function install()
    153153        {
    154 
     154            // Considering we could be moving from Edit Flow, we need to migrate the following users.
     155            $this->migrateLegacyFollowingTerms();
    155156        }
    156157
     
    192193                $publishpress->update_module_option($this->module->name, 'loaded_once', true);
    193194            }
     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);
    194209        }
    195210
     
    216231            );
    217232
    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);
    219235        }
    220236
     
    230246            if ($this->is_whitelisted_functional_view())
    231247            {
    232                 wp_enqueue_script('jquery-listfilterizer');
    233                 wp_enqueue_script('jquery-quicksearch');
    234248                wp_enqueue_script(
    235249                    'publishpress-notifications-js',
     
    237251                    array(
    238252                        'jquery',
    239                         'jquery-listfilterizer',
    240                         'jquery-quicksearch',
    241253                    ),
    242254                    PUBLISHPRESS_VERSION,
    243255                    true
    244256                );
     257
     258                wp_enqueue_script('publishpress-chosen-js', PUBLISHPRESS_URL . '/common/libs/chosen/chosen.jquery.js',
     259                    ['jquery'], PUBLISHPRESS_VERSION);
    245260            }
    246261        }
     
    264279                    PUBLISHPRESS_VERSION
    265280                );
    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
    271289         *
    272290         * @since 0.8
    273291         */
    274         public function action_admin_head_follow_js()
     292        public function action_admin_head_notify_js()
    275293        {
    276294            ?>
     
    279297                    $(document).ready(function ($) {
    280298                        /**
    281                          * Action to Follow / Unfollow posts on the manage posts screen
     299                         * Action to Notify / Stop Notifying posts on the manage posts screen
    282300                         */
    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) {
    284302
    285303                            e.preventDefault();
     
    309327
    310328        /**
    311          * Add a "Follow" link to supported post types Manage Posts view
     329         * Add a "Notify" link to supported post types Manage Posts view
    312330         *
    313331         * @since 0.8
     
    331349            }
    332350
    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>';
    335353
    336354            return $actions;
     
    338356
    339357        /**
    340          * Get an action parts for a user to follow or unfollow a post
     358         * Get an action parts for a user to set Notify or Stop Notify for a post
    341359         *
    342360         * @since 0.8
    343361         */
    344         private function get_follow_action_parts($post)
     362        private function get_notify_action_parts($post)
    345363        {
    346364            $args = array(
     
    349367            );
    350368
    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';
    356374                $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');
    358376            } else
    359377            {
    360                 $args['method'] = 'follow';
     378                $args['method'] = 'start_notifying';
    361379                $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');
    363381            }
    364382
     
    368386            return array(
    369387                'title' => $title_text,
    370                 'text'  => $follow_text,
     388                'text'  => $link_text,
    371389                'link'  => add_query_arg($args, admin_url('admin-ajax.php')),
    372390            );
     
    383401            }
    384402
    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)
    387405            {
    388406                add_meta_box(
     
    391409                    array($this, 'notifications_meta_box'),
    392410                    $post_type,
    393                     'advanced'
     411                    'side',
     412                    'high'
    394413                );
    395414            }
     
    397416
    398417        /**
    399          * Outputs box used to subscribe users and usergroups to Posts
     418         * Outputs box used to subscribe users and roles to Posts
    400419         *
    401420         * @todo add_cap to set subscribers for posts; default to Admin and editors
     
    406425
    407426            ?>
    408             <div id="pp-post_following_box">
     427            <div id="pp_post_notify_box">
    409428                <a name="subscriptions"></a>
    410429
    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'); ?>
    412432                </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">
    415435                    <?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
    417441                    $select_form_args = array(
    418                         'list_class' => 'pp-post_following_list',
     442                        'list_class' => 'pp_post_notify_list',
    419443                    );
    420                     $this->users_select_form($followers, $select_form_args);
     444                    $this->users_select_form($selected , $select_form_args);
    421445                    ?>
     446
     447
    422448                </div>
    423449
    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>
    433453
    434454                <div class="clear"></div>
    435455
    436                 <input type="hidden" name="pp-save_followers" value="1"/> <?php // Extra protection against autosaves
     456                <input type="hidden" name="pp_save_notify" value="1"/> <?php // Extra protection against autosaves
    437457                ?>
    438458
    439                 <?php wp_nonce_field('save_user_usergroups', 'pp_notifications_nonce', false); ?>
     459                <?php wp_nonce_field('save_roles', 'pp_notifications_nonce', false); ?>
    440460            </div>
    441461
     
    443463        }
    444464
    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;
    471478                    }
    472479                }
    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            }
    475502        }
    476503
     
    499526            }
    500527
    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());
    504531            } else
    505532            {
    506                 $retval = $this->unfollow_post_user($post, get_current_user_id());
     533                $retval = $this->post_set_users_stop_notify($post, get_current_user_id());
    507534            }
    508535
     
    512539            }
    513540
    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));
    515542        }
    516543
     
    545572        }
    546573
    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
    550576         *
    551577         * @param int $post ID of the post
    552578         */
    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)
    575580        {
    576581            if (!is_array($users))
     
    579584            }
    580585
    581             // Add current user to following users
     586            // Add current user to notify list
    582587            $user = wp_get_current_user();
    583588            if ($user && apply_filters('pp_notification_auto_subscribe_current_user', true, 'subscription_action'))
     
    586591            }
    587592
    588             // Add post author to following users
     593            // Add post author to notify list
    589594            if (apply_filters('pp_notification_auto_subscribe_post_author', true, 'subscription_action'))
    590595            {
     
    594599            $users = array_unique(array_map('intval', $users));
    595600
    596             $follow = $this->follow_post_user($post, $users, false);
    597         }
    598 
    599         /**
    600          * Sets usergroups to follow specified post
     601            $this->post_set_users_to_notify($post, $users, false);
     602        }
     603
     604        /**
     605         * Sets roles to be notified for the specified post
    601606         *
    602607         * @param int   $post       ID of the post
    603          * @param array $usergroups Usergroups to follow posts
    604          */
    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);
    614619        }
    615620
     
    620625        {
    621626            global $publishpress;
     627
    622628
    623629            // Kill switch for notification
     
    678684            //if( $parent_ID ) $parent = get_comment( $parent_ID );
    679685
    680             // Set user to follow post, but make it filterable
     686            // Set user to be notified for a post, but make it filterable
    681687            if (apply_filters('pp_notification_auto_subscribe_current_user', true, 'comment'))
    682688            {
    683                 $this->follow_post_user($post, (int )$current_user->ID);
    684             }
    685 
    686             // Set the post author to follow the post but make it filterable
     689                $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
    687693            if (apply_filters('pp_notification_auto_subscribe_post_author', true, 'comment'))
    688694            {
    689                 $this->follow_post_user($post, (int )$post->post_author);
     695                $this->post_set_users_to_notify($post, (int )$post->post_author);
    690696            }
    691697
     
    807813            $recipients = array();
    808814
    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)
    818829                    {
    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))
    821831                        {
    822                             $usergroup_users[] = $usergroup_user->user_email;
     832                            $role_users[] = $user->user_email;
    823833                        }
    824834                    }
     
    826836            }
    827837
    828             $users = $this->get_following_users($post_id, 'user_email');
     838            $users = $this->get_users_to_notify($post_id, 'user_email');
    829839
    830840            // Merge arrays and filter any duplicates
    831             $recipients = array_merge($authors, $admins, $users, $usergroup_users);
     841            $recipients = array_merge($authors, $admins, $users, $role_users);
    832842            $recipients = array_unique($recipients);
    833843
     
    841851                }
    842852                // Don't send the email to the current user unless we've explicitly indicated they should receive it
    843                 if (false === apply_filters('pp_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)
    844854                {
    845855                    unset($recipients[$key]);
     
    861871
    862872        /**
    863          * Set a user or users to follow a post
     873         * Set a user or users to be notified for a post
    864874         *
    865875         * @param int|object   $post   Post object or ID
    866876         * @param string|array $users  User or users to subscribe to post updates
    867          * @param bool         $append Whether users should be added to following_users list or replace existing list
     877         * @param bool         $append Whether users should be added to pp_notify_user list or replace existing list
    868878         *
    869879         * @return true|WP_Error     $response  True on success, WP_Error on failure
    870880         */
    871         public function follow_post_user($post, $users, $append = true)
     881        public function post_set_users_to_notify($post, $users, $append = true)
    872882        {
    873883            $post = get_post($post);
     
    883893
    884894            $user_terms = array();
     895
    885896            foreach ($users as $user)
    886897            {
     
    901912
    902913                // 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);
    904915
    905916                if (!is_wp_error($term))
     
    908919                }
    909920            }
    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);
    911923
    912924            if (is_wp_error($set))
     
    920932
    921933        /**
    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         *
    927940         * @return true|WP_Error     $response  True on success, WP_Error on failure
    928941         */
    929         public function unfollow_post_user($post, $users)
     942        public function post_set_roles_to_notify($post, $roles, $append = true)
    930943        {
    931944            $post = get_post($post);
     
    935948            }
    936949
     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
    9371002            if (!is_array($users))
    9381003            {
     
    9401005            }
    9411006
    942             $terms = get_the_terms($post->ID, $this->following_users_taxonomy);
     1007            $terms = get_the_terms($post->ID, $this->notify_user_taxonomy);
    9431008            if (is_wp_error($terms))
    9441009            {
     
    9681033                }
    9691034            }
    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);
    9711036
    9721037            if (is_wp_error($set))
     
    9801045
    9811046        /**
    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        {
    9921052            $post_id = (is_int($post)) ? $post : $post->ID;
    993             if (!is_array($usergroups))
    994             {
    995                 $usergroups = array($usergroups);
    996             }
    997 
    998             // make sure each usergroup id is an integer and not a number stored as a string
    999             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);
    10051065
    10061066            return;
     
    10081068
    10091069        /**
    1010          * Removes users that are deleted from receiving future notifications (i.e. makes them unfollow posts FOREVER! )
     1070         * Removes users that are deleted from receiving future notifications (i.e. makes them out of notify list for posts FOREVER! )
    10111071         *
    10121072         * @param $id int ID of the user
     
    10241084            if ($user)
    10251085            {
    1026                 // Delete term from the following_users taxonomy
    1027                 $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);
    10311091                }
    10321092            }
     
    10551115
    10561116        /**
    1057          * Gets a list of the users following the specified post
     1117         * Gets a list of the users to be notified for the specified post
    10581118         *
    10591119         * @param int    $post_id The ID of the post
    10601120         * @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
    10701129            if (!$users || is_wp_error($users))
    10711130            {
     
    11241183
    11251184        /**
    1126          * Gets a list of the usergroups that are following specified post
     1185         * Gets a list of the roles that should be notified for the specified post
    11271186         *
    11281187         * @param int $post_id
    1129          * @return array $usergroups All of the usergroup slugs
    1130          */
    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')
    11321191        {
    11331192            global $publishpress;
     
    11421201            }
    11431202
    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));
    11451204
    11461205            if ($return == 'slugs')
    11471206            {
    11481207                $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 following
     1208                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
    11611220         *
    11621221         * @param string|int $user user_login or id of user
    11631222         * @param array      $args
    1164          * @return array $posts Posts a user is following
    1165          */
    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)
    11671226        {
    11681227            if (!$user)
     
    11791238                'tax_query'      => array(
    11801239                    array(
    1181                         'taxonomy' => $this->following_users_taxonomy,
     1240                        'taxonomy' => $this->notify_user_taxonomy,
    11821241                        'field'    => 'slug',
    11831242                        'terms'    => $user,
     
    11891248                'post_status'    => 'any',
    11901249            );
    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);
    11921251            $posts     = get_posts($post_args);
    11931252
     
    15281587        public function send_notification_comment($args)
    15291588        {
    1530 
    1531 
    15321589            /* translators: 1: blog name, 2: post title */
    15331590            $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  
    3232 * class PP_User_Groups
    3333 *
    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.
    3935 */
    4036
    4137if (!class_exists('PP_User_Groups'))
    4238{
     39    /**
     40     * Class PP_User_Groups
     41     *
     42     * @deprecated
     43     */
    4344    class PP_User_Groups extends PP_Module
    4445    {
     
    9798                ),
    9899                '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,
    100101            );
    101102            $this->module = PublishPress()->register_module('user_groups', $args);
     
    593594                                <?php
    594595                                $select_form_args = array(
    595                                     'list_class' => 'pp-post_following_list',
     596                                    'list_class' => 'pp_post_notify_list',
    596597                                    'input_id'   => 'usergroup_users',
    597598                                );
     
    882883            // before <tag>, after <tag>, class, id names?
    883884            $defaults = array(
    884                 'list_class' => 'pp-post_following_list',
     885                'list_class' => 'pp_post_notify_list',
    885886                'list_id'    => 'pp-following_usergroups',
    886887                'input_id'   => 'following_usergroups',
     
    948949        public function get_usergroups($args = array())
    949950        {
    950 
    951951            // We want empty terms by default
    952952            if (!isset($args['hide_empty']))
     
    12591259                foreach ($all_usergroups as $usergroup)
    12601260                {
    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
    12621266                    if (!in_array($user_id, $usergroup->user_ids))
    12631267                    {
  • publishpress/trunk/publishpress.php

    r1839780 r1843103  
    66 * Author: PublishPress
    77 * Author URI: https://publishpress.com
    8  * Version: 1.10.0
     8 * Version: 1.11.2
    99 * Text Domain: publishpress
    1010 * Domain Path: /languages
  • publishpress/trunk/readme.txt

    r1839788 r1843103  
    77Requires PHP: 5.4
    88Tested up to: 4.9.4
    9 Stable tag: 1.10.0
     9Stable tag: 1.11.2
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8787* [Click here for more on PublishPress Editorial Metadata](https://publishpress.com/docs/editorial-metadata/)
    8888
    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
     91For larger organizations, user roles can keep your publishing workflows organized and make sure notifications are sent to the correct people.
     92
     93To 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/)
    9696
    9797= IMPORTING FROM EDITFLOW =
     
    133133The format is based on [Keep a Changelog](http://keepachangelog.com/)
    134134and 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;
    135141
    136142= [1.11.1] - 2018-03-13 =
Note: See TracChangeset for help on using the changeset viewer.