Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/20/2023 02:30:11 AM (3 years 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-blogs/classes/class-bp-blogs-component.php

    r13450 r13455  
    435435
    436436                parent::add_rewrite_rules( $rewrite_rules );
     437        }
     438
     439        /**
     440         * Parse the WP_Query and eventually display the component's directory or single item.
     441         *
     442         * @since 12.0.0
     443         *
     444         * @param WP_Query $query Required. See BP_Component::parse_query() for
     445         *                        description.
     446         */
     447        public function parse_query( $query ) {
     448                if ( ! is_multisite() ) {
     449                        return parent::parse_query( $query );
     450                }
     451
     452                // Get the BuddyPress main instance.
     453                $bp = buddypress();
     454
     455                if ( bp_is_directory_homepage( $this->id ) ) {
     456                        $query->set( $this->rewrite_ids['directory'], 1 );
     457                }
     458
     459                if ( 1 === (int) $query->get( $this->rewrite_ids['directory'] ) ) {
     460                        $bp->current_component = 'blogs';
     461
     462                        $current_action = $query->get( $this->rewrite_ids['single_item_action'] );
     463                        if ( $current_action ) {
     464                                $bp->current_action = $current_action;
     465                        }
     466
     467                        $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] );
     468                        if ( $action_variables ) {
     469                                if ( ! is_array( $action_variables ) ) {
     470                                        $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
     471                                } else {
     472                                        $bp->action_variables = $action_variables;
     473                                }
     474                        }
     475
     476                        // Set the BuddyPress queried object.
     477                        if ( isset( $bp->pages->blogs->id ) ) {
     478                                $query->queried_object    = get_post( $bp->pages->blogs->id );
     479                                $query->queried_object_id = $query->queried_object->ID;
     480                        }
     481                }
     482
     483                parent::parse_query( $query );
    437484        }
    438485
Note: See TracChangeset for help on using the changeset viewer.