Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/03/2023 06:18:23 AM (2 years ago)
Author:
imath
Message:

Stop using BP Legacy URL parser in favor of the new BP Rewrites API

  • Deprecate bp_core_set_uri_globals(). This function is moved inside the BP Classic compatibility plugin.
  • Introduce the new bp_register_nav action to hook to when globalizing Members single item navigations from the BP_Component class.
  • Improve bp_get_component_navigations() so that Avatar/Cover images navigation items are moved inside the Profile sub nav if the Extended profile component is active.
  • Register Avatar/Cover images Ajax actions so that these actions trigger our new URL Parser inside Ajax context.
  • Improve the BP_Core_Nav::add_nav() method so that any BP action variable slugs can be customized.
  • Improve Members & Groups component canonical redirections.
  • Handle slugs customization persistency using directory pages post metas.
  • Introduce a new repair tool to reset all slugs to BuddyPress default one.
  • Adapt some PHPUnit tests to better handle our new URL parser.

Props Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13464 r13468  
    389389        if ( bp_displayed_user_id() ) {
    390390            $bp->canonical_stack['base_url'] = bp_displayed_user_url();
    391 
    392             if ( bp_current_component() ) {
    393                 $bp->canonical_stack['component'] = bp_current_component();
    394             }
    395 
    396             if ( bp_current_action() ) {
    397                 $bp->canonical_stack['action'] = bp_current_action();
    398             }
    399 
    400             if ( ! empty( $bp->action_variables ) ) {
    401                 $bp->canonical_stack['action_variables'] = bp_action_variables();
    402             }
    403 
    404             // Looking at the single member root/home, so assume the default.
    405             if ( ! bp_current_component() ) {
     391            $action_variables                = (array) bp_action_variables();
     392            $path_chunks                     = bp_members_get_path_chunks(
     393                array_merge(
     394                    array( bp_current_component(), bp_current_action() ),
     395                    array_filter( $action_variables )
     396                )
     397            );
     398
     399            if ( isset( $path_chunks['single_item_component'] ) ) {
     400                $bp->canonical_stack['component'] = $path_chunks['single_item_component'];
     401
     402                // The canonical URL will not contain the default component.
     403                if ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
     404                    unset( $bp->canonical_stack['component'] );
     405                } elseif ( isset( $path_chunks['single_item_action'] ) ) {
     406                    $bp->canonical_stack['action'] = $path_chunks['single_item_action'];
     407
     408                    if ( isset( $path_chunks['single_item_action_variables'] ) ) {
     409                        $bp->canonical_stack['action_variables'] = $path_chunks['single_item_action_variables'];
     410                    }
     411                }
     412
     413                // Looking at the single member root/home, so assume the default.
     414            } else {
    406415                $bp->current_component = $bp->default_component;
    407 
    408             // The canonical URL will not contain the default component.
    409             } elseif ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
    410                 unset( $bp->canonical_stack['component'] );
    411             }
    412 
    413             // If we're on a spammer's profile page, only users with the 'bp_moderate' cap
    414             // can view subpages on the spammer's profile.
    415             //
    416             // users without the cap trying to access a spammer's subnav page will get
    417             // redirected to the root of the spammer's profile page.  this occurs by
    418             // by removing the component in the canonical stack.
     416            }
     417
     418            /*
     419             * If we're on a spammer's profile page, only users with the 'bp_moderate' cap
     420             * can view subpages on the spammer's profile.
     421             *
     422             * users without the cap trying to access a spammer's subnav page will get
     423             * redirected to the root of the spammer's profile page.  this occurs by
     424             * by removing the component in the canonical stack.
     425             */
    419426            if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    420427                unset( $bp->canonical_stack['component'] );
     
    896903                $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] );
    897904                if ( $action_variables ) {
     905                    $context = sprintf( 'bp_member_%1$s_%2$s_', $bp->current_component, $bp->current_action );
     906
    898907                    if ( ! is_array( $action_variables ) ) {
    899                         $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
    900                     } else {
    901                         $bp->action_variables = $action_variables;
     908                        $action_variables = explode( '/', ltrim( $action_variables, '/' ) );
    902909                    }
     910
     911                    foreach ( $action_variables as $key_variable => $action_variable ) {
     912                        $item_component_action_variable_rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $action_variable, $context );
     913
     914                        if ( $item_component_action_variable_rewrite_id ) {
     915                            $action_variables[ $key_variable ] = str_replace( $context, '', $item_component_action_variable_rewrite_id );
     916                        }
     917                    }
     918
     919                    $bp->action_variables = $action_variables;
    903920                }
    904921
Note: See TracChangeset for help on using the changeset viewer.