Skip to:
Content

BuddyPress.org

Opened 4 years ago

Closed 4 years ago

#7576 closed enhancement (wontfix)

Get notification description outside loop

Reported by: wordpressrene Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8.2
Component: Toolbar & Notifications Keywords: 2nd-opinion
Cc:

Description

Could you add the possibility to get the notification description (and to choose whose format) of a specific notification outside the loop? You could change the function bp_get_the_notification_description() to achieve this:

<?php
/**
 * Get full-text description for a specific notification.
 *
 * @since 1.9.0
 *
 * @param BP_Notifications_Notification $notification Notification to get the description for. Optional. Default null.
 * @param string $format Format of the description. Function returns string, if $format is 'string'. Function returns array, if $format is not 'string'. Optional. Default 'string'.
 *
 * @return string|array
 */
function bp_get_the_notification_description( $notification = null, $format = 'string' ) {
        $bp           = buddypress();
        $notification = $notification === null ? $bp->notifications->query_loop->notification : $notification;

        // Callback function exists.
        if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
                $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, $format, $notification->id );

        // @deprecated format_notification_function - 1.5
        } elseif ( isset( $bp->{ $notification->component_name }->format_notification_function ) && function_exists( $bp->{ $notification->component_name }->format_notification_function ) ) {
                $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );

        // Allow non BuddyPress components to hook in.
        } else {

                /** This filter is documented in bp-notifications/bp-notifications-functions.php */
                $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, $format, $notification->component_action, $notification->component_name, $notification->id ) );
        }

        /**
         * Filters the full-text description for a specific notification.
         *
         * @since 1.9.0
         * @since 2.3.0 Added the `$notification` parameter.
         *
         * @param string $description  Full-text description for a specific notification.
         * @param object $notification Notification object.
         */
        return apply_filters( 'bp_get_the_notification_description', $description, $notification );
}

Change History (2)

#1 @DJPaul
4 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to Under Consideration

I'm not convinced generally allowing template loop-specific functions to be used outside a loop via passing in an object. This came up on other tickets in the last few months, and as a project, we're yet to make a decision, so this is going to take a while to move forwards, unfortunately.

#2 @DJPaul
4 years ago

  • Milestone Under Consideration deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I'm deciding this is something we don't want to do at the moment, based on no feedback from other contributors that convinces me otherwise.

Note: See TracTickets for help on using tickets.