Group_Invite::list_( $args,  $assoc_args )

Get a list of invitations from a group.


Description Description

Top ↑

OPTIONS OPTIONS

–group-id= : Identifier for the group. Accepts either a slug or a numeric ID.

–user-id= : Identifier for the user. Accepts either a user_login or a numeric ID.

Top ↑

[–format=] : Render output in a particular format. [–format=] : Render output in a particular format.

default: table options:

Top ↑

EXAMPLES EXAMPLES

$ wp bp group invite list --user-id=30 --group-id=56

Source Source

File: cli/src/group-invite.php

	public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
		$group_id = $this->get_group_id_from_identifier( $assoc_args['group-id'] );
		$user     = $this->get_user_id_from_identifier( $assoc_args['user-id'] );
		$user_id  = $user->ID;

		if ( $group_id ) {
			$invite_query = new \BP_Group_Member_Query( array(
				'is_confirmed' => false,
				'group_id'     => $group_id,
			) );

			$invites = $invite_query->results;

			// Manually filter out user ID - this is not supported by the API.
			if ( $user_id ) {
				$user_invites = array();

				foreach ( $invites as $invite ) {
					if ( $user_id === $invite->user_id ) {
						$user_invites[] = $invite;
					}
				}

				$invites = $user_invites;
			}

			if ( empty( $invites ) ) {
				WP_CLI::error( 'No invitations found.' );
			}

			if ( empty( $assoc_args['fields'] ) ) {
				$fields = array();

				if ( ! $user_id ) {
					$fields[] = 'user_id';
				}

				$fields[] = 'inviter_id';
				$fields[] = 'invite_sent';
				$fields[] = 'date_modified';

				$assoc_args['fields'] = $fields;
			}

			$formatter = $this->get_formatter( $assoc_args );
			$formatter->display_items( $invites );
		} else {
			$invite_query = groups_get_invites_for_user( $user_id );
			$invites      = $invite_query['groups'];

			if ( empty( $assoc_args['fields'] ) ) {
				$fields = array(
					'id',
					'name',
					'slug',
				);

				$assoc_args['fields'] = $fields;
			}

			$formatter = $this->get_formatter( $assoc_args );
			$formatter->display_items( $invites );
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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