@@ -191,6 +191,9 @@ public function settings_init() {
191191 // Setup General Settings.
192192 $ this ->setup_general_settings ();
193193
194+ // Add Action Scheduler information section.
195+ $ this ->setup_action_scheduler_settings ();
196+
194197 $ active_subtab = isset ( $ _GET ['subtab ' ] ) ? sanitize_text_field ( wp_unslash ( $ _GET ['subtab ' ] ) ) : '' ; // phpcs:ignore WordPress.Security.NonceVerification
195198
196199 switch ( $ active_subtab ) {
@@ -358,6 +361,110 @@ private function setup_design_global_settings() {
358361 }
359362
360363
364+ /**
365+ * Setup Action Scheduler information section
366+ *
367+ * @since 1.8.0
368+ */
369+ private function setup_action_scheduler_settings () {
370+ $ tab_section = 'courier_settings ' ;
371+
372+ // Action Scheduler Information Section.
373+ add_settings_section (
374+ 'courier_action_scheduler_settings ' ,
375+ esc_html__ ( 'Action Scheduler ' , 'courier-notices ' ),
376+ array ( $ this , 'create_action_scheduler_section ' ),
377+ 'courier '
378+ );
379+
380+ add_settings_field (
381+ 'action_scheduler_info ' ,
382+ esc_html__ ( 'Status ' , 'courier-notices ' ),
383+ array ( $ this , 'render_action_scheduler_info ' ),
384+ 'courier ' ,
385+ 'courier_action_scheduler_settings ' ,
386+ array (
387+ 'field ' => 'action_scheduler_info ' ,
388+ 'section ' => $ tab_section ,
389+ 'class ' => 'action-scheduler-info ' ,
390+ 'label ' => esc_html__ ( 'Action Scheduler Status ' , 'courier-notices ' ),
391+ 'description ' => esc_html__ ( 'Information about the Action Scheduler integration. ' , 'courier-notices ' ),
392+ )
393+ );
394+ }
395+
396+ /**
397+ * Create Action Scheduler section
398+ *
399+ * @since 1.8.0
400+ *
401+ * @param array $args Array of arguments.
402+ */
403+ public function create_action_scheduler_section ( $ args ) {
404+ if ( ! empty ( $ args ['title ' ] ) ) {
405+ ?>
406+ <div class="gray-bg negative-bg">
407+ <div class="wrapper">
408+ <h2 class="light-weight">
409+ <?php echo esc_html ( $ args ['title ' ] ); ?>
410+ </h2>
411+ </div>
412+ </div>
413+ <?php
414+ }
415+ }
416+
417+ /**
418+ * Render Action Scheduler information
419+ *
420+ * @since 1.8.0
421+ *
422+ * @param array $args Array of arguments.
423+ */
424+ public function render_action_scheduler_info ( $ args ) {
425+ $ plugin_options = get_option ( 'courier_notices_options ' , [] );
426+ $ use_action_scheduler = ! empty ( $ plugin_options ['use_action_scheduler ' ] );
427+ $ action_scheduler_available = class_exists ( 'ActionScheduler ' );
428+
429+ ?>
430+ <div class="action-scheduler-info">
431+ <?php if ( $ action_scheduler_available ) : ?>
432+ <div class="notice notice-success inline">
433+ <p>
434+ <strong><?php esc_html_e ( 'Action Scheduler is available. ' , 'courier-notices ' ); ?> </strong>
435+ <?php if ( $ use_action_scheduler ) : ?>
436+ <?php esc_html_e ( 'Courier Notices is using Action Scheduler for scheduled tasks. ' , 'courier-notices ' ); ?>
437+ <?php else : ?>
438+ <?php esc_html_e ( 'Courier Notices is using WordPress Cron for scheduled tasks. ' , 'courier-notices ' ); ?>
439+ <?php endif ; ?>
440+ </p>
441+ </div>
442+ <p>
443+ <?php if ( $ use_action_scheduler ) : ?>
444+ <a href="<?php echo esc_url ( admin_url ( 'tools.php?page=action-scheduler ' ) ); ?> " class="button button-secondary">
445+ <?php esc_html_e ( 'View Scheduled Actions ' , 'courier-notices ' ); ?>
446+ </a>
447+ <?php else : ?>
448+ <a href="<?php echo esc_url ( admin_url ( 'tools.php?page=action-scheduler ' ) ); ?> " class="button button-secondary">
449+ <?php esc_html_e ( 'View Action Scheduler ' , 'courier-notices ' ); ?>
450+ </a>
451+ <?php endif ; ?>
452+ </p>
453+ <?php else : ?>
454+ <div class="notice notice-warning inline">
455+ <p>
456+ <strong><?php esc_html_e ( 'Action Scheduler is not available. ' , 'courier-notices ' ); ?> </strong>
457+ <?php esc_html_e ( 'Courier Notices is using WordPress Cron for scheduled tasks. ' , 'courier-notices ' ); ?>
458+ </p>
459+ </div>
460+ <p>
461+ <?php esc_html_e ( 'To use Action Scheduler for better reliability and scalability, install WooCommerce or another plugin that provides Action Scheduler. ' , 'courier-notices ' ); ?>
462+ </p>
463+ <?php endif ; ?>
464+ </div>
465+ <?php
466+ }
467+
361468 /**
362469 * Setup our different types of informational courier notices
363470 *
@@ -502,6 +609,15 @@ public static function get_tabs() {
502609 ),
503610 );
504611
612+ // Add Action Scheduler tab if Action Scheduler is available.
613+ if ( class_exists ( 'ActionScheduler ' ) ) {
614+ $ tabs ['action_scheduler ' ] = array (
615+ 'url ' => admin_url ( 'tools.php?page=action-scheduler ' ),
616+ 'label ' => esc_html__ ( 'Action Scheduler ' , 'courier-notices ' ),
617+ 'sub_tabs ' => array (),
618+ );
619+ }
620+
505621 return apply_filters ( 'courier_notices_settings_tabs ' , $ tabs );
506622 }
507623
0 commit comments