Making WordPress.org


Ignore:
Timestamp:
09/03/2017 09:43:53 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Introduce UI for managing plugin support reps.

Support representatives can mark forum topics as resolved or sticky (same as plugin authors and contributors), but don't have commit access to the plugin.

See #3029, #2699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r5798 r5867  
    223223                wp_cache_delete( $user->user_login, 'committer-plugins' );
    224224                Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     225
     226                return $result;
     227        }
     228
     229        /**
     230         * Retrieve a list of support reps for a specific plugin.
     231         *
     232         * @static
     233         *
     234         * @param string $plugin_slug The plugin slug.
     235         * @return array The list of user_nicename's which are support reps.
     236         */
     237        public static function get_plugin_support_reps( $plugin_slug ) {
     238                if ( ! $plugin_slug ) {
     239                        return array();
     240                }
     241
     242                if ( false === ( $support_reps = wp_cache_get( $plugin_slug, 'plugin-support-reps' ) ) ) {
     243                        $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     244                        $support_reps = wp_get_object_terms( $post->ID, 'plugin_support_reps', array( 'fields' => 'names' ) );
     245
     246                        wp_cache_set( $plugin_slug, $support_reps, 'plugin-support-reps', 12 * HOUR_IN_SECONDS );
     247                }
     248
     249                return $support_reps;
     250        }
     251
     252        /**
     253         * Add a user as a support rep for a plugin.
     254         *
     255         * @static
     256         *
     257         * @param string          $plugin_slug The plugin slug.
     258         * @param string|\WP_User $user        The user to add.
     259         * @return bool
     260         */
     261        public static function add_plugin_support_rep( $plugin_slug, $user ) {
     262                if ( ! $user instanceof \WP_User ) {
     263                        $user = new \WP_User( $user );
     264                }
     265
     266                if ( ! $user->exists() || ! $plugin_slug ) {
     267                        return false;
     268                }
     269
     270                $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     271
     272                if ( ! $post ) {
     273                        return false;
     274                }
     275
     276                $result = wp_add_object_terms( $post->ID, $user->user_nicename, 'plugin_support_reps' );
     277
     278                return $result;
     279        }
     280
     281        /**
     282         * Remove a user as a support rep for a plugin.
     283         *
     284         * @static
     285         *
     286         * @param string          $plugin_slug The plugin slug.
     287         * @param string|\WP_User $user        The user to remove.
     288         * @return bool
     289         */
     290        public static function remove_plugin_support_rep( $plugin_slug, $user ) {
     291                if ( ! $user instanceof \WP_User ) {
     292                        $user = new \WP_User( $user );
     293                }
     294
     295                if ( ! $user->exists() || ! $plugin_slug ) {
     296                        return false;
     297                }
     298
     299                $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     300
     301                if ( ! $post ) {
     302                        return false;
     303                }
     304
     305                $result = wp_remove_object_terms( $post->ID, $user->user_nicename, 'plugin_support_reps' );
    225306
    226307                return $result;
Note: See TracChangeset for help on using the changeset viewer.