Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/03/2023 06:18:23 AM (4 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-groups/classes/class-bp-groups-component.php

    r13464 r13468  
    179179                                in_array( bp_current_action(), array( 'create', 'join', 'leave-group' ), true )
    180180                        ) {
    181                                 require $this->path . 'bp-groups/actions/' . bp_current_action() . '.php';
     181                                require_once $this->path . 'bp-groups/actions/' . bp_current_action() . '.php';
    182182                        }
    183183
    184184                        // Actions - RSS feed handler.
    185185                        if ( bp_is_active( 'activity' ) && bp_is_current_action( 'feed' ) ) {
    186                                 require $this->path . 'bp-groups/actions/feed.php';
     186                                require_once $this->path . 'bp-groups/actions/feed.php';
    187187                        }
    188188
    189189                        // Actions - Random group handler.
    190190                        if ( isset( $_GET['random-group'] ) ) {
    191                                 require $this->path . 'bp-groups/actions/random.php';
     191                                require_once $this->path . 'bp-groups/actions/random.php';
    192192                        }
    193193
    194194                        // Screens - Directory.
    195195                        if ( bp_is_groups_directory() ) {
    196                                 require $this->path . 'bp-groups/screens/directory.php';
     196                                require_once $this->path . 'bp-groups/screens/directory.php';
    197197                        }
    198198
    199199                        // Screens - User profile integration.
    200200                        if ( bp_is_user() ) {
    201                                 require $this->path . 'bp-groups/screens/user/my-groups.php';
     201                                require_once $this->path . 'bp-groups/screens/user/my-groups.php';
    202202
    203203                                if ( bp_is_current_action( 'invites' ) ) {
    204                                         require $this->path . 'bp-groups/screens/user/invites.php';
     204                                        require_once $this->path . 'bp-groups/screens/user/invites.php';
    205205                                }
    206206                        }
    … …  
    209209                        if ( bp_is_group() ) {
    210210                                // Actions - Access protection.
    211                                 require $this->path . 'bp-groups/actions/access.php';
     211                                require_once $this->path . 'bp-groups/actions/access.php';
    212212
    213213                                // Public nav items.
    214214                                if ( in_array( bp_current_action(), array( 'home', 'request-membership', 'activity', 'members', 'send-invites' ), true ) ) {
    215                                         require $this->path . 'bp-groups/screens/single/' . bp_current_action() . '.php';
     215                                        require_once $this->path . 'bp-groups/screens/single/' . bp_current_action() . '.php';
    216216                                }
    217217
    218218                                // Admin nav items.
    219219                                if ( bp_is_item_admin() && is_user_logged_in() ) {
    220                                         require $this->path . 'bp-groups/screens/single/admin.php';
     220                                        require_once $this->path . 'bp-groups/screens/single/admin.php';
    221221
    222222                                        if ( in_array( bp_get_group_current_admin_tab(), array( 'edit-details', 'group-settings', 'group-avatar', 'group-cover-image', 'manage-members', 'membership-requests', 'delete-group' ), true ) ) {
    223                                                 require $this->path . 'bp-groups/screens/single/admin/' . bp_get_group_current_admin_tab() . '.php';
     223                                                require_once $this->path . 'bp-groups/screens/single/admin/' . bp_get_group_current_admin_tab() . '.php';
    224224                                        }
    225225                                }
    … …  
    554554                // Prepare for a redirect to the canonical URL.
    555555                $bp->canonical_stack['base_url'] = bp_get_group_url( $this->current_group );
    556 
    557                 if ( bp_current_action() ) {
    558                         $bp->canonical_stack['action'] = bp_current_action();
    559                 }
     556                $current_action                  = bp_current_action();
    560557
    561558                /**
    … …  
    567564                 */
    568565                if ( ! $this->current_group->front_template && ( bp_is_current_action( 'activity' ) || ( ! bp_is_active( 'activity' ) && bp_is_current_action( 'members' ) ) ) ) {
    569                         $bp->canonical_stack['action'] = 'home';
    570                 }
    571 
    572                 if ( ! empty( $bp->action_variables ) ) {
    573                         $bp->canonical_stack['action_variables'] = bp_action_variables();
    574                 }
    575 
    576                 // When viewing the default extension, the canonical URL should not have
    577                 // that extension's slug, unless more has been tacked onto the URL via
    578                 // action variables.
     566                        $current_action = 'home';
     567                }
     568
     569                if ( $current_action ) {
     570                        $context                       = 'read';
     571                        $path_chunks                   = bp_groups_get_path_chunks( array( $current_action ), $context );
     572                        $bp->canonical_stack['action'] = $current_action;
     573
     574                        if ( isset( $path_chunks['single_item_action'] ) ) {
     575                                $bp->canonical_stack['action'] = $path_chunks['single_item_action'];
     576                        }
     577
     578                        if ( ! empty( $bp->action_variables ) ) {
     579                                $key_action_variables = 'single_item_action_variables';
     580
     581                                if ( bp_is_group_admin_page() ) {
     582                                        $context = 'manage';
     583                                } elseif ( bp_is_group_create() ) {
     584                                        $context              = 'create';
     585                                        $key_action_variables = 'create_single_item_variables';;
     586                                }
     587
     588                                $path_chunks                             = bp_groups_get_path_chunks( $bp->action_variables, $context );
     589                                $bp->canonical_stack['action_variables'] = bp_action_variables();
     590
     591                                if ( isset( $path_chunks[ $key_action_variables ] ) ) {
     592                                        $bp->canonical_stack['action_variables'] = $path_chunks[ $key_action_variables ];
     593                                }
     594                        }
     595                }
     596
     597                /*
     598                 * When viewing the default extension, the canonical URL should not have
     599                 * that extension's slug, unless more has been tacked onto the URL via
     600                 * action variables.
     601                 */
    579602                if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
    580603                        unset( $bp->canonical_stack['action'] );
    … …  
    11251148                                        $bp->action_variables         = array( $group_type_slug );
    11261149                                } else {
    1127                                         $bp->current_component = false;
     1150                                        $bp->current_component        = false;
     1151                                        $this->current_directory_type = '';
    11281152                                        bp_do_404();
    11291153                                        return;
Note: See TracChangeset for help on using the changeset viewer.