Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/12/2023 10:12:37 PM (14 months ago)
Author:
imath
Message:

Administration: add a new settings tab to manage slugs customization

Compared to [13442], change the logic of Components user navigation
generation by introducing a BP_Component::register_nav() method to
globalize the nav items early (ie: the registration step) and make them
available for the new settings tab to manage slugs customization.

After a second thought, the BP_Component::setup_nav() should remain the
navigation generation step instead of playing the registration role. This
will maximize backward compatibility & third party plugins wishing their
slugs to be customizable will need to "opt-in" for BP Rewrites using the
BP_Component::register_nav() method.

This first version of the URLs settings tab does not handle slugs
customization yet, its first usage is to make sure all BP Components user
navigation slugs were registered & to put the Accordion UI in place.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13442 r13450  
    221221
    222222    /**
    223      * Set up navigation.
    224      *
    225      * @since 1.5.0
    226      *
    227      * @param array $main_nav Array of main nav items to set up.
    228      * @param array $sub_nav  Array of sub nav items to set up.
    229      */
    230     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    231 
    232         // Stop if there is no user displayed or logged in.
    233         if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    234             return;
    235         }
    236 
    237         $access = bp_core_can_edit_settings();
    238         $slug   = bp_get_profile_slug();
     223     * Register component navigation.
     224     *
     225     * @since 12.0.0
     226     *
     227     * @param array $main_nav See `BP_Component::register_nav()` for details.
     228     * @param array $sub_nav  See `BP_Component::register_nav()` for details.
     229     */
     230    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
     231        $slug = bp_get_profile_slug();
    239232
    240233        // Add 'Profile' to the main navigation.
     
    259252        // Edit Profile.
    260253        $sub_nav[] = array(
    261             'name'            => _x( 'Edit','Profile header sub menu', 'buddypress' ),
    262             'slug'            => 'edit',
    263             'parent_slug'     => $slug,
    264             'screen_function' => 'xprofile_screen_edit_profile',
    265             'position'        => 20,
    266             'user_has_access' => $access,
    267         );
    268 
    269         // The Settings > Profile nav item can only be set up after
    270         // the Settings component has run its own nav routine.
    271         add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) );
    272 
    273         parent::setup_nav( $main_nav, $sub_nav );
     254            'name'                     => _x( 'Edit','Profile header sub menu', 'buddypress' ),
     255            'slug'                     => 'edit',
     256            'parent_slug'              => $slug,
     257            'screen_function'          => 'xprofile_screen_edit_profile',
     258            'position'                 => 20,
     259            'user_has_access'          => false,
     260            'user_has_access_callback' => 'bp_core_can_edit_settings',
     261        );
     262
     263        parent::register_nav( $main_nav, $sub_nav );
    274264    }
    275265
     
    281271     *
    282272     * @since 2.1.0
     273     * @deprecated 12.0.0
    283274     */
    284275    public function setup_settings_nav() {
    285         if ( ! bp_is_active( 'settings' ) ) {
    286             return;
    287         }
    288 
    289         // Stop if there is no user displayed or logged in.
    290         if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    291             return;
    292         }
    293 
    294         // Get the settings slug.
    295         $settings_slug = bp_get_settings_slug();
    296 
    297         bp_core_new_subnav_item( array(
    298             'name'            => _x( 'Profile Visibility', 'Profile settings sub nav', 'buddypress' ),
    299             'slug'            => 'profile',
    300             'parent_slug'     => $settings_slug,
    301             'screen_function' => 'bp_xprofile_screen_settings',
    302             'position'        => 30,
    303             'user_has_access' => bp_core_can_edit_settings(),
    304         ), 'members' );
     276        _deprecated_function( __METHOD__, '12.0.0' );
    305277    }
    306278
Note: See TracChangeset for help on using the changeset viewer.