Skip to:
Content

BuddyPress.org


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

    r13441 r13450  
    239239
    240240    /**
    241      * Set up component navigation.
    242      *
    243      * @since 1.5.0
    244      *
    245      * @see BP_Component::setup_nav() for a description of arguments.
    246      *
    247      * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
    248      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
    249      */
    250     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    251 
    252         // Stop if there is no user displayed or logged in.
    253         if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    254             return;
    255         }
    256 
     241     * Register component navigation.
     242     *
     243     * @since 12.0.0
     244     *
     245     * @see `BP_Component::register_nav()` for a description of arguments.
     246     *
     247     * @param array $main_nav Optional. See `BP_Component::register_nav()` for description.
     248     * @param array $sub_nav  Optional. See `BP_Component::register_nav()` for description.
     249     */
     250    public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    257251        $slug = bp_get_activity_slug();
    258252
     
    277271
    278272        // Check @mentions.
    279         if ( bp_activity_do_mentions() ) {
    280             $sub_nav[] = array(
    281                 'name'            => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),
    282                 'slug'            => 'mentions',
    283                 'parent_slug'     => $slug,
    284                 'screen_function' => 'bp_activity_screen_mentions',
    285                 'position'        => 20,
    286                 'item_css_id'     => 'activity-mentions'
    287             );
    288         }
     273        $sub_nav[] = array(
     274            'name'            => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),
     275            'slug'            => 'mentions',
     276            'parent_slug'     => $slug,
     277            'screen_function' => 'bp_activity_screen_mentions',
     278            'position'        => 20,
     279            'item_css_id'     => 'activity-mentions',
     280            'generate'        => bp_activity_do_mentions(),
     281        );
    289282
    290283        // Favorite activity items.
    291         if ( bp_activity_can_favorite() ) {
    292             $sub_nav[] = array(
    293                 'name'            => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),
    294                 'slug'            => 'favorites',
    295                 'parent_slug'     => $slug,
    296                 'screen_function' => 'bp_activity_screen_favorites',
    297                 'position'        => 30,
    298                 'item_css_id'     => 'activity-favs'
    299             );
    300         }
     284        $sub_nav[] = array(
     285            'name'            => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),
     286            'slug'            => 'favorites',
     287            'parent_slug'     => $slug,
     288            'screen_function' => 'bp_activity_screen_favorites',
     289            'position'        => 30,
     290            'item_css_id'     => 'activity-favs',
     291            'generate'        => bp_activity_can_favorite(),
     292        );
    301293
    302294        // Additional menu if friends is active.
     
    308300                'screen_function' => 'bp_activity_screen_friends',
    309301                'position'        => 40,
    310                 'item_css_id'     => 'activity-friends'
    311             ) ;
     302                'item_css_id'     => 'activity-friends',
     303            );
    312304        }
    313305
     
    324316        }
    325317
    326         parent::setup_nav( $main_nav, $sub_nav );
     318        parent::register_nav( $main_nav, $sub_nav );
    327319    }
    328320
Note: See TracChangeset for help on using the changeset viewer.