Activity::create( $args,  $assoc_args )

Create an activity item.


Description Description

Top ↑

OPTIONS OPTIONS

[–component=] : The component for the activity item (groups, activity, etc). If none is provided, a component will be randomly selected from the active components.

[–type=] : Activity type (activity_update, group_created, etc). If none is provided, a type will be randomly chose from those natively associated with your .

[–action=] : Action text (eg "Joe created a new group Foo"). If none is provided, one will be generated automatically based on other params.

[–content=] : Activity content text. If none is provided, default text will be generated.

[–primary-link=] : URL of the item, as used in RSS feeds. If none is provided, a URL will be generated based on passed parameters.

[–user-id=] : ID of the user associated with the new item. If none is provided, a user will be randomly selected.

[–item-id=] : ID of the associated item. If none is provided, one will be generated automatically, if your activity type requires it.

[–secondary-item-id=] : ID of the secondary associated item. If none is provided, one will be generated automatically, if your activity type requires it.

[–date-recorded=] : GMT timestamp, in Y-m-d h:i:s format.

[–hide-sitewide=] : Whether to hide in sitewide streams.

[–is-spam=] : Whether the item should be marked as spam.

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

[–porcelain] : Output only the new activity id.

Top ↑

EXAMPLES EXAMPLES

$ wp bp activity create --is-spam=1
Success: Successfully created new activity item (ID #5464)

$ wp bp activity add --component=groups --item-id=564 --user-id=10
Success: Successfully created new activity item (ID #48949)

Source Source

File: cli/src/activity.php

	public function create( $args, $assoc_args ) {
		$r = wp_parse_args( $assoc_args,
			array(
				'component'         => '',
				'type'              => '',
				'action'            => '',
				'content'           => '',
				'primary-link'      => '',
				'user-id'           => '',
				'item-id'           => '',
				'secondary-item-id' => '',
				'date-recorded'     => bp_core_current_time(),
				'hide-sitewide'     => 0,
				'is-spam'           => 0,
			)
		);

		// Fill in any missing information.
		if ( empty( $r['component'] ) ) {
			$r['component'] = $this->get_random_component();
		}

		if ( empty( $r['type'] ) ) {
			$r['type'] = $this->get_random_type_from_component( $r['component'] );
		}

		if ( 'groups' === $r['component'] ) {
			$r['item-id'] = $this->get_group_id_from_identifier( $r['item-id'] );
		}

		// If some data is not set, we have to generate it.
		if ( empty( $r['item-id'] ) || empty( $r['secondary-item-id'] ) ) {
			$r = $this->generate_item_details( $r );
		}

		$id = bp_activity_add(
			array(
				'action'            => $r['action'],
				'content'           => $r['content'],
				'component'         => $r['component'],
				'type'              => $r['type'],
				'primary_link'      => $r['primary-link'],
				'user_id'           => $r['user-id'],
				'item_id'           => $r['item-id'],
				'secondary_item_id' => $r['secondary-item-id'],
				'date_recorded'     => $r['date-recorded'],
				'hide_sitewide'     => (bool) $r['hide-sitewide'],
				'is_spam'           => (bool) $r['is-spam'],
			)
		);

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

		if ( ! is_numeric( $id ) ) {
			WP_CLI::error( 'Could not create activity item.' );
		}

		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
			WP_CLI::log( $id );
		} else {
			WP_CLI::success( sprintf( 'Successfully created new activity item (ID #%d)', $id ) );
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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