cancel_scheduled_noptin_action( int|string|array $action_name_id_or_array )
Cancels a scheduled action.
Description Description
This is useful if you need to cancel an action that you had previously scheduled via:-
do_noptin_background_action()
schedule_noptin_background_action()
schedule_noptin_recurring_background_action()
Pass all
as the only argument to cancel all actions scheduled by the above functions.
See also See also
Parameters Parameters
- $action_name_id_or_array
(int|string|array) (Required) (required) The action to cancel. Accepted args:-
- __'all'__ Cancel all actions.
- __$hook_name__ Pass a string to cancel all actions using that hook.
- __$action_id__ Pass an integer to cancel an action by its id.
- __$array__ You can also pass an array of the above. If any element in the array can't be canceled, the function will return false.
Return Return
(bool) True on success. False otherwise.
Source Source
File: includes/functions.php
function cancel_scheduled_noptin_action( $action_name_id_or_array ) { // Ensure the AS db store helper exists. if ( class_exists( 'ActionScheduler_DBStore' ) ) { return false; } // In case the developer wants to cancel all actions. if ( 'all' === $action_name_id_or_array ) { ActionScheduler_DBStore::instance()->cancel_actions_by_group( 'noptin' ); return true; } // In case the developer wants to cancel an action by id. if ( is_numeric( $action_name_id_or_array ) ) { try { ActionScheduler_DBStore::instance()->cancel_action( ( int ) $action_name_id_or_array ); return true; } catch ( InvalidArgumentException $e ) { log_noptin_message( $e->getMessage() ); return false; } } // Developers can also cancel an action by a hook name. if ( is_string( $action_name_id_or_array ) ) { ActionScheduler_DBStore::instance()->cancel_actions_by_hook( $action_name_id_or_array ); return true; } // You can also pass in an array of hooks/action ids. if ( is_array( $action_name_id_or_array ) ) { $result = array_map( 'cancel_scheduled_noptin_action', $action_name_id_or_array ); return ! in_array( false, $result, true ); } // We have an invalid argument. return false; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.2.7 | Introduced. |