$hook, 'status' => \ActionScheduler_Store::STATUS_PENDING, 'per_page' => 1, ], ); // Also check in-progress actions — on fast environments the task may // already be running by the time the next page load checks. if ( empty( $next_action ) || ! is_array( $next_action ) ) { $next_action = as_get_scheduled_actions( [ 'hook' => $hook, 'status' => \ActionScheduler_Store::STATUS_RUNNING, 'per_page' => 1, ], ); } if ( empty( $next_action ) || ! is_array( $next_action ) ) { return false; } // find out if any actions get_args() has 'show_notice' => true. $show_notice = false; foreach ( $next_action as $action ) { $args = $action->get_args(); if ( isset( $args['show_notice'] ) && ! empty( $args['show_notice'] ) ) { $show_notice = true; break; } } return $show_notice; } /** * Check if there are any failed actions for a given hook and group. * * @param string $hook The hook that the job will trigger. * @param string $group The group the job is assigned to (if any). * @return bool True if there are any failed actions, false otherwise. */ public function hasFailedActions( $hook, $group = '' ) { $args = [ 'hook' => $hook, 'group' => $group, 'status' => \ActionScheduler_Store::STATUS_FAILED, 'per_page' => 1, // We only need to know if at least one exists. ]; $failed_actions = $this->search( $args, 'ids' ); return ! empty( $failed_actions ); } /** * Find scheduled actions * * @param array $args Possible arguments, with their default values: * 'hook' => '' - the name of the action that will be triggered * 'args' => null - the args array that will be passed with the action * 'date' => null - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '=' * 'modified' => null - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '=' * 'group' => '' - the group the action belongs to * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING * 'claimed' => null - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID * 'per_page' => 5 - Number of results to return * 'offset' => 0 * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date' * 'order' => 'ASC'. * * @param string $return_format OBJECT, ARRAY_A, or ids. * @return array */ public function search( $args = array(), $return_format = OBJECT ) { return \as_get_scheduled_actions( $args, $return_format ); } /** * Start running the queue immediately. * * @return void */ public function run() { $identifier = 'as_async_request_queue_runner'; // make an async request to run the queue. wp_remote_post( esc_url_raw( add_query_arg( [ 'action' => $identifier, 'nonce' => wp_create_nonce( $identifier ), ], admin_url( 'admin-ajax.php' ) ) ), array( 'timeout' => 0.01, 'blocking' => false, 'cookies' => $_COOKIE, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), ) ); } }