Making WordPress.org


Ignore:
Timestamp:
10/11/2016 06:42:46 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Allow non-published plugins to be viewed on the front-end by reviewers and contributors/commiters/submitters of the plugin.

This also adds a notice on the top of plugin pages with the status of the plugin.

See #2111.

File:
1 edited

Legend:

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

    r4212 r4213  
    531531                }
    532532
     533                // For singular requests, or self-author profile requests allow restricted post_status items to show on the front-end.
     534                if ( is_user_logged_in() && (
     535                        !empty( $wp_query->query_vars['name'] ) ||
     536                        (
     537                                !empty( $wp_query->query_vars['plugin_contributor'] ) &&
     538                                (
     539                                        current_user_can( 'plugin_review' ) ||
     540                                        0 === strcasecmp( $wp_query->query_vars['plugin_contributor'], wp_get_current_user()->user_nicename )
     541                                )
     542                        ) )
     543                ) {
     544                        $wp_query->query_vars['post_status'] = array( 'pending', 'approved', 'publish', 'closed', 'disabled' );
     545
     546                        add_filter( 'posts_results', function( $posts, $this_wp_query ) use( $wp_query ) {
     547                                if ( $this_wp_query != $wp_query ) {
     548                                        return $posts;
     549                                }
     550
     551                                $restricted_access_statii = array_diff( $wp_query->query_vars['post_status'], array( 'publish' ) );
     552                                foreach ( $posts as $i => $post ) {
     553                                        // If the plugin is not in the restricted statuses list, show it
     554                                        if ( 'plugin' != $post->post_type || ! in_array( $post->post_status, $restricted_access_statii, true ) ) {
     555                                                continue;
     556                                        }
     557
     558                                        // Plugin Reviewers can see all sorts of plugins
     559                                        if ( current_user_can( 'plugin_review' ) ) {
     560                                                continue;
     561                                        }
     562
     563                                        // Original submitter can always see
     564                                        if ( $post->post_author == get_current_user_id() ) {
     565                                                continue;
     566                                        }
     567
     568                                        // Committers (user_login) can always see
     569                                        if ( in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ) {
     570                                                continue;
     571                                        }
     572
     573                                        // Contributors (user_nicename) can always see
     574                                        if ( in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true ) ) {
     575                                                continue;
     576                                        }
     577
     578                                        // everyone else can't.
     579                                        unset( $posts[ $i ] );
     580                                }
     581
     582                                return $posts;
     583                        }, 10, 2 );
     584                }
     585
     586                // By default, all archives are sorted by active installs
    533587                if ( $wp_query->is_archive() && empty( $wp_query->query_vars['orderby'] ) ) {
    534588                        $wp_query->query_vars['orderby']  = 'meta_value_num';
Note: See TracChangeset for help on using the changeset viewer.