BP_Invitation::get( array $args = array() )

Get invitations, based on provided filter parameters.

Description

Parameters

$args

(Optional) Associative array of arguments. All arguments but $page and $per_page can be treated as filter values for get_where_sql() and get_query_clauses(). All items are optional.

  • 'id'
    (int|array) ID of invitation being updated. Can be an array of IDs.
  • 'user_id'
    (int|array) ID of user being queried. Can be an Can be an array of IDs.
  • 'inviter_id'
    (int|array) ID of user who created the invitation. Can be an array of IDs.
  • 'invitee_email'
    (string|array) Email address of invited users being queried. Can be an array of addresses.
  • 'class'
    (string|array) Name of the class to filter by. Can be an array of class names.
  • 'item_id'
    (int|array) ID of associated item. Can be an array of multiple item IDs.
  • 'secondary_item_id'
    (int|array) ID of secondary associated item. Can be an array of multiple IDs.
  • 'type'
    (string|array) Type of item. An "invite" is sent from one user to another. A "request" is submitted by a user and no inviter is required. 'all' returns all. Default: 'all'.
  • 'invite_sent'
    (string) Limit to draft, sent or all 'draft' limits to unsent invites, 'sent' returns only sent invites, 'all' returns all. Default: 'all'.
  • 'accepted'
    (bool) Limit to accepted or not-yet-accepted invitations. 'accepted' returns accepted invites, 'pending' returns pending invites, 'all' returns all. Default: 'pending'
  • 'search_terms'
    (string) Term to match against class field.
  • 'order_by'
    (string) Database column to order by.
  • 'sort_order'
    (string) Either 'ASC' or 'DESC'.
  • 'order_by'
    (string) Field to order results by.
  • 'sort_order'
    (string) ASC or DESC.
  • 'page'
    (int) Number of the current page of results. Default: false (no pagination, all items).
  • 'per_page'
    (int) Number of items to show per page. Default: false (no pagination, all items).
  • 'fields'
    (string) Which fields to return. Specify 'item_ids' to fetch a list of Item_IDs. Specify 'ids' to fetch a list of Invitation IDs. Default: 'all' (return BP_Invitation objects).

Default value: array()

Return

(array) BP_Invitation objects | IDs of found invit.

Source

File: bp-core/classes/class-bp-invitation.php

	public static function get( $args = array() ) {
		global $wpdb;
		$invites_table_name = BP_Invitation_Manager::get_table_name();

		// Parse the arguments
		$r  = bp_parse_args( $args, array(
			'id'                => false,
			'user_id'           => false,
			'inviter_id'        => false,
			'invitee_email'     => false,
			'class'             => false,
			'item_id'           => false,
			'secondary_item_id' => false,
			'type'              => 'all',
			'invite_sent'       => 'all',
			'accepted'          => 'pending',
			'search_terms'      => '',
			'order_by'          => false,
			'sort_order'        => false,
			'page'              => false,
			'per_page'          => false,
			'fields'            => 'all',
		), 'bp_invitations_invitation_get' );

		$sql = array(
			'select'     => "SELECT",
			'fields'     => '',
			'from'       => "FROM {$invites_table_name} i",
			'where'      => '',
			'orderby'    => '',
			'pagination' => '',
		);

		if ( 'item_ids' === $r['fields'] ) {
			$sql['fields'] = "DISTINCT i.item_id";
		} else if ( 'user_ids' === $r['fields'] ) {
			$sql['fields'] = "DISTINCT i.user_id";
		} else if ( 'inviter_ids' === $r['fields'] ) {
			$sql['fields'] = "DISTINCT i.inviter_id";
		} else {
			$sql['fields'] = 'DISTINCT i.id';
		}

		// WHERE
		$sql['where'] = self::get_where_sql( array(
			'id'                => $r['id'],
			'user_id'           => $r['user_id'],
			'inviter_id'		=> $r['inviter_id'],
			'invitee_email'     => $r['invitee_email'],
			'class'             => $r['class'],
			'item_id'           => $r['item_id'],
			'secondary_item_id' => $r['secondary_item_id'],
			'type'              => $r['type'],
			'invite_sent'       => $r['invite_sent'],
			'accepted'          => $r['accepted'],
			'search_terms'      => $r['search_terms'],
		) );

		// ORDER BY
		$sql['orderby'] = self::get_order_by_sql( array(
			'order_by'   => $r['order_by'],
			'sort_order' => $r['sort_order']
		) );

		// LIMIT %d, %d
		$sql['pagination'] = self::get_paged_sql( array(
			'page'     => $r['page'],
			'per_page' => $r['per_page'],
		) );

		$paged_invites_sql = "{$sql['select']} {$sql['fields']} {$sql['from']} {$sql['where']} {$sql['orderby']} {$sql['pagination']}";

		/**
		 * Filters the pagination SQL statement.
		 *
		 * @since BuddyBoss 1.3.5
		 *
		 * @param string $value Concatenated SQL statement.
		 * @param array  $sql   Array of SQL parts before concatenation.
		 * @param array  $r     Array of parsed arguments for the get method.
		 */
		$paged_invites_sql = apply_filters( 'bp_invitations_get_paged_invitations_sql', $paged_invites_sql, $sql, $r );

		$cached = bp_core_get_incremented_cache( $paged_invites_sql, 'bp_invitations' );
		if ( false === $cached ) {
			$paged_invite_ids = $wpdb->get_col( $paged_invites_sql );
			bp_core_set_incremented_cache( $paged_invites_sql, 'bp_invitations', $paged_invite_ids );
		} else {
			$paged_invite_ids = $cached;
		}

		// Special return format cases.
		if ( in_array( $r['fields'], array( 'ids', 'item_ids', 'user_ids', 'inviter_ids' ), true ) ) {
			// We only want the field that was found.
			return array_map( 'intval', $paged_invite_ids );
		}

		$uncached_ids = bp_get_non_cached_ids( $paged_invite_ids, 'bp_invitations' );
		if ( $uncached_ids ) {
			$ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) );
			$data_objects = $wpdb->get_results( "SELECT i.* FROM {$invites_table_name} i WHERE i.id IN ({$ids_sql})" );
			foreach ( $data_objects as $data_object ) {
				wp_cache_set( $data_object->id, $data_object, 'bp_invitations' );
			}
		}

		$paged_invites = array();
		foreach ( $paged_invite_ids as $paged_invite_id ) {
			$paged_invites[] = new BP_Invitation( $paged_invite_id );
		}

		return $paged_invites;
	}

Changelog

Changelog
Version Description
BuddyBoss 1.3.5 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.