processor (if needed). * * @param string $option Name of the option to add. * @param mixed $value Value of the option. */ private function process_added_option( string $option, $value ) { $this->process_updated_option( false, $value ); } /** * Hooked onto 'delete_option' to remove the batch processor. */ private function process_deleted_option() { $this->process_updated_option( false, false ); } /** * Hooked onto 'update_option' to enqueue the batch processor as needed. * * @param mixed $old_value Previous option value. * @param mixed $new_value New option value. */ private function process_updated_option( $old_value, $new_value ) { $enable = wc_string_to_bool( $new_value ); if ( $enable ) { $this->batch_processing->enqueue_processor( self::class ); } else { $this->batch_processing->remove_processor( self::class ); } } /** * Hooked onto 'pre_update_option' to prevent enabling of the cleanup process when conditions aren't met. * * @param mixed $new_value New option value. * @param mixed $old_value Previous option value. */ private function pre_update_option( $new_value, $old_value ) { return $this->can_run() ? $new_value : 'no'; } /** * Checks whether there are any orders in need of cleanup and cleanup can run. * * @return bool TRUE if there are orders in need of cleanup, FALSE otherwise. */ private function orders_pending() { return ! empty( $this->get_next_batch_to_process( 1 ) ); } /** * Hooked onto 'shutdown' to clean up or set things straight in case of failures (timeouts, etc). */ private function maybe_reset_state() { $is_enqueued = $this->batch_processing->is_enqueued( self::class ); $is_flag_set = $this->is_flag_set(); if ( $is_enqueued xor $is_flag_set ) { $this->toggle_flag( false ); $this->batch_processing->remove_processor( self::class ); } } }
No account yet?
Create an Account