diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php index 5485c100cc0..59ee651522e 100644 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php @@ -132,11 +132,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { protected function make_action_from_post( $post ) { $hook = $post->post_title; $args = json_decode( $post->post_content, true ); - - // Handle args that do not decode properly. - if ( JSON_ERROR_NONE !== json_last_error() || ! is_array( $args ) ) { - throw ActionScheduler_InvalidActionException::from_decoding_args( $post->ID ); - } + $this->validate_args( $args, $post->ID ); $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true ); if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) { @@ -788,4 +784,24 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $taxonomy_registrar = new ActionScheduler_wpPostStore_TaxonomyRegistrar(); $taxonomy_registrar->register(); } + + /** + * Validate that we could decode action arguments. + * + * @param mixed $args The decoded arguments. + * @param int $action_id The action ID. + * + * @throws ActionScheduler_InvalidActionException When the decoded arguments are invalid. + */ + private function validate_args( $args, $action_id ) { + // Ensure we have an array of args. + if ( ! is_array( $args ) ) { + throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id ); + } + + // Validate JSON decoding if possible. + if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) { + throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id ); + } + } }