Changeset 9862
- Timestamp:
- 05/13/2020 05:02:12 AM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r9684 r9862 50 50 add_filter( 'the_content', array( $this, 'filter_rel_nofollow_ugc' ) ); 51 51 add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 ); 52 add_action( 'wp_head', array( Template::class, 'output_meta' ), 1 );53 52 add_action( 'wp_head', array( Template::class, 'hreflang_link_attributes' ), 2 ); 54 add_action( 'wp_head', array( Template::class, 'archive_link_rel_prev_next' ), 3 ); 55 add_action( 'wp_head', array( Template::class, 'archive_rel_canonical_link' ), 3 ); 53 54 // Add no-index headers where appropriate. 55 add_filter( 'wporg_noindex_request', [ Template::class, 'should_noindex_request' ] ); 56 57 // Fix the Canonical link when needed. 58 add_action( 'wporg_canonical_url', [ Template::class, 'wporg_canonical_url' ] ); 56 59 57 60 // Cron tasks. … … 544 547 remove_action( 'wp_head', 'feed_links', 2 ); 545 548 remove_action( 'wp_head', 'feed_links_extra', 3 ); 546 547 // Remove the core <link rel="canonical"> as we've got a plugin-directory-specific version548 remove_action( 'wp_head', 'rel_canonical' );549 549 550 550 add_filter( 'get_term', array( __NAMESPACE__ . '\I18n', 'translate_term' ) ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r9702 r9862 155 155 156 156 $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' ) ) { 163 159 $metas[] = sprintf( 164 160 '<meta name="description" value="%s" />', 165 161 esc_attr( get_the_excerpt() ) 166 162 ); 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' ) ) { 173 173 $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; 228 179 } 229 180 … … 1032 983 1033 984 /** 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 /**1046 985 * Get the current front-end requested URL. 1047 986 */ 1048 987 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(); 1073 990 1074 991 if ( $path_only && $link ) { … … 1079 996 1080 997 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/'; 1081 1009 } 1082 1010
Note: See TracChangeset
for help on using the changeset viewer.