Automator_Functions::is_recipe_completed( null $recipe_id = null, null $user_id = null )

Check if the recipe was completed


Parameters Parameters

$recipe_id

(null) (Optional)

Default value: null

$user_id

(null) (Optional)

Default value: null


Top ↑

Return Return

(null|bool)


Source Source

File: src/core/lib/class-automator-functions.php

	public function is_recipe_completed( $recipe_id = null, $user_id = null ) {

		if ( null === $recipe_id || ! is_numeric( $recipe_id ) ) {
			Automator()->error->trigger( 'You are trying to check if a recipe is completed without providing a recipe_id.' );

			return null;
		}

		/**
		 * If recipe is completed maximum number of times, bail.
		 *
		 * @since 3.0
		 */
		if ( $this->is_recipe_completed_max_times( $recipe_id ) ) {
			return true;
		}

		if ( ! is_user_logged_in() ) {
			return null;
		}

		// Set user ID
		if ( is_null( $user_id ) ) {
			$user_id = get_current_user_id();
		}

		global $wpdb;
		$results = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT COUNT(completed) AS num_times_completed
						FROM {$wpdb->prefix}uap_recipe_log
						WHERE 1=1
						AND user_id = %d
						AND automator_recipe_id = %d
						AND completed = 1",
				$user_id,
				$recipe_id
			)
		);

		if ( 0 === $results ) {
			return false;
		}

		$results = empty( $results ) ? 0 : $results;

		return $this->utilities->recipe_number_times_completed( $recipe_id, $results );
	}