ActionScheduler_ActionFactory::store_unique_action()protectedWC 1.0

Store action if it's unique.

Метод класса: ActionScheduler_ActionFactory{}

Хуков нет.

Возвращает

int. ID of the created action. Will be 0 if action was not created.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->store_unique_action( $action );
$action(ActionScheduler_Action) (обязательный)
Action object to store.

Код ActionScheduler_ActionFactory::store_unique_action() WC 9.0.2

protected function store_unique_action( ActionScheduler_Action $action ) {
	$store = ActionScheduler_Store::instance();
	if ( method_exists( $store, 'save_unique_action' ) ) {
		return $store->save_unique_action( $action );
	} else {
		/**
		 * Fallback to non-unique action if the store doesn't support unique actions.
		 * We try to save the action as unique, accepting that there might be a race condition.
		 * This is likely still better than givinig up on unique actions entirely.
		 */
		$existing_action_id = (int) $store->find_action(
			$action->get_hook(),
			array(
				'args'   => $action->get_args(),
				'status' => ActionScheduler_Store::STATUS_PENDING,
				'group'  => $action->get_group(),
			)
		);
		if ( $existing_action_id > 0 ) {
			return 0;
		}
		return $store->save_action( $action );
	}
}