PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | classes/async-operation/async-operation.php +64 -2 1.6.01.7.7 View file →
@@ -31,15 +31,15 @@
31 31
32 32 if ( ! in_array( $hook, Async_Operation_Hook::get_values(), true ) ) {
33 33 Logger::log( Logger::LEVEL_ERROR, "Hook $hook is not a part of Async_Operation_Hook values" );
34 34
35 - throw new TypeError( "Hook $hook is not a part of Async_Operation_Hook values" );
35 + throw new TypeError( esc_html( "Hook $hook is not a part of Async_Operation_Hook values" ) );
36 36 }
37 37
38 38 if ( ! in_array( $queue, Async_Operation_Queue::get_values(), true ) ) {
39 39 Logger::log( Logger::LEVEL_ERROR, "Queue $queue is not a part of Async_Operation_Queue values" );
40 40
41 - throw new TypeError( "Queue $queue is not a part of Async_Operation_Queue values" );
41 + throw new TypeError( esc_html( "Queue $queue is not a part of Async_Operation_Queue values" ) );
42 42 }
43 43
44 44 return as_enqueue_async_action(
45 45 $hook,
@@ -49,8 +49,34 @@
49 49 $priority
50 50 );
51 51 }
52 52
53 + public static function create_recurring( int $timestamp, int $interval_in_seconds, string $hook, array $args, string $queue, int $priority = 10, $unique = false ): int {
54 + self::check_library_is_registered();
55 +
56 + if ( ! in_array( $hook, Async_Operation_Hook::get_values(), true ) ) {
57 + Logger::log( Logger::LEVEL_ERROR, "Hook $hook is not a part of Async_Operation_Hook values" );
58 +
59 + throw new TypeError( esc_html( "Hook $hook is not a part of Async_Operation_Hook values" ) );
60 + }
61 +
62 + if ( ! in_array( $queue, Async_Operation_Queue::get_values(), true ) ) {
63 + Logger::log( Logger::LEVEL_ERROR, "Queue $queue is not a part of Async_Operation_Queue values" );
64 +
65 + throw new TypeError( esc_html( "Queue $queue is not a part of Async_Operation_Queue values" ) );
66 + }
67 +
68 + return as_schedule_recurring_action(
69 + $timestamp,
70 + $interval_in_seconds,
71 + $hook,
72 + $args,
73 + $queue,
74 + $unique,
75 + $priority
76 + );
77 + }
78 +
53 79 /**
54 80 * @param Operation_Query_Interface $query
55 81 *
56 82 * @return Async_Operation_Item[]|int[]
@@ -102,8 +128,44 @@
102 128 ->set_logs( $logger->get_logs( $action_id ) );
103 129 }
104 130
105 131 return $actions;
132 + }
133 +
134 + public static function get_by_id( int $action_id ): ?Async_Operation_Item {
135 + self::check_library_is_registered();
136 +
137 + $store = ActionScheduler::store();
138 + $logger = ActionScheduler::logger();
139 +
140 + try {
141 + $action = $store->fetch_action( $action_id );
142 + } catch ( Throwable $t ) {
143 + Logger::log(
144 + Logger::LEVEL_ERROR,
145 + "Unable to fetch an action `$action_id`. Reason: " . $t->getMessage()
146 + );
147 +
148 + return null;
149 + }
150 +
151 + if ( is_a( $action, 'ActionScheduler_NullAction' ) ) {
152 + Logger::log(
153 + Logger::LEVEL_WARN,
154 + 'ActionScheduler_NullAction found'
155 + );
156 +
157 + return null;
158 + }
159 +
160 + return ( new Async_Operation_Item() )
161 + ->set_id( $action_id )
162 + ->set_hook( $action->get_hook() )
163 + ->set_status( $store->get_status( $action_id ) )
164 + ->set_args( $action->get_args() )
165 + ->set_queue( $action->get_group() )
166 + ->set_date( $store->get_date( $action_id ) )
167 + ->set_logs( $logger->get_logs( $action_id ) );
106 168 }
107 169
108 170 /**
109 171 * @throws Async_Operation_Exception