Making WordPress.org

Changeset 7898


Ignore:
Timestamp:
11/26/2018 04:51:14 AM (8 years ago)
Author:
dd32
Message:

WordPress.org: hreflang: Add a default x-default hreflang tag and use the canonical URL for singular pages when possible.

Fixes #3947, #3948.

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

Legend:

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

    r7282 r7898  
    783783                        );
    784784
     785                        // Add x-default to the list of sites.
     786                        $sites['x-default'] = (object) array(
     787                                'locale'    => 'x-default',
     788                                'hreflang'  => 'x-default',
     789                                'subdomain' => '',
     790                        );
     791
    785792                        uasort( $sites, function( $a, $b ) {
    786793                                return strcasecmp( $a->hreflang, $b->hreflang );
     
    788795
    789796                        wp_cache_set( 'local-sites-' . get_post()->post_name, $sites, 'locale-associations', DAY_IN_SECONDS );
     797                }
     798
     799                if ( is_singular() ) {
     800                        $path = parse_url( get_permalink(), PHP_URL_PATH );
     801                        if ( get_query_var( 'plugin_advanced' ) ) {
     802                                $path .= 'advanced/';
     803                        }
     804                } else {
     805                        // WordPress doesn't have a good way to get the canonical version of non-singular urls.
     806                        $path = $_SERVER['REQUEST_URI']; // phpcs:ignore
    790807                }
    791808
     
    794811                                'https://%swordpress.org%s',
    795812                                $site->subdomain ? "{$site->subdomain}." : '',
    796                                 $_SERVER['REQUEST_URI']
     813                                $path
    797814                        );
    798815
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r7600 r7898  
    10901090 */
    10911091function wporg_themes_add_hreflang_link_attributes() {
     1092        if ( is_404() ) {
     1093                return;
     1094        }
     1095
    10921096        wp_cache_add_global_groups( array( 'locale-associations' ) );
    10931097
     
    11361140                );
    11371141
     1142                // Add x-default to the list of sites.
     1143                $sites['x-default'] = (object) array(
     1144                        'locale'    => 'x-default',
     1145                        'hreflang'  => 'x-default',
     1146                        'subdomain' => '',
     1147                );
     1148
    11381149                uasort( $sites, function( $a, $b ) {
    11391150                        return strcasecmp( $a->hreflang, $b->hreflang );
     
    11411152
    11421153                wp_cache_set( 'local-sites', $sites, 'locale-associations' );
     1154        }
     1155
     1156        if ( is_singular() ) {
     1157                $path = parse_url( get_permalink(), PHP_URL_PATH );
     1158        } else {
     1159                // WordPress doesn't have a good way to get the canonical version of non-singular urls.
     1160                $path = $_SERVER['REQUEST_URI']; // phpcs:ignore
    11431161        }
    11441162
     
    11471165                        'https://%swordpress.org%s',
    11481166                        $site->subdomain ? "{$site->subdomain}." : '',
    1149                         $_SERVER[ 'REQUEST_URI' ]
     1167                        $path
    11501168                );
    11511169
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg/functions.php

    r7641 r7898  
    191191 */
    192192function hreflang_link_attributes() {
     193        // No hreflangs on 404 pages.
     194        if ( is_404() ) {
     195                return;
     196        }
     197
    193198        wp_cache_add_global_groups( array( 'locale-associations' ) );
    194199
     
    265270                );
    266271
     272                // Add x-default to the list of sites.
     273                $sites['x-default'] = (object) array(
     274                        'locale'    => 'x-default',
     275                        'hreflang'  => 'x-default',
     276                        'subdomain' => '',
     277                );
     278
    267279                uasort( $sites, function( $a, $b ) {
    268280                        return strcasecmp( $a->hreflang, $b->hreflang );
     
    270282
    271283                wp_cache_set( 'local-sites', $sites, 'locale-associations' );
     284        }
     285
     286        if ( is_singular() ) {
     287                $path = parse_url( get_permalink(), PHP_URL_PATH );
     288        } else {
     289                // WordPress doesn't have a good way to get the canonical version of non-singular urls.
     290                $path = $_SERVER['REQUEST_URI']; // phpcs:ignore
    272291        }
    273292
     
    276295                        'https://%swordpress.org%s',
    277296                        $site->subdomain ? "{$site->subdomain}." : '',
    278                         $_SERVER['REQUEST_URI'] // phpcs:ignore
     297                        $path
    279298                );
    280299
Note: See TracChangeset for help on using the changeset viewer.