Making WordPress.org


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

Support Forums: Introduce Directory_Compat::get_support_reps() method to retrieve users assigned as the plugin/theme support reps.

See #2699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r5636 r5868  
    2424        var $authors      = null;
    2525        var $contributors = null;
     26        var $support_reps = null;
    2627        var $query        = null;
    2728        var $term         = null;
     
    317318                                $this->authors           = $this->get_authors( $slug );
    318319                                $this->contributors      = $this->get_contributors( $slug );
     320                                $this->support_reps      = $this->get_support_reps( $slug );
    319321                                $this->term              = $terms[0];
    320322
     
    332334                                // Instantiate WPORG_Stickies mode for topic view.
    333335                                if ( class_exists( 'WordPressdotorg\Forums\Stickies_Compat' ) ) {
    334                                         $this->stickies = new Stickies_Compat( $this->compat(), $this->slug(), $this->taxonomy(), $this->get_object( $this->slug() ), $this->term, $this->authors, $this->contributors );
     336                                        $this->stickies = new Stickies_Compat( $this->compat(), $this->slug(), $this->taxonomy(), $this->get_object( $this->slug() ), $this->term, $this->authors, $this->contributors, $this->support_reps );
    335337                                }
    336338
     
    341343
    342344        /**
    343          * Allow plugin/theme authors and contributors to resolve a topic on their support forum.
     345         * Allow plugin/theme authors, contributors, and support reps to resolve a topic
     346         * on their support forum.
    344347         *
    345348         * @param bool $retval If the user can set a topic resolution for the topic
     
    358361                        ( ! empty( $this->contributors ) && in_array( $user->user_nicename, $this->contributors ) )
    359362                ||
     363                        ( ! empty( $this->support_reps ) && in_array( $user->user_nicename, $this->support_reps ) )
     364                ||
     365                        // Back-compat for support reps added before https://meta.trac.wordpress.org/changeset/5867,
     366                        // can be removed once they are re-added via the Plugin Directory UI.
    360367                        ( is_a( $user, 'WP_User' ) && $user->supportrep == $this->slug() )
    361368                ) {
     
    902909                return $contributors;
    903910        }
     911
     912        public function get_support_reps( $slug ) {
     913                global $wpdb;
     914
     915                if ( null !== $this->support_reps ) {
     916                        return $this->support_reps;
     917                }
     918
     919                // Themes do not have support reps right now.
     920                if ( $this->compat() == 'theme' ) {
     921                        $support_reps = array();
     922                        return $support_reps;
     923                }
     924
     925                // Check the cache.
     926                $cache_key = $slug;
     927                $cache_group = $this->compat() . '-support-reps-slugs';
     928                $support_reps = wp_cache_get( $cache_key, $cache_group );
     929                if ( ! $support_reps ) {
     930                        $plugin = $this->get_object( $slug );
     931                        $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
     932                        $support_reps = $wpdb->get_col( $wpdb->prepare(
     933                                "SELECT slug
     934                                 FROM {$prefix}terms AS t
     935                                 LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
     936                                 LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
     937                                 WHERE tt.taxonomy = 'plugin_support_reps' AND tr.object_id = %d",
     938                                 $plugin->ID
     939                        ) );
     940
     941                        wp_cache_set( $cache_key, $support_reps, $cache_group, HOUR_IN_SECONDS );
     942                }
     943                return $support_reps;
     944        }
    904945}
Note: See TracChangeset for help on using the changeset viewer.