PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.1
2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / lib / action-scheduler / classes / ActionScheduler_AdminView.php
sureforms / inc / lib / action-scheduler / classes Last commit date
WP_CLI 2 years ago abstracts 4 months ago actions 2 years ago data-stores 2 years ago migration 2 years ago schedules 2 years ago schema 2 years ago ActionScheduler_ActionClaim.php 2 years ago ActionScheduler_ActionFactory.php 2 years ago ActionScheduler_AdminView.php 2 years ago ActionScheduler_AsyncRequest_QueueRunner.php 2 years ago ActionScheduler_Compatibility.php 2 years ago ActionScheduler_DataController.php 2 years ago ActionScheduler_DateTime.php 2 years ago ActionScheduler_Exception.php 2 years ago ActionScheduler_FatalErrorMonitor.php 2 years ago ActionScheduler_InvalidActionException.php 2 years ago ActionScheduler_ListTable.php 2 years ago ActionScheduler_LogEntry.php 2 years ago ActionScheduler_NullLogEntry.php 2 years ago ActionScheduler_OptionLock.php 2 years ago ActionScheduler_QueueCleaner.php 2 years ago ActionScheduler_QueueRunner.php 2 years ago ActionScheduler_Versions.php 2 years ago ActionScheduler_WPCommentCleaner.php 2 years ago ActionScheduler_wcSystemStatus.php 2 years ago
ActionScheduler_AdminView.php
257 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_AdminView
5 *
6 * @codeCoverageIgnore
7 */
8 class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
9
10 private static $admin_view = null;
11
12 private static $screen_id = 'tools_page_action-scheduler';
13
14 /** @var ActionScheduler_ListTable */
15 protected $list_table;
16
17 /**
18 * @return ActionScheduler_AdminView
19 * @codeCoverageIgnore
20 */
21 public static function instance() {
22
23 if ( empty( self::$admin_view ) ) {
24 $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' );
25 self::$admin_view = new $class();
26 }
27
28 return self::$admin_view;
29 }
30
31 /**
32 * @codeCoverageIgnore
33 */
34 public function init() {
35 if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
36
37 if ( class_exists( 'WooCommerce' ) ) {
38 add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
39 add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
40 add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
41 }
42
43 add_action( 'admin_menu', array( $this, 'register_menu' ) );
44 add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) );
45 add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
46 }
47 }
48
49 public function system_status_report() {
50 $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
51 $table->render();
52 }
53
54 /**
55 * Registers action-scheduler into WooCommerce > System status.
56 *
57 * @param array $tabs An associative array of tab key => label.
58 * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
59 */
60 public function register_system_status_tab( array $tabs ) {
61 $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
62
63 return $tabs;
64 }
65
66 /**
67 * Include Action Scheduler's administration under the Tools menu.
68 *
69 * A menu under the Tools menu is important for backward compatibility (as that's
70 * where it started), and also provides more convenient access than the WooCommerce
71 * System Status page, and for sites where WooCommerce isn't active.
72 */
73 public function register_menu() {
74 $hook_suffix = add_submenu_page(
75 'tools.php',
76 __( 'Scheduled Actions', 'action-scheduler' ),
77 __( 'Scheduled Actions', 'action-scheduler' ),
78 'manage_options',
79 'action-scheduler',
80 array( $this, 'render_admin_ui' )
81 );
82 add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) );
83 }
84
85 /**
86 * Triggers processing of any pending actions.
87 */
88 public function process_admin_ui() {
89 $this->get_list_table();
90 }
91
92 /**
93 * Renders the Admin UI
94 */
95 public function render_admin_ui() {
96 $table = $this->get_list_table();
97 $table->display_page();
98 }
99
100 /**
101 * Get the admin UI object and process any requested actions.
102 *
103 * @return ActionScheduler_ListTable
104 */
105 protected function get_list_table() {
106 if ( null === $this->list_table ) {
107 $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
108 $this->list_table->process_actions();
109 }
110
111 return $this->list_table;
112 }
113
114 /**
115 * Action: admin_notices
116 *
117 * Maybe check past-due actions, and print notice.
118 *
119 * @uses $this->check_pastdue_actions()
120 */
121 public function maybe_check_pastdue_actions() {
122
123 // Filter to prevent checking actions (ex: inappropriate user).
124 if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
125 return;
126 }
127
128 // Get last check transient.
129 $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );
130
131 // If transient exists, we're within interval, so bail.
132 if ( ! empty( $last_check ) ) {
133 return;
134 }
135
136 // Perform the check.
137 $this->check_pastdue_actions();
138 }
139
140 /**
141 * Check past-due actions, and print notice.
142 *
143 * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511)
144 */
145 protected function check_pastdue_actions() {
146
147 // Set thresholds.
148 $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
149 $threshhold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
150
151 // Set fallback value for past-due actions count.
152 $num_pastdue_actions = 0;
153
154 // Allow third-parties to preempt the default check logic.
155 $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null );
156
157 // If no third-party preempted and there are no past-due actions, return early.
158 if ( ! is_null( $check ) ) {
159 return;
160 }
161
162 // Scheduled actions query arguments.
163 $query_args = array(
164 'date' => as_get_datetime_object( time() - $threshold_seconds ),
165 'status' => ActionScheduler_Store::STATUS_PENDING,
166 'per_page' => $threshhold_min,
167 );
168
169 // If no third-party preempted, run default check.
170 if ( is_null( $check ) ) {
171 $store = ActionScheduler_Store::instance();
172 $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );
173
174 // Check if past-due actions count is greater than or equal to threshold.
175 $check = ( $num_pastdue_actions >= $threshhold_min );
176 $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min );
177 }
178
179 // If check failed, set transient and abort.
180 if ( ! boolval( $check ) ) {
181 $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
182 set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
183
184 return;
185 }
186
187 $actions_url = add_query_arg(
188 array(
189 'page' => 'action-scheduler',
190 'status' => 'past-due',
191 'order' => 'asc',
192 ),
193 admin_url( 'tools.php' )
194 );
195
196 // Print notice.
197 echo '<div class="notice notice-warning"><p>';
198 printf(
199 _n(
200 // translators: 1) is the number of affected actions, 2) is a link to an admin screen.
201 '<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>',
202 '<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>',
203 $num_pastdue_actions,
204 'action-scheduler'
205 ),
206 $num_pastdue_actions,
207 esc_attr( esc_url( $actions_url ) )
208 );
209 echo '</p></div>';
210
211 // Facilitate third-parties to evaluate and print notices.
212 do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
213 }
214
215 /**
216 * Provide more information about the screen and its data in the help tab.
217 */
218 public function add_help_tabs() {
219 $screen = get_current_screen();
220
221 if ( ! $screen || self::$screen_id != $screen->id ) {
222 return;
223 }
224
225 $as_version = ActionScheduler_Versions::instance()->latest_version();
226 $screen->add_help_tab(
227 array(
228 'id' => 'action_scheduler_about',
229 'title' => __( 'About', 'action-scheduler' ),
230 'content' =>
231 '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
232 '<p>' .
233 __( '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' ) .
234 '</p>',
235 )
236 );
237
238 $screen->add_help_tab(
239 array(
240 'id' => 'action_scheduler_columns',
241 'title' => __( 'Columns', 'action-scheduler' ),
242 'content' =>
243 '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
244 '<ul>' .
245 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
246 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
247 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
248 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
249 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
250 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
251 sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
252 '</ul>',
253 )
254 );
255 }
256 }
257