Making WordPress.org


Ignore:
Timestamp:
11/20/2018 07:04:56 PM (6 years ago)
Author:
coffee2code
Message:

Plugin Directory: Add helper function for retrieving plugins for which a user is a support rep.

File:
1 edited

Legend:

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

    r6287 r7877  
    232232
    233233    /**
     234     * Retrieve a list of plugins for which a user is a support rep.
     235     *
     236     * @static
     237     * @global \wpdb $wpdb WordPress database abstraction object.
     238     *
     239     * @param string|WP_User $user The user.
     240     * @return array         Array of WP_Post objects.
     241     */
     242    public static function get_support_rep_plugins( $user ) {
     243        global $wpdb;
     244
     245        if ( ! $user instanceof \WP_User ) {
     246            $user = new \WP_User( $user );
     247        }
     248
     249        $plugins = [];
     250
     251        if ( $user->exists() && ( false === ( $plugins = wp_cache_get( $user->user_nicename, 'support-rep-plugins' ) ) ) ) {
     252            $query = new \WP_Query( [
     253                'post_type'      => 'plugin',
     254                'post_status'    => 'publish',
     255                'posts_per_page' => 250,
     256                'no_found_rows'  => true,
     257                'tax_query' => [
     258                    [
     259                        'taxonomy' => 'plugin_support_reps',
     260                        'field'    => 'slug',
     261                        'terms'    => $user->user_nicename,
     262                    ],
     263                ],
     264            ] );
     265
     266            $plugins = $query->have_posts() ? $query->posts : [];
     267
     268            wp_cache_set( $user->user_nicename, $plugins, 'support-rep-plugins', 12 * HOUR_IN_SECONDS );
     269        }
     270
     271        return $plugins;
     272    }
     273
     274    /**
    234275     * Retrieve a list of support reps for a specific plugin.
    235276     *
     
    281322
    282323        wp_cache_delete( $plugin_slug, 'plugin-support-reps' );
     324        wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
    283325
    284326        return $result;
     
    312354
    313355        wp_cache_delete( $plugin_slug, 'plugin-support-reps' );
     356        wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
    314357
    315358        return $result;
Note: See TracChangeset for help on using the changeset viewer.