Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/08/2021 01:23:26 PM (3 years ago)
Author:
imath
Message:

Introduce a new function to get a list of type labels keyed by names

bp_activity_get_types_list() returns an array of activity type labels keyed by activity type names. It satisfies a need which appeared working on a new Activity BP Block.

Fixes #8504

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r12907 r12987  
    841841     */
    842842    return apply_filters( 'bp_activity_get_types', $actions );
     843}
     844
     845/**
     846 * Returns the list of available BuddyPress activity types.
     847 *
     848 * @since 9.0.0
     849 *
     850 * @return array An array of activity type labels keyed by type names.
     851 */
     852function bp_activity_get_types_list() {
     853    $actions_object = bp_activity_get_actions();
     854    $actions_array  = get_object_vars( $actions_object );
     855
     856    $types = array();
     857    foreach ( $actions_array as $component => $actions ) {
     858        $new_types = wp_list_pluck( $actions, 'label', 'key' );
     859
     860        if ( $types ) {
     861            // Makes sure activity types are unique.
     862            $new_types = array_diff_key( $new_types, $types );
     863
     864            if ( 'friends' === $component ) {
     865                $new_types = array_diff_key(
     866                    array(
     867                        'friendship_accepted'              => false,
     868                        'friendship_created'               => false,
     869                        'friends_register_activity_action' => false,
     870                    ),
     871                    $new_types
     872                );
     873
     874                $new_types['friendship_accepted,friendship_created'] = __( 'Friendships', 'buddypress' );
     875            }
     876        }
     877
     878        $types = array_merge( $types, $new_types );
     879    }
     880
     881    /**
     882     * Filter here to edit the activity types list.
     883     *
     884     * @since 9.0.0
     885     *
     886     * @param array $types An array of activity type labels keyed by type names.
     887     */
     888    return apply_filters( 'bp_activity_get_types_list', $types );
    843889}
    844890
Note: See TracChangeset for help on using the changeset viewer.