Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/12/2023 10:12:37 PM (13 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-blogs/classes/class-bp-blogs-component.php

    r13442 r13450  
    199199
    200200    /**
    201      * Set up component navigation for bp-blogs.
    202      *
    203      * @see BP_Component::setup_nav() for a description of arguments.
    204      *
    205      * @param array $main_nav Optional. See BP_Component::setup_nav() for
     201     * Register component navigation.
     202     *
     203     * @since 12.0.0
     204     *
     205     * @see `BP_Component::register_nav()` for a description of arguments.
     206     *
     207     * @param array $main_nav Optional. See `BP_Component::register_nav()` for
    206208     *                        description.
    207      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
     209     * @param array $sub_nav  Optional. See `BP_Component::register_nav()` for
    208210     *                        description.
    209211     */
    210     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    211 
     212    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    212213        /**
    213214         * Blog/post/comment menus should not appear on single WordPress setups.
     
    219220        }
    220221
    221         // Stop if there is no user displayed or logged in.
    222         if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    223             return;
    224         }
    225 
    226222        $slug = bp_get_blogs_slug();
    227223
    228         // Add 'Sites' to the main navigation.
    229         $count    = (int) bp_get_total_blog_count_for_user();
    230         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    231         $nav_text = sprintf(
    232             /* translators: %s: Site count for the current user */
    233             __( 'Sites %s', 'buddypress' ),
    234             sprintf(
    235                 '<span class="%s">%s</span>',
    236                 esc_attr( $class ),
    237                 esc_html( $count )
    238             )
    239         );
    240224        $main_nav = array(
    241             'name'                => $nav_text,
     225            'name'                => __( 'Sites', 'buddypress' ),
    242226            'slug'                => $slug,
    243227            'position'            => 30,
     
    256240
    257241        // Setup navigation.
     242        parent::register_nav( $main_nav, $sub_nav );
     243    }
     244
     245    /**
     246     * Set up component navigation.
     247     *
     248     * @since 1.5.0
     249     * @since 12.0.0 Used to customize the main navigation name.
     250     *
     251     * @see `BP_Component::setup_nav()` for a description of arguments.
     252     *
     253     * @param array $main_nav Optional. See `BP_Component::setup_nav()` for
     254     *                        description.
     255     * @param array $sub_nav  Optional. See `BP_Component::setup_nav()` for
     256     *                        description.
     257     */
     258    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
     259        // Only grab count if we're on a user page.
     260        if ( is_multisite() && bp_is_user() && isset( $this->main_nav['name'] ) ) {
     261            // Add the number of sites to the main nav.
     262            $count                  = (int) bp_get_total_blog_count_for_user();
     263            $class                  = ( 0 === $count ) ? 'no-count' : 'count';
     264            $this->main_nav['name'] = sprintf(
     265                /* translators: %s: Site count for the displayed user */
     266                __( 'Sites %s', 'buddypress' ),
     267                sprintf(
     268                    '<span class="%s">%s</span>',
     269                    esc_attr( $class ),
     270                    bp_core_number_format( $count )
     271                )
     272            );
     273        }
     274
    258275        parent::setup_nav( $main_nav, $sub_nav );
    259276    }
Note: See TracChangeset for help on using the changeset viewer.