bp_has_message_threads( array|string $args = array() )

Retrieve private message threads for display in inbox/sentbox/notices.


Description Description

Similar to WordPress’s have_posts() function, this function is responsible for querying the database and retrieving private messages for display inside the theme via individual template parts for a member’s inbox/sentbox/notices.


Parameters Parameters

$args

(Optional) Array of arguments. All are optional.

  • 'user_id'
    (int) ID of the user whose threads are being loaded. Default: ID of the logged-in user.
  • 'box'
    (string) Current "box" view. If not provided here, the current view will be inferred from the URL.
  • 'per_page'
    (int) Number of results to return per page. Default: 10.
  • 'max'
    (int) Max results to return. Default: false.
  • 'type'
    (string) Type of messages to return. Values: 'all', 'read', 'unread' Default: 'all'
  • 'search_terms'
    (string) Terms to which to limit results. Default: the value of $_REQUEST['s'].
  • 'page_arg'
    (string) URL argument used for the pagination param. Default: 'mpage'.
  • 'meta_query'
    (array) Meta query arguments. Only applicable if $box is not 'notices'. See WP_Meta_Query more details.

Default value: array()


Top ↑

Return Return

(bool) True if there are threads to display, otherwise false.


Top ↑

Source Source

File: bp-messages/bp-messages-template.php

function bp_has_message_threads( $args = array() ) {
	global $messages_template;

	// The default box the user is looking at.
	$current_action = bp_current_action();
	switch ( $current_action ) {
		case 'sentbox' :
		case 'notices' :
		case 'inbox'   :
			$default_box = $current_action;
			break;
		default :
			$default_box = 'inbox';
			break;
	}

	// User ID
	// @todo displayed user for moderators that get this far?
	$user_id = bp_displayed_user_id();

	// Search Terms.
	$search_terms = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';

	// Parse the arguments.
	$r = bp_parse_args( $args, array(
		'user_id'      => $user_id,
		'box'          => $default_box,
		'per_page'     => 10,
		'max'          => false,
		'type'         => 'all',
		'search_terms' => $search_terms,
		'page_arg'     => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
		'meta_query'   => array()
	), 'has_message_threads' );

	// Load the messages loop global up with messages.
	$messages_template = new BP_Messages_Box_Template( $r );

	/**
	 * Filters if there are any message threads to display in inbox/sentbox/notices.
	 *
	 * @since 1.1.0
	 *
	 * @param bool                     $value             Whether or not the message has threads.
	 * @param BP_Messages_Box_Template $messages_template Current message box template object.
	 * @param array                    $r                 Array of parsed arguments passed into function.
	 */
	return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template, $r );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.