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-friends/classes/class-bp-friends-component.php

    r13441 r13450  
    149149
    150150    /**
    151      * Set up component navigation.
    152      *
    153      * @since 1.5.0
    154      *
    155      * @see BP_Component::setup_nav() for a description of arguments.
    156      *
    157      * @param array $main_nav Optional. See BP_Component::setup_nav() for
     151     * Register component navigation.
     152     *
     153     * @since 12.0.0
     154     *
     155     * @see `BP_Component::register_nav()` for a description of arguments.
     156     *
     157     * @param array $main_nav Optional. See `BP_Component::register_nav()` for
    158158     *                        description.
    159      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
     159     * @param array $sub_nav  Optional. See `BP_Component::register_nav()` for
    160160     *                        description.
    161161     */
    162     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    163 
    164         // Stop if there is no user displayed or logged in.
    165         if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    166             return;
    167         }
    168 
    169         $access = bp_core_can_edit_settings();
     162    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    170163        $slug   = bp_get_friends_slug();
    171164
    172         // Add 'Friends' to the main navigation.
    173         $count = friends_get_total_friend_count();
    174         $class = ( 0 === $count ) ? 'no-count' : 'count';
    175 
    176         $main_nav_name = sprintf(
    177             /* translators: %s: Friend count for the current user */
    178             __( 'Friends %s', 'buddypress' ),
    179             sprintf(
    180                 '<span class="%s">%s</span>',
    181                 esc_attr( $class ),
    182                 esc_html( $count )
    183             )
    184         );
    185 
    186165        $main_nav = array(
    187             'name'                => $main_nav_name,
     166            'name'                => __( 'Friends', 'buddypress' ),
    188167            'slug'                => $slug,
    189168            'position'            => 60,
     
    204183
    205184        $sub_nav[] = array(
    206             'name'            => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ),
    207             'slug'            => 'requests',
    208             'parent_slug'     => $slug,
    209             'screen_function' => 'friends_screen_requests',
    210             'position'        => 20,
    211             'user_has_access' => $access,
    212         );
     185            'name'                     => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ),
     186            'slug'                     => 'requests',
     187            'parent_slug'              => $slug,
     188            'screen_function'          => 'friends_screen_requests',
     189            'position'                 => 20,
     190            'user_has_access'          => false,
     191            'user_has_access_callback' => 'bp_core_can_edit_settings',
     192        );
     193
     194        parent::register_nav( $main_nav, $sub_nav );
     195    }
     196
     197    /**
     198     * Set up component navigation.
     199     *
     200     * @since 1.5.0
     201     *
     202     * @see `BP_Component::setup_nav()` for a description of arguments.
     203     *
     204     * @param array $main_nav Optional. See `BP_Component::setup_nav()` for
     205     *                        description.
     206     * @param array $sub_nav  Optional. See `BP_Component::setup_nav()` for
     207     *                        description.
     208     */
     209    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
     210        // Only grab count if we're on a user page.
     211        if ( bp_is_user() && isset( $this->main_nav['name'] ) ) {
     212            // Add 'Friends' to the main navigation.
     213            $count                  = friends_get_total_friend_count();
     214            $class                  = ( 0 === $count ) ? 'no-count' : 'count';
     215            $this->main_nav['name'] = sprintf(
     216                /* translators: %s: Friend count for the current user */
     217                __( 'Friends %s', 'buddypress' ),
     218                sprintf(
     219                    '<span class="%s">%s</span>',
     220                    esc_attr( $class ),
     221                    esc_html( $count )
     222                )
     223            );
     224        }
    213225
    214226        parent::setup_nav( $main_nav, $sub_nav );
Note: See TracChangeset for help on using the changeset viewer.