PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.4
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / ActionScheduler_AdminView.php

ActionScheduler_AdminView.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.4, at app/Services/Libraries/action-scheduler/classes/ActionScheduler_AdminView.php

313 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Third-party library (Action Scheduler)
3
4 /**
5 * Class ActionScheduler_AdminView
6 *
7 * @codeCoverageIgnore
8 */
9 class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
10
11 /**
12 * Instance.
13 *
14 * @var null|self
15 */
16 private static $admin_view = null;
17
18 /**
19 * Screen ID.
20 *
21 * @var string
22 */
23 private static $screen_id = 'tools_page_action-scheduler';
24
25 /**
26 * ActionScheduler_ListTable instance.
27 *
28 * @var ActionScheduler_ListTable
29 */
30 protected $list_table;
31
32 /**
33 * Get instance.
34 *
35 * @return ActionScheduler_AdminView
36 * @codeCoverageIgnore
37 */
38 public static function instance() {
39
40 if ( empty( self::$admin_view ) ) {
41 $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' );
42 self::$admin_view = new $class();
43 }
44
45 return self::$admin_view;
46 }
47
48 /**
49 * Initialize.
50 *
51 * @codeCoverageIgnore
52 */
53 public function init() {
54 if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
55
56 if ( class_exists( 'WooCommerce' ) ) {
57 add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
58 add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
59 add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
60 }
61
62 add_action( 'admin_menu', array( $this, 'register_menu' ) );
63 add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) );
64 add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
65 }
66 }
67
68 /**
69 * Print system status report.
70 */
71 public function system_status_report() {
72 $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
73 $table->render();
74 }
75
76 /**
77 * Registers action-scheduler into WooCommerce > System status.
78 *
79 * @param array $tabs An associative array of tab key => label.
80 * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
81 */
82 public function register_system_status_tab( array $tabs ) {
83 $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
84
85 return $tabs;
86 }
87
88 /**
89 * Include Action Scheduler's administration under the Tools menu.
90 *
91 * A menu under the Tools menu is important for backward compatibility (as that's
92 * where it started), and also provides more convenient access than the WooCommerce
93 * System Status page, and for sites where WooCommerce isn't active.
94 */
95 public function register_menu() {
96 $hook_suffix = add_submenu_page(
97 'tools.php',
98 __( 'Scheduled Actions', 'action-scheduler' ),
99 __( 'Scheduled Actions', 'action-scheduler' ),
100 'manage_options',
101 'action-scheduler',
102 array( $this, 'render_admin_ui' )
103 );
104 add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) );
105 }
106
107 /**
108 * Triggers processing of any pending actions.
109 */
110 public function process_admin_ui() {
111 $this->get_list_table();
112 }
113
114 /**
115 * Renders the Admin UI
116 */
117 public function render_admin_ui() {
118 $table = $this->get_list_table();
119 $table->display_page();
120 }
121
122 /**
123 * Get the admin UI object and process any requested actions.
124 *
125 * @return ActionScheduler_ListTable
126 */
127 protected function get_list_table() {
128 if ( null === $this->list_table ) {
129 $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
130 $this->list_table->process_actions();
131 }
132
133 return $this->list_table;
134 }
135
136 /**
137 * Action: admin_notices
138 *
139 * Maybe check past-due actions, and print notice.
140 *
141 * @uses $this->check_pastdue_actions()
142 */
143 public function maybe_check_pastdue_actions() {
144
145 // Filter to prevent checking actions (ex: inappropriate user).
146 if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
147 return;
148 }
149
150 // Get last check transient.
151 $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );
152
153 // If transient exists, we're within interval, so bail.
154 if ( ! empty( $last_check ) ) {
155 return;
156 }
157
158 // Perform the check.
159 $this->check_pastdue_actions();
160 }
161
162 /**
163 * Check past-due actions, and print notice.
164 */
165 protected function check_pastdue_actions() {
166
167 // Set thresholds.
168 $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
169 $threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
170
171 // Set fallback value for past-due actions count.
172 $num_pastdue_actions = 0;
173
174 // Allow third-parties to preempt the default check logic.
175 $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null );
176
177 // If no third-party preempted and there are no past-due actions, return early.
178 if ( ! is_null( $check ) ) {
179 return;
180 }
181
182 // Scheduled actions query arguments.
183 $query_args = array(
184 'date' => as_get_datetime_object( time() - $threshold_seconds ),
185 'status' => ActionScheduler_Store::STATUS_PENDING,
186 'per_page' => $threshold_min,
187 );
188
189 // If no third-party preempted, run default check.
190 if ( is_null( $check ) ) {
191 $store = ActionScheduler_Store::instance();
192 $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );
193
194 // Check if past-due actions count is greater than or equal to threshold.
195 $check = ( $num_pastdue_actions >= $threshold_min );
196 $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
197 }
198
199 // If check failed, set transient and abort.
200 if ( ! boolval( $check ) ) {
201 $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
202 set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
203
204 return;
205 }
206
207 $actions_url = add_query_arg(
208 array(
209 'page' => 'action-scheduler',
210 'status' => 'past-due',
211 'order' => 'asc',
212 ),
213 admin_url( 'tools.php' )
214 );
215
216 // Print notice.
217 echo '<div class="notice notice-warning"><p>';
218 printf(
219 wp_kses(
220 // translators: 1) is the number of affected actions, 2) is a link to an admin screen.
221 _n(
222 '<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>',
223 '<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>',
224 $num_pastdue_actions,
225 'action-scheduler'
226 ),
227 array(
228 'strong' => array(),
229 'a' => array(
230 'href' => true,
231 'target' => true,
232 ),
233 )
234 ),
235 absint( $num_pastdue_actions ),
236 esc_attr( esc_url( $actions_url ) )
237 );
238 echo '</p></div>';
239
240 // Facilitate third-parties to evaluate and print notices.
241 do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
242 }
243
244 /**
245 * Provide more information about the screen and its data in the help tab.
246 */
247 public function add_help_tabs() {
248 $screen = get_current_screen();
249
250 if ( ! $screen || self::$screen_id !== $screen->id ) {
251 return;
252 }
253
254 $as_version = ActionScheduler_Versions::instance()->latest_version();
255 $as_source = ActionScheduler_SystemInformation::active_source();
256 $as_source_path = ActionScheduler_SystemInformation::active_source_path();
257 $as_source_markup = sprintf( '<code>%s</code>', esc_html( $as_source_path ) );
258
259 if ( ! empty( $as_source ) ) {
260 $as_source_markup = sprintf(
261 '%s: <abbr title="%s">%s</abbr>',
262 ucfirst( $as_source['type'] ),
263 esc_attr( $as_source_path ),
264 esc_html( $as_source['name'] )
265 );
266 }
267
268 $screen->add_help_tab(
269 array(
270 'id' => 'action_scheduler_about',
271 'title' => __( 'About', 'action-scheduler' ),
272 'content' =>
273 // translators: %s is the Action Scheduler version.
274 '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
275 '<p>' .
276 __( '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' ) .
277 '</p>' .
278 '<h3>' . esc_html__( 'Source', 'action-scheduler' ) . '</h3>' .
279 '<p>' .
280 esc_html__( 'Action Scheduler is currently being loaded from the following location. This can be useful when debugging, or if requested by the support team.', 'action-scheduler' ) .
281 '</p>' .
282 '<p>' . $as_source_markup . '</p>' .
283 '<h3>' . esc_html__( 'WP CLI', 'action-scheduler' ) . '</h3>' .
284 '<p>' .
285 sprintf(
286 /* translators: %1$s is WP CLI command (not translatable) */
287 esc_html__( 'WP CLI commands are available: execute %1$s for a list of available commands.', 'action-scheduler' ),
288 '<code>wp help action-scheduler</code>'
289 ) .
290 '</p>',
291 )
292 );
293
294 $screen->add_help_tab(
295 array(
296 'id' => 'action_scheduler_columns',
297 'title' => __( 'Columns', 'action-scheduler' ),
298 'content' =>
299 '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
300 '<ul>' .
301 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
302 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
303 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
304 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
305 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
306 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
307 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
308 '</ul>',
309 )
310 );
311 }
312 }
313