Skip to:
Content

BuddyPress.org


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

    r13450 r13455  
    498498
    499499    /**
     500     * Parse the WP_Query and eventually display the component's directory or single item.
     501     *
     502     * @since 12.0.0
     503     *
     504     * @param WP_Query $query Required. See BP_Component::parse_query() for
     505     *                        description.
     506     */
     507    public function parse_query( $query ) {
     508        if ( bp_is_directory_homepage( $this->id ) ) {
     509            $query->set( $this->rewrite_ids['directory'], 1 );
     510        }
     511
     512        if ( 1 === (int) $query->get( $this->rewrite_ids['directory'] ) ) {
     513            $bp = buddypress();
     514
     515            // Set the Activity component as current.
     516            $bp->current_component = 'activity';
     517
     518            $current_action = $query->get( $this->rewrite_ids['single_item_action'] );
     519            if ( $current_action ) {
     520                $bp->current_action = $current_action;
     521            }
     522
     523            $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] );
     524            if ( $action_variables ) {
     525                if ( ! is_array( $action_variables ) ) {
     526                    $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
     527                } else {
     528                    $bp->action_variables = $action_variables;
     529                }
     530            }
     531
     532            // Set the BuddyPress queried object.
     533            if ( isset( $bp->pages->activity->id ) ) {
     534                $query->queried_object    = get_post( $bp->pages->activity->id );
     535                $query->queried_object_id = $query->queried_object->ID;
     536            }
     537        }
     538
     539        parent::parse_query( $query );
     540    }
     541
     542    /**
    500543     * Init the BP REST API.
    501544     *
Note: See TracChangeset for help on using the changeset viewer.