ActionScheduler_ActionFactory::store_unique_action
Store action if it's unique.
Method of the class: ActionScheduler_ActionFactory{}
No Hooks.
Returns
Int. ID of the created action. Will be 0 if action was not created.
Usage
// protected - for code of main (parent) or child class $result = $this->store_unique_action( $action );
- $action(ActionScheduler_Action) (required)
- Action object to store.
ActionScheduler_ActionFactory::store_unique_action() ActionScheduler ActionFactory::store unique action code WC 10.6.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 giving 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 );
}
}