PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
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
image-optimization / vendor / woocommerce / action-scheduler / classes / ActionScheduler_AdminView.php

ActionScheduler_AdminView.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at vendor/woocommerce/action-scheduler/classes/ActionScheduler_AdminView.php

261 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_AdminView
5 * @codeCoverageIgnore
6 */
7 class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
8
9 /** @var null|self */
10 private static $admin_view = NULL;
11
12 /** @var string */
13 private static $screen_id = 'tools_page_action-scheduler';
14
15 /** @var ActionScheduler_ListTable */
16 protected $list_table;
17
18 /**
19 * @return ActionScheduler_AdminView
20 * @codeCoverageIgnore
21 */
22 public static function instance() {
23
24 if ( empty( self::$admin_view ) ) {
25 $class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
26 self::$admin_view = new $class();
27 }
28
29 return self::$admin_view;
30 }
31
32 /**
33 * Initialize.
34 *
35 * @codeCoverageIgnore
36 */
37 public function init() {
38 if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
39
40 if ( class_exists( 'WooCommerce' ) ) {
41 add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
42 add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
43 add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
44 }
45
46 add_action( 'admin_menu', array( $this, 'register_menu' ) );
47 add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) );
48 add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
49 }
50 }
51
52 /**
53 * Print system status report.
54 */
55 public function system_status_report() {
56 $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
57 $table->render();
58 }
59
60 /**
61 * Registers action-scheduler into WooCommerce > System status.
62 *
63 * @param array $tabs An associative array of tab key => label.
64 * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
65 */
66 public function register_system_status_tab( array $tabs ) {
67 $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
68
69 return $tabs;
70 }
71
72 /**
73 * Include Action Scheduler's administration under the Tools menu.
74 *
75 * A menu under the Tools menu is important for backward compatibility (as that's
76 * where it started), and also provides more convenient access than the WooCommerce
77 * System Status page, and for sites where WooCommerce isn't active.
78 */
79 public function register_menu() {
80 $hook_suffix = add_submenu_page(
81 'tools.php',
82 __( 'Scheduled Actions', 'action-scheduler' ),
83 __( 'Scheduled Actions', 'action-scheduler' ),
84 'manage_options',
85 'action-scheduler',
86 array( $this, 'render_admin_ui' )
87 );
88 add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
89 }
90
91 /**
92 * Triggers processing of any pending actions.
93 */
94 public function process_admin_ui() {
95 $this->get_list_table();
96 }
97
98 /**
99 * Renders the Admin UI
100 */
101 public function render_admin_ui() {
102 $table = $this->get_list_table();
103 $table->display_page();
104 }
105
106 /**
107 * Get the admin UI object and process any requested actions.
108 *
109 * @return ActionScheduler_ListTable
110 */
111 protected function get_list_table() {
112 if ( null === $this->list_table ) {
113 $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
114 $this->list_table->process_actions();
115 }
116
117 return $this->list_table;
118 }
119
120 /**
121 * Action: admin_notices
122 *
123 * Maybe check past-due actions, and print notice.
124 *
125 * @uses $this->check_pastdue_actions()
126 */
127 public function maybe_check_pastdue_actions() {
128
129 // Filter to prevent checking actions (ex: inappropriate user).
130 if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
131 return;
132 }
133
134 // Get last check transient.
135 $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );
136
137 // If transient exists, we're within interval, so bail.
138 if ( ! empty( $last_check ) ) {
139 return;
140 }
141
142 // Perform the check.
143 $this->check_pastdue_actions();
144 }
145
146 /**
147 * Check past-due actions, and print notice.
148 *
149 * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511)
150 */
151 protected function check_pastdue_actions() {
152
153 // Set thresholds.
154 $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
155 $threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
156
157 // Set fallback value for past-due actions count.
158 $num_pastdue_actions = 0;
159
160 // Allow third-parties to preempt the default check logic.
161 $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null );
162
163 // If no third-party preempted and there are no past-due actions, return early.
164 if ( ! is_null( $check ) ) {
165 return;
166 }
167
168 // Scheduled actions query arguments.
169 $query_args = array(
170 'date' => as_get_datetime_object( time() - $threshold_seconds ),
171 'status' => ActionScheduler_Store::STATUS_PENDING,
172 'per_page' => $threshold_min,
173 );
174
175 // If no third-party preempted, run default check.
176 if ( is_null( $check ) ) {
177 $store = ActionScheduler_Store::instance();
178 $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );
179
180 // Check if past-due actions count is greater than or equal to threshold.
181 $check = ( $num_pastdue_actions >= $threshold_min );
182 $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
183 }
184
185 // If check failed, set transient and abort.
186 if ( ! boolval( $check ) ) {
187 $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
188 set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
189
190 return;
191 }
192
193 $actions_url = add_query_arg( array(
194 'page' => 'action-scheduler',
195 'status' => 'past-due',
196 'order' => 'asc',
197 ), admin_url( 'tools.php' ) );
198
199 // Print notice.
200 echo '<div class="notice notice-warning"><p>';
201 printf(
202 // translators: 1) is the number of affected actions, 2) is a link to an admin screen.
203 _n(
204 '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
205 '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
206 $num_pastdue_actions,
207 'action-scheduler'
208 ),
209 $num_pastdue_actions,
210 esc_attr( esc_url( $actions_url ) )
211 );
212 echo '</p></div>';
213
214 // Facilitate third-parties to evaluate and print notices.
215 do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
216 }
217
218 /**
219 * Provide more information about the screen and its data in the help tab.
220 */
221 public function add_help_tabs() {
222 $screen = get_current_screen();
223
224 if ( ! $screen || self::$screen_id != $screen->id ) {
225 return;
226 }
227
228 $as_version = ActionScheduler_Versions::instance()->latest_version();
229 $screen->add_help_tab(
230 array(
231 'id' => 'action_scheduler_about',
232 'title' => __( 'About', 'action-scheduler' ),
233 'content' =>
234 // translators: %s is the Action Scheduler version.
235 '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
236 '<p>' .
237 __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) .
238 '</p>',
239 )
240 );
241
242 $screen->add_help_tab(
243 array(
244 'id' => 'action_scheduler_columns',
245 'title' => __( 'Columns', 'action-scheduler' ),
246 'content' =>
247 '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
248 '<ul>' .
249 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
250 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
251 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
252 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
253 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
254 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
255 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
256 '</ul>',
257 )
258 );
259 }
260 }
261