Group_Member::create( $args,  $assoc_args )

Add a member to 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 ↑

[–role=] : Group member role (member, mod, admin). [–role=] : Group member role (member, mod, admin).

default: member options:

[–porcelain] : Return only the added group member id.

Top ↑

EXAMPLES EXAMPLES

$ wp bp group member add --group-id=3 --user-id=10
Success: Added user #3 to group #3 as member.

$ wp bp group member create --group-id=bar --user-id=20 --role=mod
Success: Added user #20 to group #45 as mod.

Source Source

File: cli/src/group-member.php

	public function create( $args, $assoc_args ) {
		$group_id = $this->get_group_id_from_identifier( $assoc_args['group-id'] );
		$user     = $this->get_user_id_from_identifier( $assoc_args['user-id'] );
		$role     = $assoc_args['role'];
		$joined   = groups_join_group( $group_id, $user->ID );

		if ( ! $joined ) {
			WP_CLI::error( 'Could not add user to the group.' );
		}

		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
			WP_CLI::log( $user->ID );
		} else {
			if ( 'member' !== $role ) {
				groups_promote_member( $user->ID, $group_id, $role );
			}

			WP_CLI::success(
				sprintf(
					'Added user #%d to group #%d as %s.',
					$user->ID,
					$group_id,
					$role
				)
			);
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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