Friends::generate( $args,  $assoc_args )

Generate random friendships.


Description Description

Top ↑

OPTIONS OPTIONS

Top ↑

[–count=] : How many friendships to generate. [–count=] : How many friendships to generate.

Top ↑

default: 100 default: 100

[–initiator=] : ID of the first user. Accepts either a user_login or a numeric ID.

[–friend=] : ID of the second user. Accepts either a user_login or a numeric ID.

[–force-accept] : Whether to force acceptance.

Top ↑

EXAMPLES EXAMPLES

$ wp bp friend generate --count=50
$ wp bp friend generate --initiator=121 --count=50

Source Source

File: cli/src/friends.php

	public function generate( $args, $assoc_args ) {
		$notify = WP_CLI\Utils\make_progress_bar( 'Generating friendships', $assoc_args['count'] );

		for ( $i = 0; $i < $assoc_args['count']; $i++ ) {

			if ( isset( $assoc_args['initiator'] ) ) {
				$user   = $this->get_user_id_from_identifier( $assoc_args['initiator'] );
				$member = $user->ID;
			} else {
				$member = $this->get_random_user_id();
			}

			if ( isset( $assoc_args['friend'] ) ) {
				$user_2 = $this->get_user_id_from_identifier( $assoc_args['friend'] );
				$friend = $user_2->ID;
			} else {
				$friend = $this->get_random_user_id();
			}

			$this->create(
				array( $member, $friend ),
				array(
					'silent',
					'force-accept',
				)
			);

			$notify->tick();
		}

		$notify->finish();
	}


Top ↑

User Contributed Notes User Contributed Notes

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