Making WordPress.org

Ticket #2627: 2627-add-noindex-meta.2.patch

File 2627-add-noindex-meta.2.patch, 5.8 KB (added by tellyworth, 7 years ago)
  • plugins/plugin-directory/class-plugin-directory.php

     
    4646                add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
    4747                add_action( 'wp_head', array( Template::class, 'meta_description' ), 1 );
    4848                add_action( 'wp_head', array( Template::class, 'hreflang_link_attributes' ), 2 );
     49                add_action( 'wp_head', array( Template::class, 'output_meta' ), 1 );
    4950
    5051                // Cron tasks.
    5152                new Jobs\Manager();
     
    317318                ) );
    318319                register_post_status( 'disabled', array(
    319320                        'label'                     => _x( 'Disabled', 'plugin status', 'wporg-plugins' ),
    320                         'public'                    => false,
     321                        'public'                    => true,
    321322                        'show_in_admin_status_list' => current_user_can( 'plugin_disable' ),
    322323                        'label_count'               => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'wporg-plugins' ),
    323324                ) );
     
    818819                        }, 10, 2 );
    819820                }
    820821
     822                // Allow anyone to view a disabled plugin directly from its page. It won't show in search results or lists.
     823                if ( !empty( $wp_query->query_vars['name'] ) ) {
     824                        $wp_query->query_vars['post_status'] = (array) $wp_query->query_vars['post_status'];
     825                        $wp_query->query_vars['post_status'][] = 'disabled';
     826                        $wp_query->query_vars['post_status'] = array_unique( $wp_query->query_vars['post_status'] );
     827                }
     828
    821829                // By default, all archives are sorted by active installs
    822830                if ( $wp_query->is_archive() && empty( $wp_query->query_vars['orderby'] ) ) {
    823831                        $wp_query->query_vars['orderby']  = 'meta_value_num';
  • plugins/plugin-directory/class-template.php

     
    4545                endif;
    4646
    4747                // Schema for plugin pages.
    48                 if ( is_singular( 'plugin' ) ) :
    49                         $plugin = get_queried_object();
     48                if ( is_singular( 'plugin' ) && get_post_status( get_queried_object_id() ) !== 'disabled' ) {
     49                        self::plugin_json_jd_schema( get_queried_object() );
     50                }
     51        }
    5052
    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 );
     53        /**
     54         * Prints JSON LD schema for a specific plugin
     55         *
     56         * @param \WP_Post $plugin Plugin to output JSON LD Schema for.
     57         */
     58        protected static function plugin_json_jd_schema( $plugin ) {
     59                $rating      = get_post_meta( $plugin->ID, 'rating', true ) ?: 0;
     60                $ratings     = get_post_meta( $plugin->ID, 'ratings', true ) ?: [];
     61                $num_ratings = array_sum( $ratings );
    5462
    55                         echo PHP_EOL;
    56                         ?>
    57 <script type="application/ld+json">
     63                echo PHP_EOL;
     64                ?>
     65                <script type="application/ld+json">
    5866        [
    5967                {
    6068                        "@context": "http://schema.org",
     
    114122                }
    115123        ]
    116124</script>
    117                         <?php
    118                 endif;
     125                <?php
    119126        }
    120127
    121128        /**
     129         * Prints meta tags on a page.
     130         */
     131        public static function output_meta() {
     132                $metas = [];
     133
     134                // Add noindex on disabled plugin page.
     135                if ( is_singular( 'plugin' ) && get_post_status( get_queried_object_id() ) === 'disabled' ) {
     136                        $metas[] = '<meta name="robots" content="noindex" />';
     137                }
     138
     139                echo implode( PHP_EOL, $metas );
     140        }
     141
     142        /**
    122143         * Prints meta description in the head of a page.
    123144         *
    124145         * @static
  • themes/pub/wporg-plugins/template-parts/plugin-single.php

     
    2424                                <p><?php _e( 'This plugin <strong>hasn&#146;t been updated in over 2 years</strong>. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.', 'wporg-plugins' ); ?></p>
    2525                        </div><!-- .plugin-notice -->
    2626                <?php endif; ?>
    27                 <?php if ( 'publish' != get_post()->post_status ) :
     27<?php if ( 'publish' != get_post()->post_status ) :
    2828                                $notice_type = 'notice-error';
    2929                                switch ( get_post()->post_status ) {
    3030                                        case 'draft':
     
    5050                                                // fall through
    5151                                        default:
    5252                                        case 'closed':
    53                                                 $message = __( 'This plugin is closed and is not visible to the public.', 'wporg-plugins' );
     53                                                $message = __( 'This plugin is closed and no longer available for download.', 'wporg-plugins' );
    5454                                                break;
    5555                                }
    5656                        ?>
     
    9595                                </div>
    9696                        <?php endif; ?>
    9797
     98                        <?php if ( get_post_status() !== 'disabled' || current_user_can( 'plugin_admin_view', get_post() ) ) : ?>
    9899                        <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
     100                        <?php endif; ?>
    99101                </div>
    100102
    101103                <?php the_title( '<h1 class="plugin-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h1>' ); ?>
  • themes/pub/wporg-plugins/template-parts/section-advanced.php

     
    4040                // List Trunk, followed by the most recent non-stable release.
    4141                $tags = array_reverse( $tags );
    4242
    43                 if ( $tags ) {
     43                if ( $tags && 'publish' == get_post()->post_status ) {
    4444                        echo '<h5>' . __( 'Previous Versions', 'wporg-plugins' ) . '</h5>';
    4545
    4646                        echo '<div class="plugin-notice notice notice-info notice-alt"><p>' . __( 'Previous versions of this plugin may not be secure or stable and are available for testing purposes only.', 'wporg-plugins' ) . '</p></div>';