Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/20/2023 02:30:11 AM (12 months ago)
Author:
imath
Message:

Start implementing parse_query() methods for directory components

First concerned commponents are: Activity, Blogs & Members.

  • Remove the notice used to force pretty permalinks
  • Use plain links to test parse_query() methods are rightly setting BuddyPress URI globals
  • Introduce some helper functions used during the BP Rewrites API parsing process :
    • bp_is_directory_homepage() is checking if a BP Directory is used as the site's homepage
    • bp_rewrites_get_custom_slug_rewrite_id() finds a Rewrite ID out of a custom slug.
    • bp_rewrites_get_member_data() returns the field to use to get the user by.
    • bp_reset_query() makes it possible to parse again a request in specific cases (eg: root profiles)

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/87
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template-loader.php

    r13350 r13455  
    579579
    580580/**
     581 * Resets the query to fit our permalink structure if needed.
     582 *
     583 * This is used for specific cases such as Root Member's profile.
     584 *
     585 * @since 12.0.0
     586 *
     587 * @param string   $bp_request A specific BuddyPress request.
     588 * @param WP_Query $query The WordPress query object.
     589 * @return true
     590 */
     591function bp_reset_query( $bp_request = '', WP_Query $query = null ) {
     592    global $wp;
     593
     594    // Get BuddyPress main instance.
     595    $bp = buddypress();
     596
     597    // Back up request uri.
     598    $reset_server_request_uri = '';
     599    if ( isset( $_SERVER['REQUEST_URI'] ) ) {
     600        $reset_server_request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );
     601    }
     602
     603    // Temporarly override the request uri.
     604    if ( isset( $wp->request ) ) {
     605        $_SERVER['REQUEST_URI'] = str_replace( $wp->request, $bp_request, $reset_server_request_uri );
     606
     607        // Reparse request.
     608        $wp->parse_request();
     609
     610        // Reparse query.
     611        bp_remove_all_filters( 'parse_query' );
     612        $query->parse_query( $wp->query_vars );
     613        bp_restore_all_filters( 'parse_query' );
     614    }
     615
     616    // Restore request uri.
     617    $_SERVER['REQUEST_URI'] = $reset_server_request_uri;
     618
     619    // The query is reset.
     620    return true;
     621}
     622
     623/**
    581624 * Possibly intercept the template being loaded.
    582625 *
Note: See TracChangeset for help on using the changeset viewer.