PluginProbe
WANotifier for Forms and Actions / 3.1.1
WANotifier for Forms and Actions v3.1.1
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
← All changes | libraries/action-scheduler/classes/ActionScheduler_AdminView.php +98 -38 2.7.93.1.1 View file →
@@ -1,20 +1,37 @@
1 1 <?php
2 2
3 3 /**
4 4 * Class ActionScheduler_AdminView
5 + *
5 6 * @codeCoverageIgnore
6 7 */
7 8 class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
8 9
9 - private static $admin_view = NULL;
10 + /**
11 + * Instance.
12 + *
13 + * @var null|self
14 + */
15 + private static $admin_view = null;
10 16
17 + /**
18 + * Screen ID.
19 + *
20 + * @var string
21 + */
11 22 private static $screen_id = 'tools_page_action-scheduler';
12 23
13 - /** @var ActionScheduler_ListTable */
24 + /**
25 + * ActionScheduler_ListTable instance.
26 + *
27 + * @var ActionScheduler_ListTable
28 + */
14 29 protected $list_table;
15 30
16 31 /**
32 + * Get instance.
33 + *
17 34 * @return ActionScheduler_AdminView
18 35 * @codeCoverageIgnore
19 36 */
20 37 public static function instance() {
@@ -19,9 +36,9 @@
19 36 */
20 37 public static function instance() {
21 38
22 39 if ( empty( self::$admin_view ) ) {
23 - $class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
40 + $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' );
24 41 self::$admin_view = new $class();
25 42 }
26 43
27 44 return self::$admin_view;
@@ -27,12 +44,14 @@
27 44 return self::$admin_view;
28 45 }
29 46
30 47 /**
48 + * Initialize.
49 + *
31 50 * @codeCoverageIgnore
32 51 */
33 52 public function init() {
34 - if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
53 + if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
35 54
36 55 if ( class_exists( 'WooCommerce' ) ) {
37 56 add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
38 57 add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
@@ -44,8 +63,11 @@
44 63 add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
45 64 }
46 65 }
47 66
67 + /**
68 + * Print system status report.
69 + */
48 70 public function system_status_report() {
49 71 $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
50 72 $table->render();
51 73 }
@@ -77,9 +99,9 @@
77 99 'manage_options',
78 100 'action-scheduler',
79 101 array( $this, 'render_admin_ui' )
80 102 );
81 - add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
103 + add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) );
82 104 }
83 105
84 106 /**
85 107 * Triggers processing of any pending actions.
@@ -118,35 +140,33 @@
118 140 * @uses $this->check_pastdue_actions()
119 141 */
120 142 public function maybe_check_pastdue_actions() {
121 143
122 - # Filter to prevent checking actions (ex: inappropriate user).
144 + // Filter to prevent checking actions (ex: inappropriate user).
123 145 if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
124 146 return;
125 147 }
126 148
127 - # Get last check transient.
149 + // Get last check transient.
128 150 $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );
129 151
130 - # If transient exists, we're within interval, so bail.
152 + // If transient exists, we're within interval, so bail.
131 153 if ( ! empty( $last_check ) ) {
132 154 return;
133 155 }
134 156
135 - # Perform the check.
157 + // Perform the check.
136 158 $this->check_pastdue_actions();
137 159 }
138 160
139 161 /**
140 162 * Check past-due actions, and print notice.
141 - *
142 - * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511)
143 163 */
144 164 protected function check_pastdue_actions() {
145 165
146 - # Set thresholds.
147 - $threshold_seconds = ( int ) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
148 - $threshhold_min = ( int ) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
166 + // Set thresholds.
167 + $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
168 + $threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
149 169
150 170 // Set fallback value for past-due actions count.
151 171 $num_pastdue_actions = 0;
152 172
@@ -157,26 +177,26 @@
157 177 if ( ! is_null( $check ) ) {
158 178 return;
159 179 }
160 180
161 - # Scheduled actions query arguments.
181 + // Scheduled actions query arguments.
162 182 $query_args = array(
163 183 'date' => as_get_datetime_object( time() - $threshold_seconds ),
164 184 'status' => ActionScheduler_Store::STATUS_PENDING,
165 - 'per_page' => $threshhold_min,
185 + 'per_page' => $threshold_min,
166 186 );
167 187
168 - # If no third-party preempted, run default check.
188 + // If no third-party preempted, run default check.
169 189 if ( is_null( $check ) ) {
170 - $store = ActionScheduler_Store::instance();
171 - $num_pastdue_actions = ( int ) $store->query_actions( $query_args, 'count' );
190 + $store = ActionScheduler_Store::instance();
191 + $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );
172 192
173 - # Check if past-due actions count is greater than or equal to threshold.
174 - $check = ( $num_pastdue_actions >= $threshhold_min );
175 - $check = ( bool ) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min );
193 + // Check if past-due actions count is greater than or equal to threshold.
194 + $check = ( $num_pastdue_actions >= $threshold_min );
195 + $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
176 196 }
177 197
178 - # If check failed, set transient and abort.
198 + // If check failed, set transient and abort.
179 199 if ( ! boolval( $check ) ) {
180 200 $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
181 201 set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
182 202
@@ -182,30 +202,43 @@
182 202
183 203 return;
184 204 }
185 205
186 - $actions_url = add_query_arg( array(
187 - 'page' => 'action-scheduler',
188 - 'status' => 'past-due',
189 - 'order' => 'asc',
190 - ), admin_url( 'tools.php' ) );
206 + $actions_url = add_query_arg(
207 + array(
208 + 'page' => 'action-scheduler',
209 + 'status' => 'past-due',
210 + 'order' => 'asc',
211 + ),
212 + admin_url( 'tools.php' )
213 + );
191 214
192 - # Print notice.
193 - echo '<div class="notice notice-warning"><p>';
194 - printf(
215 + // Print notice.
216 + $message = wp_kses(
217 + // translators: 1) is the number of affected actions, 2) is a link to an admin screen.
195 218 _n(
196 - // translators: 1) is the number of affected actions, 2) is a link to an admin screen.
197 219 '<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>',
198 220 '<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>',
199 221 $num_pastdue_actions,
200 222 'action-scheduler'
201 223 ),
202 - $num_pastdue_actions,
203 - esc_attr( esc_url( $actions_url ) )
224 + array(
225 + 'strong' => array(),
226 + 'a' => array(
227 + 'href' => true,
228 + 'target' => true,
229 + ),
230 + )
204 231 );
205 - echo '</p></div>';
232 + wp_admin_notice(
233 + $message,
234 + array(
235 + 'type' => 'warning',
236 + 'paragraph_wrap' => true,
237 + )
238 + );
206 239
207 - # Facilitate third-parties to evaluate and print notices.
240 + // Facilitate third-parties to evaluate and print notices.
208 241 do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
209 242 }
210 243
211 244 /**
@@ -213,21 +246,48 @@
213 246 */
214 247 public function add_help_tabs() {
215 248 $screen = get_current_screen();
216 249
217 - if ( ! $screen || self::$screen_id != $screen->id ) {
250 + if ( ! $screen || self::$screen_id !== $screen->id ) {
218 251 return;
219 252 }
220 253
221 - $as_version = ActionScheduler_Versions::instance()->latest_version();
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 +
222 268 $screen->add_help_tab(
223 269 array(
224 270 'id' => 'action_scheduler_about',
225 271 'title' => __( 'About', 'action-scheduler' ),
226 272 'content' =>
273 + // translators: %s is the Action Scheduler version.
227 274 '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
228 275 '<p>' .
229 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 + ) .
230 290 '</p>',
231 291 )
232 292 );
233 293