Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/18/2021 10:18:06 AM (2 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-core/bp-core-functions.php

    r12797 r12892  
    948948     */
    949949    return apply_filters( 'bp_core_get_component_search_query_arg', $query_arg, $component );
     950}
     951
     952/**
     953 * Get a list of all active component objects.
     954 *
     955 * @since 8.0.0
     956 *
     957 * @param array $args {
     958 *     Optional. An array of key => value arguments to match against the component objects.
     959 *     Default empty array.
     960 *
     961 *     @type string $name          Translatable name for the component.
     962 *     @type string $id            Unique ID for the component.
     963 *     @type string $slug          Unique slug for the component, for use in query strings and URLs.
     964 *     @type bool   $has_directory True if the component has a top-level directory. False otherwise.
     965 *     @type string $root_slug     Slug used by the component's directory page.
     966 * }
     967 * @param string $output   Optional. The type of output to return. Accepts 'ids'
     968 *                         or 'objects'. Default 'ids'.
     969 * @param string $operator Optional. The logical operation to perform. 'or' means only one
     970 *                         element from the array needs to match; 'and' means all elements
     971 *                         must match. Accepts 'or' or 'and'. Default 'and'.
     972 * @return array A list of component ids or objects.
     973 */
     974function bp_core_get_active_components( $args = array(), $output = 'ids', $operator = 'and' ) {
     975    $bp = buddypress();
     976
     977    $active_components = array_keys( $bp->active_components );
     978
     979    $xprofile_id = array_search( 'xprofile', $active_components, true );
     980    if ( false !== $xprofile_id ) {
     981        $active_components[ $xprofile_id ] = 'profile';
     982    }
     983
     984    $components = array();
     985    foreach ( $active_components as $id ) {
     986        if ( isset( $bp->{$id} ) && $bp->{$id} instanceof BP_Component ) {
     987            $components[ $id ] = $bp->{$id};
     988        }
     989    }
     990
     991    $components = wp_filter_object_list( $components, $args, $operator );
     992
     993    if ( 'ids' === $output ) {
     994        $components = wp_list_pluck( $components, 'id' );
     995    }
     996
     997    return $components;
    950998}
    951999
Note: See TracChangeset for help on using the changeset viewer.