Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/18/2021 10:18:06 AM (4 years ago)
Author:
imath
Message:

Nouveau: improve the way customizable slugs are handled

BuddyPress uses constants such as BP_FRIENDS_SLUG to let advanced users customize component URL slugs. The Nouveau template pack was wrongly checking hardcoded component names at various places into its code, in particular into the following functions and template tags:

  • bp_nouveau_current_object()
  • bp_nouveau_filter_options()
  • bp_nouveau_wrapper()

This commit also introduces a new BP Core function to get the active BP Component objects: bp_core_get_active_components(). The $args argument can be used to filter the active components according to their slugs, names, ids or root slugs. Nouveau uses it to determine the component ID out of its slug and use this component ID instead of slugs to create its needed dynamic selectors, classes and data attributes.

Props mattneil

Fixes #8133

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/functions.php

    r12595 r12892  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 8.0.0
    77 */
    88
     
    238238 */
    239239function bp_nouveau_wrapper( $args = array() ) {
    240  /**
    241     * Classes need to be determined & set by component to a certain degree
    242     *
    243     * Check the component to find a default container_class to add
    244     */
    245     $current_component_class = bp_current_component() . '-meta';
     240    /**
     241     * Classes need to be determined & set by component to a certain degree.
     242     *
     243     * Check the component to find a default container_class based on the component ID to add.
     244     * We need to to this because bp_current_component() is using the component slugs which can differ
     245     * from the component ID.
     246     */
     247    $current_component_id = bp_core_get_active_components( array( 'slug' => bp_current_component() ) );
     248    if ( $current_component_id && 1 === count( $current_component_id ) ) {
     249        $current_component_id = reset( $current_component_id );
     250    } else {
     251        $current_component_id = bp_current_component();
     252    }
     253
     254    $current_component_class = $current_component_id . '-meta';
    246255
    247256    if ( bp_is_group_activity() ) {
     
    256265            'container'         => 'div',
    257266            'container_id'      => '',
    258             'container_classes' => array( $generic_class, $current_component_class   ),
     267            'container_classes' => array( $generic_class, $current_component_class ),
    259268            'output'            => '',
    260269        ),
     
    533542
    534543    if ( empty( $component ) ) {
    535         if ( 'directory' === $context || 'user' === $context ) {
    536             $component = bp_current_component();
     544        if ( 'user' === $context ) {
     545            $component = bp_core_get_active_components( array( 'slug' => bp_current_component() ) );
     546            $component = reset( $component );
    537547
    538548            if ( 'friends' === $component ) {
     
    544554        } elseif ( 'group' === $context && bp_is_group_members() ) {
    545555            $component = 'members';
     556        } else {
     557            $component = bp_current_component();
    546558        }
    547559    }
Note: See TracChangeset for help on using the changeset viewer.