[buddypress-trac] [BuddyPress Trac] #7576: Get notification description outside loop
buddypress-trac
noreply at wordpress.org
Fri Jul 28 13:35:40 UTC 2017
#7576: Get notification description outside loop
-------------------------------------+-----------------------------
Reporter: wordpressrene | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Toolbar & Notifications | Version: 2.8.2
Severity: normal | Keywords:
-------------------------------------+-----------------------------
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
<?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 );
}
}}}
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7576>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list