Making WordPress.org


Ignore:
Timestamp:
05/13/2020 05:02:12 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Remove specific SEO fixes that are included in the generic SEO fixes plugin.

See #5173.

File:
1 edited

Legend:

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

    r9702 r9862  
    155155
    156156                $metas   = [];
    157                 $noindex = false;
    158 
    159                 // Prevent duplicate search engine results.
    160                 if ( get_query_var( 'plugin_advanced' ) || is_search() ) {
    161                         $noindex = true;
    162                 } elseif ( is_singular( 'plugin' ) ) {
     157
     158                if ( is_singular( 'plugin' ) ) {
    163159                        $metas[] = sprintf(
    164160                                '<meta name="description" value="%s" />',
    165161                                esc_attr( get_the_excerpt() )
    166162                        );
    167 
    168                         // Add noindex for closed or outdated plugins.
    169                         if ( 'publish' !== get_post_status() || self::is_plugin_outdated() ) {
    170                                 $noindex = true;
    171                         }
    172                 } elseif ( is_tax() && $wp_query->found_posts <= 3 ) {
     163                }
     164
     165                echo implode( "\n", $metas );
     166        }
     167
     168        /**
     169         * Whether the current request should be noindexed.
     170         */
     171        public static function should_noindex_request( $noindex ) {
     172                if ( get_query_var( 'plugin_advanced' ) ) {
    173173                        $noindex = true;
    174                 }
    175 
    176                 if ( $noindex ) {
    177                         $metas[] = '<meta name="robots" content="noindex,follow" />' . "\n";
    178                 }
    179 
    180                 echo implode( "\n", $metas );
    181         }
    182 
    183         /**
    184          * Prints <link rel="prev|next"> tags for archives.
    185          *
    186          * @static
    187          */
    188         public static function archive_link_rel_prev_next() {
    189                 global $paged, $wp_query, $wp_rewrite;
    190                 if ( ! is_archive() && ! is_search() ) {
    191                         return;
    192                 }
    193 
    194                 $max_page = $wp_query->max_num_pages;
    195                 if ( ! $paged ) {
    196                         $paged = 1;
    197                 }
    198 
    199                 $nextpage = intval( $paged ) + 1;
    200                 $prevpage = intval( $paged ) - 1;
    201 
    202                 // re-implement get_pagenum_link() using our canonical url.
    203                 $current_url = Template::get_current_url();
    204                 if ( ! $current_url ) {
    205                         return;
    206                 }
    207 
    208                 $current_url = remove_query_arg( 'paged', $current_url );
    209                 $current_url = preg_replace( "|{$wp_rewrite->pagination_base}/\d+/?$|", '', $current_url );
    210 
    211                 // Just assume pretty permalinks everywhere.
    212                 $next_url = $current_url . "{$wp_rewrite->pagination_base}/{$nextpage}/";
    213                 $prev_url = $current_url . ( $prevpage > 1 ? "{$wp_rewrite->pagination_base}/{$prevpage}/" : '' );
    214 
    215                 if ( $prevpage >= 1 ) {
    216                         printf(
    217                                 '<link rel="prev" href="%s">' . "\n",
    218                                 esc_url( $prev_url )
    219                         );
    220                 }
    221 
    222                 if ( $nextpage <= $max_page ) {
    223                         printf(
    224                                 '<link rel="next" href="%s">' . "\n",
    225                                 esc_url( $next_url )
    226                         );
    227                 }
     174                } else if ( is_singular( 'plugin' ) && self::is_plugin_outdated() ) {
     175                        $noindex = true;
     176                }
     177
     178                return $noindex;
    228179        }
    229180
     
    1032983
    1033984        /**
    1034          * Outputs a <link rel="canonical"> on archive pages.
    1035          */
    1036         public static function archive_rel_canonical_link() {
    1037                 if ( $url = self::get_current_url() ) {
    1038                         printf(
    1039                                 '<link rel="canonical" href="%s">' . "\n",
    1040                                 esc_url( $url )
    1041                         );
    1042                 }
    1043         }
    1044 
    1045         /**
    1046985         * Get the current front-end requested URL.
    1047986         */
    1048987        public static function get_current_url( $path_only = false ) {
    1049                 $queried_object = get_queried_object();
    1050                 $link = false;
    1051 
    1052                 if ( is_tax() || is_tag() || is_category() ) {
    1053                         $link = get_term_link( $queried_object );
    1054                 } elseif ( is_singular() ) {
    1055                         $link = get_permalink( $queried_object );
    1056 
    1057                         if ( is_singular( 'plugin' ) && get_query_var( 'plugin_advanced' ) ) {
    1058                                 $link .= 'advanced/';
    1059                         }
    1060                 } elseif ( is_search() ) {
    1061                         $link = home_url( 'search/' . urlencode( get_query_var( 's' ) ) . '/' );
    1062                 } elseif ( is_front_page() ) {
    1063                         $link = home_url( '/' );
    1064                 }
    1065 
    1066                 if ( $link && is_paged() ) {
    1067                         if ( false !== stripos( $link, '?' ) ) {
    1068                                 $link = add_query_arg( 'paged', (int) get_query_var( 'paged' ), $link );
    1069                         } else {
    1070                                 $link = rtrim( $link, '/' ) . '/page/' . (int) get_query_var( 'paged' ) . '/';
    1071                         }
    1072                 }
     988
     989                $link = \WordPressdotorg\SEO\Canonical\get_canonical_url();
    1073990
    1074991                if ( $path_only && $link ) {
     
    1079996
    1080997                        return $path;
     998                }
     999
     1000                return $link;
     1001        }
     1002
     1003        /**
     1004         * Filter the WordPress.org Canonical URL to understand the Plugin Directory.
     1005         */
     1006        public static function wporg_canonical_url( $link ) {
     1007                if ( is_singular( 'plugin' ) && get_query_var( 'plugin_advanced' ) ) {
     1008                        $link = get_permalink( get_queried_object() ) . 'advanced/';
    10811009                }
    10821010
Note: See TracChangeset for help on using the changeset viewer.