Making WordPress.org

Changeset 6118


Ignore:
Timestamp:
11/14/2017 05:01:46 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Allow closed/disabled plugins to have a public page.

  • Add a notice explaining the plugin's current status.
  • Add noindex meta tag.
  • Remove Download button and Previous Versions section.

Props tellyworth, jipmoors, Ipstenu, SergeyBiryukov.
See #2627.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
5 edited

Legend:

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

    r6034 r6118  
    268268
    269269            case 'closed':
    270                 $message = __( 'This plugin is closed and no longer available for use.', 'wporg-plugins' );
     270                $message = __( 'This plugin has been closed and is no longer available for download.', 'wporg-plugins' );
    271271                $type    = 'notice-error';
    272272                break;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r5867 r6118  
    4545        add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
    4646        add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
    47         add_action( 'wp_head', array( Template::class, 'meta_description' ), 1 );
     47        add_action( 'wp_head', array( Template::class, 'output_meta' ), 1 );
    4848        add_action( 'wp_head', array( Template::class, 'hreflang_link_attributes' ), 2 );
    4949
     
    318318        register_post_status( 'disabled', array(
    319319            'label'                     => _x( 'Disabled', 'plugin status', 'wporg-plugins' ),
    320             'public'                    => false,
     320            'public'                    => true,
    321321            'show_in_admin_status_list' => current_user_can( 'plugin_disable' ),
    322322            'label_count'               => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'wporg-plugins' ),
     
    330330        register_post_status( 'closed', array(
    331331            'label'                     => _x( 'Closed', 'plugin status', 'wporg-plugins' ),
    332             'public'                    => false,
     332            'public'                    => true,
    333333            'show_in_admin_status_list' => current_user_can( 'plugin_close' ),
    334334            'label_count'               => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'wporg-plugins' ),
     
    789789
    790790        // For singular requests, or self-author profile requests allow restricted post_status items to show on the front-end.
    791         if ( $wp_query->is_main_query() && ( $viewing_own_author_archive || is_user_logged_in() && !empty( $wp_query->query_vars['name'] ) ) ) {
     791        if ( $wp_query->is_main_query() && ( $viewing_own_author_archive || is_user_logged_in() && ! empty( $wp_query->query_vars['name'] ) ) ) {
    792792
    793793            $wp_query->query_vars['post_status'] = array( 'approved', 'publish', 'closed', 'disabled' );
     
    817817                return $posts;
    818818            }, 10, 2 );
     819        }
     820
     821        // Allow anyone to view a closed plugin directly from its page. It won't show in search results or lists.
     822        if ( $wp_query->is_main_query() && ! empty( $wp_query->query_vars['name'] ) ) {
     823            $wp_query->query_vars['post_status'] = (array) $wp_query->query_vars['post_status'];
     824            $wp_query->query_vars['post_status'][] = 'closed';
     825            $wp_query->query_vars['post_status'][] = 'disabled';
     826            $wp_query->query_vars['post_status'] = array_unique( $wp_query->query_vars['post_status'] );
    819827        }
    820828
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r6027 r6118  
    4646
    4747        // Schema for plugin pages.
    48         if ( is_singular( 'plugin' ) ) :
    49             $plugin = get_queried_object();
    50 
    51             $rating      = get_post_meta( $plugin->ID, 'rating', true ) ?: 0;
    52             $ratings     = get_post_meta( $plugin->ID, 'ratings', true ) ?: [];
    53             $num_ratings = array_sum( $ratings );
    54 
    55             echo PHP_EOL;
    56             ?>
     48        if ( is_singular( 'plugin' ) && 'publish' === get_post_status( get_queried_object_id() ) ) {
     49            self::plugin_json_jd_schema( get_queried_object() );
     50        }
     51    }
     52
     53    /**
     54     * Prints JSON LD schema for a specific plugin.
     55     *
     56     * @static
     57     *
     58     * @param \WP_Post $plugin Plugin to output JSON LD Schema for.
     59     */
     60    protected static function plugin_json_jd_schema( $plugin ) {
     61        $rating      = get_post_meta( $plugin->ID, 'rating', true ) ?: 0;
     62        $ratings     = get_post_meta( $plugin->ID, 'ratings', true ) ?: [];
     63        $num_ratings = array_sum( $ratings );
     64
     65        echo PHP_EOL;
     66        ?>
    5767<script type="application/ld+json">
    5868    [
     
    115125    ]
    116126</script>
    117             <?php
    118         endif;
    119     }
    120 
    121     /**
    122      * Prints meta description in the head of a page.
    123      *
    124      * @static
    125      */
    126     public static function meta_description() {
     127        <?php
     128    }
     129
     130    /**
     131     * Prints meta tags in the head of a page.
     132     *
     133     * @static
     134     */
     135    public static function output_meta() {
     136        $metas = [];
     137
    127138        if ( is_singular( 'plugin' ) ) {
    128             printf( '<meta name="description" value="%s"/>',
    129                 esc_attr( get_the_excerpt( get_queried_object() ) )
     139            $metas[] = sprintf( '<meta name="description" value="%s" />',
     140                esc_attr( get_the_excerpt() )
    130141            );
    131         }
     142
     143            // Add noindex on disabled plugin page.
     144            if ( 'publish' !== get_post_status() ) {
     145                $metas[] = '<meta name="robots" content="noindex" />';
     146            }
     147        }
     148
     149        echo implode( "\n", $metas );
    132150    }
    133151
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    r5457 r6118  
    1515
    1616$content = Plugin_Directory::instance()->split_post_content_into_pages( get_the_content() );
     17$status  = get_post_status();
    1718
    1819?><article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
     
    2526            </div><!-- .plugin-notice -->
    2627        <?php endif; ?>
    27         <?php if ( 'publish' != get_post()->post_status ) :
     28        <?php if ( 'publish' !== $status ) :
    2829                $notice_type = 'notice-error';
    29                 switch ( get_post()->post_status ) {
     30                switch ( $status ) {
    3031                    case 'draft':
    3132                    case 'pending':
     
    4041
    4142                    case 'rejected':
    42                         $message = __( 'This plugin is rejected and is not visible to the public.', 'wporg-plugins' );
     43                        $message = __( 'This plugin has been rejected and is not visible to the public.', 'wporg-plugins' );
    4344                        break;
    4445
    4546                    case 'disabled':
    4647                        if ( current_user_can( 'plugin_approve' ) ) {
    47                             $message = __( 'This plugin is disabled (closed, but actively serving updates) and is not visible to the public.', 'wporg-plugins' );
     48                            $message = __( 'This plugin is disabled (closed, but actively serving updates).', 'wporg-plugins' );
     49                            break;
     50                        } else {
     51                            $message = __( 'This plugin has been closed for new installs.', 'wporg-plugins' );
    4852                            break;
    4953                        }
     
    5155                    default:
    5256                    case 'closed':
    53                         $message = __( 'This plugin is closed and is not visible to the public.', 'wporg-plugins' );
     57                        $message = __( 'This plugin has been closed and is no longer available for download.', 'wporg-plugins' );
    5458                        break;
    5559                }
     
    5862                <p><?php echo $message; ?></p>
    5963            </div><!-- .plugin-notice -->
     64
     65            <?php if ( in_array( $status, array( 'closed', 'disabled' ) ) && get_current_user_id() == get_post()->post_author ) : ?>
     66                <div class="plugin-notice notice notice-info notice-alt">
     67                    <p><?php
     68                        printf(
     69                            /* translators: 1: plugins@wordpress.org */
     70                            __( 'If you did not request this change, please contact <a href="mailto:%1$s">%1$s</a> for a status. All developers with commit access are contacted when a plugin is closed, with the reasons why, so check your spam email too.', 'wporg-plugins' ),
     71                            'plugins@wordpress.org'
     72                        );
     73                    ?></p>
     74                </div><!-- .plugin-notice -->
     75            <?php endif; ?>
    6076        <?php endif; ?>
    6177
     
    96112            <?php endif; ?>
    97113
    98             <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
     114            <?php if ( 'publish' === get_post_status() || current_user_can( 'plugin_admin_view', get_post() ) ) : ?>
     115                <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
     116            <?php endif; ?>
    99117        </div>
    100118
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-advanced.php

    r5255 r6118  
    4141        $tags = array_reverse( $tags );
    4242
    43         if ( $tags ) {
     43        if ( $tags && 'publish' === get_post_status() ) {
    4444            echo '<h5>' . __( 'Previous Versions', 'wporg-plugins' ) . '</h5>';
    4545
Note: See TracChangeset for help on using the changeset viewer.