WordPress.org

Making WordPress.org

Changeset 5868


Ignore:
Timestamp:
09/03/2017 09:46:04 PM (4 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
Files:
4 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}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin-directory-compat.php

    r5755 r5868  
    7979            $this->authors      = $this->get_authors( $slug );
    8080            $this->contributors = $this->get_contributors( $slug );
     81            $this->support_reps = $this->get_support_reps( $slug );
    8182        }
    8283    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-stickies-compat.php

    r5749 r5868  
    1313    var $term     = null;
    1414
    15     public function __construct( $compat, $slug, $taxonomy, $object, $term, $authors = array(), $contributors = array() ) {
     15    public function __construct( $compat, $slug, $taxonomy, $object, $term, $authors = array(), $contributors = array(), $support_reps = array() ) {
    1616        if ( empty( $compat ) || empty( $slug ) || empty( $taxonomy ) || empty( $object ) || empty( $term ) ) {
    1717            return;
     
    2525        $this->authors      = $authors;
    2626        $this->contributors = $contributors;
     27        $this->support_reps = $support_reps;
    2728
    2829        // Remove global stickies from sticky array.
     
    248249                $retval = true;
    249250            }
     251
     252            // Compat support reps.
     253            if ( $this->support_reps && in_array( $user->user_nicename, $this->support_reps ) ) {
     254                $retval = true;
     255            }
    250256        }
    251257        return $retval;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-theme-directory-compat.php

    r5755 r5868  
    7979            $this->authors      = $this->get_authors( $slug );
    8080            $this->contributors = $this->get_contributors( $slug );
     81            $this->support_reps = $this->get_support_reps( $slug );
    8182        }
    8283    }
Note: See TracChangeset for help on using the changeset viewer.