Automattic\WooCommerce\Blocks\Patterns

PTKPatternsStore::schedule_action_if_not_pendingprivateWC 1.0

Schedule an action if it's not already pending.

Method of the class: PTKPatternsStore{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->schedule_action_if_not_pending( $action );
$action(string) (required)
The action name to schedule.

PTKPatternsStore::schedule_action_if_not_pending() code WC 9.9.3

private function schedule_action_if_not_pending( $action ) {
	$last_request = get_transient( 'last_fetch_patterns_request' );
	// The most efficient way to check for an existing action is to use `as_has_scheduled_action`, but in unusual
	// cases where another plugin has loaded a very old version of Action Scheduler, it may not be available to us.

	$has_scheduled_action = function_exists( 'as_has_scheduled_action' ) ? 'as_has_scheduled_action' : 'as_next_scheduled_action';
	if ( call_user_func( $has_scheduled_action, $action ) || false !== $last_request ) {
		return;
	}

	as_schedule_single_action( time(), $action );
	set_transient( 'last_fetch_patterns_request', time(), HOUR_IN_SECONDS );
}