Making WordPress.org

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

File 2627-add-noindex-meta.patch, 4.7 KB (added by jipmoors, 8 years ago)

Adding meta robots noindex to disabled plugin page

  • wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4343                add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    4444                add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
    4545                add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
     46                add_action( 'wp_head', array( Template::class, 'output_meta' ), 1 );
    4647
    4748                // Cron tasks.
    4849                new Jobs\Manager();
     
    298299                ) );
    299300                register_post_status( 'disabled', array(
    300301                        'label'                     => _x( 'Disabled', 'plugin status', 'wporg-plugins' ),
    301                         'public'                    => false,
     302                        'public'                    => true,
    302303                        'show_in_admin_status_list' => current_user_can( 'plugin_disable' ),
    303304                        'label_count'               => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'wporg-plugins' ),
    304305                ) );
     
    786787                        }, 10, 2 );
    787788                }
    788789
     790                // Allow anyone to view a disabled plugin directly from its page. It won't show in search results or lists.
     791                if ( !empty( $wp_query->query_vars['name'] ) ) {
     792                        $wp_query->query_vars['post_status'][] = 'disabled';
     793                        $wp_query->query_vars['post_status'] = array_unique( $wp_query->query_vars['post_status'] );
     794                }
     795
    789796                // By default, all archives are sorted by active installs
    790797                if ( $wp_query->is_archive() && empty( $wp_query->query_vars['orderby'] ) ) {
    791798                        $wp_query->query_vars['orderby']  = 'meta_value_num';
  • wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    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>' ); ?>
  • wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    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
     126        }
     127
     128        /**
     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 );
    119140        }
    120141
    121142        /**