Group_Invite::create( $args,  $assoc_args )

Invite 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.

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

[–message=] : Message to send with the invitation.

[–silent] : Whether to silent the invite creation.

Top ↑

EXAMPLES EXAMPLES

$ wp bp group invite add --group-id=40 --user-id=10 --inviter-id=1331
Success: Member invited to the group.

$ wp bp group invite create --group-id=40 --user-id=user_slug --inviter-id=804
Success: Member invited to the group.

Source Source

File: cli/src/group-invite.php

	public function create( $args, $assoc_args ) {
		$r = wp_parse_args( $assoc_args, array(
			'user-id'       => false,
			'group-id'      => false,
			'inviter-id'    => false,
			'message'       => '',
			'date-modified' => bp_core_current_time(),
		) );

		if ( $r['user-id'] === $r['inviter-id'] ) {
			return;
		}

		$group_id = $this->get_group_id_from_identifier( $r['group-id'] );
		$user     = $this->get_user_id_from_identifier( $r['user-id'] );
		$inviter  = $this->get_user_id_from_identifier( $r['inviter-id'] );

		$invite = groups_invite_user( array(
			'user_id'       => $user->ID,
			'group_id'      => $group_id,
			'inviter_id'    => $inviter->ID,
			'date_modified' => $r['date-modified'],
			'content'       => $r['message'],
		) );

		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'silent' ) ) {
			return;
		}

		if ( $invite ) {
			WP_CLI::success( 'Member invited to the group.' );
		} else {
			WP_CLI::error( 'Could not invite the member.' );
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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