BP_ACTIVITYSTRM::bp_activity_posted_update( $content,  $user_id,  $activity_id )

Validation function when the trigger action is hit


Parameters Parameters

$content

(Required)

$user_id

(Required)

$activity_id

(Required)


Source Source

File: src/integrations/buddypress/triggers/bp-activitystrm.php

	public function bp_activity_posted_update( $content, $user_id, $activity_id ) {



		$recipes            = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		$required_users     = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );
		$matched_recipe_ids = array();


		foreach ( $recipes as $recipe_id => $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {
				$trigger_id = $trigger['ID'];
				if ( intval( '-1' ) === intval( $required_users[ $recipe_id ][ $trigger_id ] ) || intval( $user_id ) === intval( $required_users[ $recipe_id ][ $trigger_id ] ) ) {
					$matched_recipe_ids[] = [
						'recipe_id'  => $recipe_id,
						'trigger_id' => $trigger_id,
					];
				}
			}
		}

		if ( ! empty( $matched_recipe_ids ) ) {
			foreach ( $matched_recipe_ids as $matched_recipe_id ) {
				$args = [
					'code'             => $this->trigger_code,
					'meta'             => $this->trigger_meta,
					'user_id'          => $user_id,
					'recipe_to_match'  => $matched_recipe_id['recipe_id'],
					'trigger_to_match' => $matched_recipe_id['trigger_id'],
					'ignore_post_id'   => true,
				];

				$returns = Automator()->maybe_add_trigger_entry( $args, false );

				if ( $returns ) {
					foreach ( $returns as $result ) {
						if ( true === $result['result'] ) {

							$trigger_meta = [
								'user_id'        => $user_id,
								'trigger_id'     => $result['args']['trigger_id'],
								'trigger_log_id' => $result['args']['get_trigger_id'],
								'run_number'     => $result['args']['run_number'],
							];

							// ACTIVITY_ID Token
							$trigger_meta['meta_key']   = 'ACTIVITY_ID';
							$trigger_meta['meta_value'] = $activity_id;
							Automator()->insert_trigger_meta( $trigger_meta );

							// ACTIVITY_CONTENT Token
							$trigger_meta['meta_key']   = 'ACTIVITY_CONTENT';
							$trigger_meta['meta_value'] = $content;
							Automator()->insert_trigger_meta( $trigger_meta );

							Automator()->maybe_trigger_complete( $result['args'] );
						}
					}
				}
			}
		}
	}