WordPress.org

Making WordPress.org

Changeset 4613


Ignore:
Timestamp:
01/09/2017 05:43:43 PM (4 years ago)
Author:
Otto42
Message:

Support Forums: Fix login URL redirection to point to correct location in combination with existing SSO redirection code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r4610 r4613  
    2727        // Add notice to reply forms for privileged users in closed forums.
    2828        add_action( 'bbp_template_notices', array( $this, 'closed_forum_notice_for_moderators' ), 1 );
     29
     30        // Fix login url links
     31        add_filter( 'login_url', array( $this, 'fix_login_url' ), 10, 3 );
    2932    }
    3033
     
    122125    }
    123126
     127    /**
     128     * Adjust the login URL to point back to whatever part of the support forums we're
     129     * currently looking at. This allows the redirect to come back to the same place
     130     * instead of the main /support URL by default.
     131     */
     132    public function fix_login_url( $login_url, $redirect, $force_reauth ) {
     133        // modify the redirect_to for the support forums to point to the current page
     134        if ( 0 === strpos($_SERVER['REQUEST_URI'], '/support' ) ) {
     135            // Note that this is not normal because of the code in /mu-plugins/wporg-sso/class-wporg-sso.php.
     136            // The login_url function there expects the redirect_to as the first parameter passed into it instead of the second
     137            // Since we're changing this with a filter on login_url, then we have to change the login_url to the
     138            // place we want to redirect instead, and then let the SSO plugin do the rest.
     139            //
     140            // If the SSO code gets fixed, this will need to be modified.
     141            //
     142            // parse_url is used here to remove any additional query args from the REQUEST_URI before redirection
     143            // The SSO code handles the urlencoding of the redirect_to parameter
     144            $url_parts = parse_url('https://wordpress.org'.$_SERVER['REQUEST_URI']);
     145            $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . (isset($url_parts['path'])?$url_parts['path']:'');
     146            $login_url = $constructed_url;
     147        }
     148        return $login_url;
     149    }
     150
    124151}
Note: See TracChangeset for help on using the changeset viewer.