Group_Member::list_( $args,  $assoc_args )

Get a list of group memberships.


Description Description

This command can be used to fetch a list of a user’s groups (using the –user-id parameter) or a group’s members (using the –group-id flag).

Top ↑

OPTIONS OPTIONS

: Identifier for the group. Can be a numeric ID or the group slug.
[–fields=] : Limit the output to specific signup fields.
[–format=] : Render output in a particular format. — default: table options: – table – csv – ids – json – count – yaml —
[–=] : One or more parameters to pass. See groups_get_group_members()
## EXAMPLES
$ wp bp group member list 3 $ wp bp group member list my-group


Source Source

File: cli/src/group-member.php

	public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
		$group_id = $this->get_group_id_from_identifier( $args[0] );

		$roles = array( 'members' );
		if ( isset( $assoc_args['role'] ) ) {
			if ( is_string( $assoc_args['role'] ) ) {
				$roles = explode( ',', $assoc_args['role'] );
			} else {
				$roles = $assoc_args['role'];
			}
		}

		// Get our members.
		$members_query = groups_get_group_members(
			array(
				'group_id'            => $group_id,
				'exclude_admins_mods' => false,
				'group_role'          => $roles,
			)
		);

		$members = $members_query['members'];

		// Make 'role' human-readable.
		foreach ( $members as &$member ) {
			$role = 'member';
			if ( $member->is_mod ) {
				$role = 'mod';
			} elseif ( $member->is_admin ) {
				$role = 'admin';
			}

			$member->role = $role;
		}

		if ( empty( $members ) ) {
			WP_CLI::error( 'No group members found.' );
		}

		if ( empty( $assoc_args['fields'] ) ) {
			$assoc_args['fields'] = array(
				'user_id',
				'user_login',
				'fullname',
				'date_modified',
				'role',
			);
		}

		$this->get_formatter( $assoc_args )->display_items( $members );
	}


Top ↑

User Contributed Notes User Contributed Notes

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