Skip to:
Content

BuddyPress.org

Changeset 13492


Ignore:
Timestamp:
05/29/2023 05:51:12 AM (9 months ago)
Author:
imath
Message:

Make sure BP_Component::parse_query() always run

Only running it when BP Rewrites are on is not the right way to go as some plugins might have been using the WP Rewrites API for a while and might have extended this method from their component's class.

Instead of only running this method if BP Rewrites are on, we're adding a URL parser check inside each component having a directory to figure out whether it's needed to set BP URI globals.

See #4954
Fixes #8908
Closes https://github.com/buddypress/buddypress/pull/109

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r13471 r13492  
    506506     */
    507507    public function parse_query( $query ) {
     508        /*
     509         * If BP Rewrites are not in use, no need to parse BP URI globals another time.
     510         * Legacy Parser should have already set these.
     511         */
     512        if ( 'rewrites' !== bp_core_get_query_parser() ) {
     513            return parent::parse_query( $query );
     514        }
     515
    508516        if ( bp_is_directory_homepage( $this->id ) ) {
    509517            $query->set( $this->rewrite_ids['directory'], 1 );
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r13481 r13492  
    445445     */
    446446    public function parse_query( $query ) {
    447         if ( ! is_multisite() ) {
     447        /*
     448         * Only Multisite configs have a Sites directory.
     449         * If BP Rewrites are not in use, no need to parse BP URI globals another time.
     450         * Legacy Parser should have already set these.
     451         */
     452        if ( ! is_multisite() || 'rewrites' !== bp_core_get_query_parser() ) {
    448453            return parent::parse_query( $query );
    449454        }
  • trunk/src/bp-core/bp-core-template-loader.php

    r13468 r13492  
    566566    }
    567567
    568     // Set some needed URI globals.
    569     $bp                        = buddypress();
    570     $bp->unfiltered_uri        = explode( '/', $GLOBALS['wp']->request );
    571     $bp->unfiltered_uri_offset = 0;
     568    // Eventually Set some missing URI globals.
     569    $bp = buddypress();
     570
     571    if ( ! $bp->unfiltered_uri ) {
     572        $bp->unfiltered_uri        = explode( '/', $GLOBALS['wp']->request );
     573        $bp->unfiltered_uri_offset = 0;
     574    }
    572575
    573576    /**
  • trunk/src/bp-core/classes/class-bp-component.php

    r13471 r13492  
    578578
    579579        // Allow components to parse the main query.
    580         if ( 'rewrites' === bp_core_get_query_parser() ) {
    581             /**
    582              * Only fire this hook when pretty links are disabled.
    583              *
    584              * @todo Remove once BP Rewrites merge process is ended.
    585              */
    586             add_action( 'bp_parse_query',  array( $this, 'parse_query' ), 10 );
    587         }
     580        add_action( 'bp_parse_query',  array( $this, 'parse_query' ), 10 );
    588581
    589582        // Generate rewrite rules.
     
    12361229     */
    12371230    public function parse_query( $query ) {
    1238         if ( is_buddypress() ) {
     1231        if ( is_buddypress() && 'rewrites' === bp_core_get_query_parser() ) {
    12391232            add_filter( 'posts_pre_query', array( $this, 'pre_query' ), 10, 2 );
    12401233        }
  • trunk/src/bp-core/classes/class-bp-core.php

    r13471 r13492  
    424424     */
    425425    public function parse_query( $query ) {
     426        /*
     427         * If BP Rewrites are not in use, no need to parse BP URI globals another time.
     428         * Legacy Parser should have already set these.
     429         */
     430        if ( 'rewrites' !== bp_core_get_query_parser() ) {
     431            return parent::parse_query( $query );
     432        }
     433
    426434        $is_search = $query->get( 'pagename' ) === bp_get_search_slug() || ( isset( $_GET['bp_search'] ) && 1 === (int) $_GET['bp_search'] );
    427435
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13481 r13492  
    10671067     */
    10681068    public function parse_query( $query ) {
     1069        /*
     1070         * If BP Rewrites are not in use, no need to parse BP URI globals another time.
     1071         * Legacy Parser should have already set these.
     1072         */
     1073        if ( 'rewrites' !== bp_core_get_query_parser() ) {
     1074            return parent::parse_query( $query );
     1075        }
     1076
    10691077        if ( bp_is_directory_homepage( $this->id ) ) {
    10701078            $query->set( $this->rewrite_ids['directory'], 1 );
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13481 r13492  
    777777     */
    778778    public function parse_query( $query ) {
     779        /*
     780         * If BP Rewrites are not in use, no need to parse BP URI globals another time.
     781         * Legacy Parser should have already set these.
     782         */
     783        if ( 'rewrites' !== bp_core_get_query_parser() ) {
     784            return parent::parse_query( $query );
     785        }
     786
    779787        // Init the current member and member type.
    780788        $member      = false;
Note: See TracChangeset for help on using the changeset viewer.