Making WordPress.org


Ignore:
Timestamp:
02/04/2019 04:36:07 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Output hreflang links to all languages on non-plugin pages.

Previously these were using the first plugin in an archive, which resulted in varied alternates.

See #4067.

File:
1 edited

Legend:

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

    r8186 r8187  
    824824                global $wpdb;
    825825
    826                 if ( ! get_post() ) {
     826                $post = false;
     827                if ( is_singular( 'plugin' ) ) {
     828                        $post = get_post();
     829                }
     830
     831                $path = self::get_current_url( $path_only = true );
     832                if ( ! $path ) {
    827833                        return;
    828834                }
    … …  
    830836                wp_cache_add_global_groups( array( 'locale-associations' ) );
    831837
    832                 if ( false === ( $sites = wp_cache_get( 'local-sites-' . get_post()->post_name, 'locale-associations' ) ) ) {
     838                // WARNING: for any changes below, check other uses of the `locale-assosciations` group as there's shared cache keys in use.
     839                $cache_key = $post ? 'local-sites-' . $post->post_name : 'local-sites';
     840                if ( false === ( $sites = wp_cache_get( $cache_key, 'locale-associations' ) ) ) {
    833841
    834842                        // get subdomain/locale associations
    835843                        $subdomains = $wpdb->get_results( 'SELECT locale, subdomain FROM wporg_locales', OBJECT_K );
    836844
    837                         $sites = Plugin_I18n::instance()->get_locales();
    838 
    839845                        require_once GLOTPRESS_LOCALES_PATH;
     846
     847                        if ( $post ) {
     848                                $sites = Plugin_I18n::instance()->get_locales();
     849                        } else {
     850                                $sites = array();
     851                                foreach ( array_keys( $subdomains ) as $locale ) {
     852                                        $sites[] = (object) array(
     853                                                'wp_locale'    => $locale
     854                                        );
     855                                }
     856                        }
    840857
    841858                        foreach ( $sites as $key => $site ) {
    … …  
    884901                        } );
    885902
    886                         wp_cache_set( 'local-sites-' . get_post()->post_name, $sites, 'locale-associations', DAY_IN_SECONDS );
    887                 }
    888 
    889                 if ( is_singular() ) {
    890                         $path = parse_url( get_permalink(), PHP_URL_PATH );
    891                         if ( get_query_var( 'plugin_advanced' ) ) {
    892                                 $path .= 'advanced/';
    893                         }
    894                 } else {
    895                         // WordPress doesn't have a good way to get the canonical version of non-singular urls.
    896                         $path = $_SERVER['REQUEST_URI']; // phpcs:ignore
     903                        wp_cache_set( $cache_key, $sites, 'locale-associations', DAY_IN_SECONDS );
    897904                }
    898905
    … …  
    915922         * Outputs a <link rel="canonical"> on archive pages.
    916923         */
    917         public function archive_rel_canonical_link() {
     924        public static function archive_rel_canonical_link() {
    918925                if ( $url = self::get_current_url() ) {
    919926                        printf(
    … …  
    927934         * Get the current front-end requested URL.
    928935         */
    929         public function get_current_url() {
     936        public static function get_current_url( $path_only = false ) {
    930937                $queried_object = get_queried_object();
    931938                $link = false;
    … …  
    953960                }
    954961
     962                if ( $path_only && $link ) {
     963                        $path = parse_url( $link, PHP_URL_PATH );
     964                        if ( $query = parse_url( $link, PHP_URL_QUERY ) ) {
     965                                $path .= '?' . $query;
     966                        }
     967
     968                        return $path;
     969                }
     970
    955971                return $link;
    956972        }
Note: See TracChangeset for help on using the changeset viewer.