WordPress.org

Making WordPress.org

Changeset 6207


Ignore:
Timestamp:
12/03/2017 05:22:18 PM (3 years ago)
Author:
Otto42
Message:

Plugins: Fix the redirect_to URL in the same way as the support forums. Fixes #3108

File:
1 edited

Legend:

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

    r6204 r6207  
    7676        add_filter( 'default_option_jetpack_sync_full__finished', '__return_null' );
    7777
     78        // Fix login URLs in admin bar
     79        add_filter( 'login_url', array( $this, 'fix_login_url' ), 10, 3 );
     80
    7881        /*
    7982         * Load all Admin-specific items.
     
    865868        return $value;
    866869    }
     870
     871    /**
     872     * Adjust the login URL to point back to whatever part of the support forums we're
     873     * currently looking at. This allows the redirect to come back to the same place
     874     * instead of the main /support URL by default.
     875     */
     876    public function fix_login_url( $login_url, $redirect, $force_reauth ) {
     877        // modify the redirect_to for the support forums to point to the current page
     878        if ( 0 === strpos($_SERVER['REQUEST_URI'], '/plugins' ) ) {
     879            // Note that this is not normal because of the code in /mu-plugins/wporg-sso/class-wporg-sso.php.
     880            // The login_url function there expects the redirect_to as the first parameter passed into it instead of the second
     881            // Since we're changing this with a filter on login_url, then we have to change the login_url to the
     882            // place we want to redirect instead, and then let the SSO plugin do the rest.
     883            //
     884            // If the SSO code gets fixed, this will need to be modified.
     885            //
     886            // parse_url is used here to remove any additional query args from the REQUEST_URI before redirection
     887            // The SSO code handles the urlencoding of the redirect_to parameter
     888            $url_parts = parse_url('https://wordpress.org'.$_SERVER['REQUEST_URI']);
     889            $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . (isset($url_parts['path'])?$url_parts['path']:'');
     890            $login_url = $constructed_url;
     891        }
     892        return $login_url;
     893    }
     894
    867895
    868896    /**
Note: See TracChangeset for help on using the changeset viewer.