Friends::create( $args,  $assoc_args )

Create a new friendship.


Description Description

Top ↑

OPTIONS OPTIONS

: ID of the user who is sending the friendship request. Accepts either a user_login or a numeric ID.
: ID of the user whose friendship is being requested. Accepts either a user_login or a numeric ID.
[–force-accept] : Whether to force acceptance.
[–silent] : Whether to silent the message creation.
[–porcelain] : Return only the friendship id.
## EXAMPLES
$ wp bp friend create user1 another_use Success: Friendship successfully created.
$ wp bp friend create user1 another_use –force-accept Success: Friendship successfully created.


Source Source

File: cli/src/friends.php

	public function create( $args, $assoc_args ) {
		$initiator = $this->get_user_id_from_identifier( $args[0] );
		$friend    = $this->get_user_id_from_identifier( $args[1] );

		// Silent it before it errors.
		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'silent' ) ) {
			return;
		}

		// Check if users are already friends, and bail if they do.
		if ( friends_check_friendship( $initiator->ID, $friend->ID ) ) {
			WP_CLI::error( 'These users are already friends.' );
		}

		$force = WP_CLI\Utils\get_flag_value( $assoc_args, 'force-accept' );

		if ( ! friends_add_friend( $initiator->ID, $friend->ID, $force ) ) {
			WP_CLI::error( 'There was a problem while creating the friendship.' );
		}

		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
			WP_CLI::log( \BP_Friends_Friendship::get_friendship_id( $initiator->ID, $friend->ID ) );
		} else {
			if ( $force ) {
				WP_CLI::success( 'Friendship successfully created.' );
			} else {
				WP_CLI::success( 'Friendship successfully created but not accepted.' );
			}
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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