WPJM_SUBMITJOB::job_manager_job_submitted( $new_status,  $old_status,  $post )


Parameters Parameters

$job_id

(Required)

$post

(Required)

$update

(Required)


Source Source

File: src/integrations/wp-job-manager/triggers/wpjm-submitjob.php

	public function job_manager_job_submitted( $new_status, $old_status, $post ) {



		if ( empty( $post ) ) {
			return;
		}

		if ( ! $post instanceof \WP_Post ) {
			return;
		}

		$job_id = $post->ID;

		if ( 'job_listing' !== $post->post_type ) {
			return;
		}

		if ( ! in_array( $post->post_status, array( 'pending', 'publish' ), true ) ) {
			return;
		}

		$job_terms = wpjm_get_the_job_types( $job_id );

		$recipes    = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		$conditions = $this->match_condition( $job_terms, $recipes, $this->trigger_meta, $this->trigger_code );

		if ( empty( $conditions ) ) {
			return;
		}

		$user_id = $post->post_author;

		foreach ( $conditions['recipe_ids'] as $recipe_id ) {
			if ( ! Automator()->is_recipe_completed( $recipe_id, $user_id ) ) {
				$trigger_args = array(
					'code'            => $this->trigger_code,
					'meta'            => $this->trigger_meta,
					'recipe_to_match' => $recipe_id,
					'ignore_post_id'  => true,
					'user_id'         => $user_id,
				);

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

				if ( $args ) {
					foreach ( $args 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'],
							];

							$trigger_meta['meta_key']   = $this->trigger_code;
							$trigger_meta['meta_value'] = $job_id;
							Automator()->insert_trigger_meta( $trigger_meta );
							Automator()->maybe_trigger_complete( $result['args'] );
							break;
						}
					}
				}
			}
		}
	}