Making WordPress.org

Changeset 9461


Ignore:
Timestamp:
02/04/2020 12:16:34 AM (4 years ago)
Author:
dd32
Message:

Login: Add a Canonical header to the login screens.

Fixes #5004.

Location:
sites/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/wporg-sso/wp-plugin.php

    r9459 r9461  
    3333
    3434        /**
     35         * Holds the route regex hit in `valid_sso_paths`
     36         * @var bool|string
     37         */
     38        static $matched_route_regex = false;
     39
     40        /**
    3541         * Holds any matched route params.
    3642         * @var array
     
    211217                if ( ! preg_match( '!/wp-login\.php$!', $this->script ) ) {
    212218                    // ... but not on its login screen.
    213                     self::$matched_route = false;
     219                    self::$matched_route        = false;
     220                    self::$matched_route_regex  = false;
    214221                    self::$matched_route_params = array();
    215222                    foreach ( $this->valid_sso_paths as $route => $regex ) {
    216223                        if ( preg_match( '!^' . $regex . '(?:[/?]{1,2}.*)?$!', $_SERVER['REQUEST_URI'], $matches ) ) {
    217                             self::$matched_route = $route;
     224                            self::$matched_route        = $route;
     225                            self::$matched_route_regex  = $regex;
    218226                            self::$matched_route_params = $matches;
    219227                            break;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php

    r9253 r9461  
    355355}
    356356add_action( 'login_purge_pending_registrations', 'wporg_login_purge_pending_registrations' );
     357
     358/**
     359 * Add a canonical tag to the login screens.
     360 */
     361function wporg_login_canonical_link() {
     362    $canonical = false;
     363
     364    // If the regular expression for this route is not matching, it's the canonical.
     365    if ( false === stripos( WP_WPOrg_SSO::$matched_route_regex, '(' ) ) {
     366        $canonical = site_url( WP_WPOrg_SSO::$matched_route_regex );
     367    }
     368
     369    if ( $canonical ) {
     370        printf( '<link rel="canonical" href="%s" />', esc_url( $canonical ) );
     371    }
     372}
     373add_action( 'login_head', 'wporg_login_canonical_link' );
     374add_action( 'wp_head', 'wporg_login_canonical_link' );
Note: See TracChangeset for help on using the changeset viewer.