BP_Notifications_Notification::get_current_notifications_for_user( array $args = array() )

Get unread notifications for a user, in a pagination-friendly format.

Description

Parameters

$args

(array) (Optional) Array of arguments.

  • 'user_id'
    (int) ID of the user for whom the notifications are being fetched. Default: logged-in user ID.
  • 'is_new'
    (bool) Whether to limit the query to unread notifications. Default: true.
  • 'page'
    (int) Number of the page to return. Default: 1.
  • 'per_page'
    (int) Number of results to display per page. Default: 10.
  • 'search_terms'
    (string) Optional. A term to search against in the 'component_name' and 'component_action' columns.

Default value: array()

Return

(array)

  • 'notifications'
    (array) Array of notification results.
  • 'total'
    (int) Count of all located notifications matching the query params.

Source

File: bp-notifications/classes/class-bp-notifications-notification.php

	public static function get_current_notifications_for_user( $args = array() ) {
		$r = wp_parse_args( $args, array(
			'user_id'      => bp_loggedin_user_id(),
			'is_new'       => true,
			'page'         => 1,
			'per_page'     => 25,
			'search_terms' => '',
		) );

		$notifications = self::get( $r );

		// Bail if no notifications.
		if ( empty( $notifications ) ) {
			return false;
		}

		$total_count = self::get_total_count( $r );

		return array( 'notifications' => &$notifications, 'total' => $total_count );
	}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.