Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/27/2021 06:59:23 AM (5 years ago)
Author:
imath
Message:

BP Nouveau: introduce a function to get active component slugs

bp_nouveau_get_component_slug() accepts the component's ID as an argument and uses the bp_get_{$component_id}_slug() corresponding function to get its slug only if the component is active.

Replace all occurences of bp_get_{$component_id}_slug() by bp_nouveau_get_component_slug( $component_id ) to prevent errors.

Fixes #8464

File:
1 edited

Legend:

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

    r12892 r12908  
    13921392        return true;
    13931393}
     1394
     1395/**
     1396 * Gets the component's slug thanks to its ID.
     1397 *
     1398 * @since 8.0.0
     1399 *
     1400 * @param string $component_id The component ID.
     1401 * @return string The slug for the requested component ID.
     1402 */
     1403function bp_nouveau_get_component_slug( $component_id = '' ) {
     1404        $slug = '';
     1405
     1406        if ( bp_is_active( $component_id ) ) {
     1407                switch ( $component_id ) {
     1408                        case 'activity':
     1409                                $slug = bp_get_activity_slug();
     1410                                break;
     1411                        case 'blogs':
     1412                                $slug = bp_get_blogs_slug();
     1413                                break;
     1414                        case 'friends':
     1415                                $slug = bp_get_friends_slug();
     1416                                break;
     1417                        case 'groups':
     1418                                $slug = bp_get_groups_slug();
     1419                                break;
     1420                        case 'messages':
     1421                                $slug = bp_get_messages_slug();
     1422                                break;
     1423                        case 'notifications':
     1424                                $slug = bp_get_notifications_slug();
     1425                                break;
     1426                        case 'settings':
     1427                                $slug = bp_get_settings_slug();
     1428                                break;
     1429                        case 'xprofile':
     1430                                $slug = bp_get_profile_slug();
     1431                                break;
     1432                }
     1433        }
     1434
     1435        // Defaults to the component ID.
     1436        if ( ! $slug ) {
     1437                $slug = $component_id;
     1438        }
     1439
     1440        /**
     1441         * Filter here to edit the slug for the requested component ID.
     1442         *
     1443         * @since 8.0.0
     1444         *
     1445         * @param string $slug         The slug for the requested component ID.
     1446         * @param string $component_id The component ID.
     1447         */
     1448        return apply_filters( 'bp_nouveau_get_component_slug', $slug, $component_id );
     1449}
Note: See TracChangeset for help on using the changeset viewer.