Changeset 3317252
- Timestamp:
- 06/24/2025 11:00:19 PM (9 months ago)
- Location:
- wp-cron-pixie
- Files:
-
- 11 added
- 1 deleted
- 4 edited
-
tags/1.5.0 (added)
-
tags/1.5.0/README.txt (added)
-
tags/1.5.0/css (added)
-
tags/1.5.0/css/main.css (added)
-
tags/1.5.0/includes (added)
-
tags/1.5.0/includes/class-cron-pixie.php (added)
-
tags/1.5.0/js (added)
-
tags/1.5.0/js/main.js (added)
-
tags/1.5.0/js/ui.js (added)
-
tags/1.5.0/wp-cron-pixie.php (added)
-
trunk/README.txt (modified) (6 diffs)
-
trunk/includes/class-cron-pixie.php (modified) (22 diffs)
-
trunk/js/CronPixie.js (deleted)
-
trunk/js/main.js (modified) (1 diff)
-
trunk/js/ui.js (added)
-
trunk/wp-cron-pixie.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-cron-pixie/trunk/README.txt
r3219061 r3317252 1 === Plugin Name ===1 === WP Cron Pixie === 2 2 Contributors: ianmjones 3 3 Donate link: https://ianmjones.com/ 4 4 Tags: cron, wp-cron, dashboard, admin, widget 5 Requires at least: 5.36 Tested up to: 6. 77 Stable tag: 1. 4.48 Requires PHP: 5.69 License: GPLv2 or later10 License URI: http ://www.gnu.org/licenses/gpl-2.0.html5 Requires at least: 6.0 6 Tested up to: 6.8 7 Stable tag: 1.5.0 8 Requires PHP: 7.4 9 License: MIT 10 License URI: https://mit-license.org/ 11 11 12 12 A little dashboard widget to view the WordPress cron. … … 22 22 1. [Building Reactive WordPress Plugins – Part 3 – Elm](https://deliciousbrains.com/building-reactive-wordpress-plugins-part-3-elm/) 23 23 24 The current version is using Gleam on the front end. 25 24 26 == Installation == 25 27 … … 31 33 = From WordPress.org = 32 34 1. Download WP Cron Pixie. 33 1. Upload the 'wp-cron-pixie' directory to your '/wp-content/plugins/' directory, using your favo rite method (ftp, sftp, scp, etc...)35 1. Upload the 'wp-cron-pixie' directory to your '/wp-content/plugins/' directory, using your favourite method (ftp, sftp, scp, etc...) 34 36 1. Activate WP Cron Pixie from your Plugins page. 35 37 … … 45 47 46 48 == Changelog == 49 50 = 1.5.0 = 51 * Gleam front end. 52 * Fixed "Error message: Event schedule does not exist." debug.log messages when example events enabled. 53 * Fixed example events not being removed from cron schedules after turning them off. 54 * Tested with WP 6.8 55 * Requires WP 6.0+ 56 * Requires PHP 7.4+ 47 57 48 58 = 1.4.4 = … … 67 77 * Added "Refresh" icon for manual refresh of data. 68 78 * Fixed not all strings in UI being translatable. 69 * Elm 0.19 front end.79 * Elm 0.19 front end. 70 80 71 81 = 1.3.1 = … … 74 84 75 85 = 1.3 = 76 * Elm 0.18 front end.86 * Elm 0.18 front end. 77 87 78 88 = 1.2 = 79 * Elm front end.89 * Elm front end. 80 90 81 91 = 1.1 = 82 * Vue.js front end.92 * Vue.js front end. 83 93 84 94 = 1.0 = 85 95 * Initial release. 86 * Backbone.js front end.96 * Backbone.js front end. -
wp-cron-pixie/trunk/includes/class-cron-pixie.php
r2808278 r3317252 1 1 <?php 2 2 /** 3 * Cron_Pixie class file. 4 * 5 * @package Cron_Pixie 6 */ 7 8 namespace Cron_Pixie; 9 10 use WP_Error; 11 12 /** 13 * Cron_Pixie class. 14 */ 3 15 class Cron_Pixie { 16 /** 17 * The context for our nonce. 18 * 19 * @var string 20 */ 21 const NONCE_CONTEXT = 'cron-pixie'; 4 22 5 23 /** … … 13 31 * Often used plugin info. 14 32 * 15 * @var array 16 */ 17 private $plugin_meta;33 * @var array<string, string> 34 */ 35 private array $plugin_meta; 18 36 19 37 /** 20 38 * Cron_Pixie constructor. 21 39 * 22 * Registers all action and filter hooks if user can use widget.23 * 24 * @param array $plugin_meta25 */ 26 public function __construct( $plugin_meta = array() ) {40 * Bare minimum to set up cron schedule for example events. 41 * 42 * @param array<string, string> $plugin_meta Plugin's meta data. 43 */ 44 public function __construct( array $plugin_meta = array() ) { 27 45 if ( empty( $plugin_meta ) ) { 28 46 return; … … 31 49 $this->plugin_meta = $plugin_meta; 32 50 51 // Add a schedule of our own for testing. 52 add_filter( 'cron_schedules', array( $this, 'filter_cron_schedules' ) ); 53 54 // Process the "passed" event so that we can reschedule for the past again. 55 add_action( 'cron_pixie_passed_event', array( $this, 'reschedule_passed_event' ) ); 56 } 57 58 /** 59 * Init the plugin, if being loaded in the right context. 60 * 61 * Registers all action and filter hooks if user can use widget. 62 * 63 * @return void 64 */ 65 public function init(): void { 33 66 // Using the plugin in the network admin dashboard makes no sense. 34 67 if ( is_network_admin() ) { … … 48 81 49 82 // AJAX handlers. 50 add_action( 'wp_ajax_cron_pixie_schedules', array( $this, 'ajax_schedules' ) ); 51 add_action( 'wp_ajax_cron_pixie_events', array( $this, 'ajax_events' ) ); 52 add_action( 'wp_ajax_cron_pixie_example_events', array( $this, 'ajax_example_events' ) ); 53 add_action( 'wp_ajax_cron_pixie_auto_refresh', array( $this, 'ajax_auto_refresh' ) ); 54 55 if ( $this->_get_setting( 'example_events' ) ) { 56 // Add a schedule of our own for testing. 57 add_filter( 'cron_schedules', array( $this, 'filter_cron_schedules' ) ); 58 59 // Add events to our test schedule. 60 $this->_create_test_events(); 61 } else { 62 // Remove events from our test schedule. 63 $this->_remove_test_events(); 64 } 83 add_action( 'wp_ajax_cron_pixie_get_schedules', array( $this, 'ajax_get_schedules' ) ); 84 add_action( 'wp_ajax_cron_pixie_update_event', array( $this, 'ajax_update_event' ) ); 85 add_action( 'wp_ajax_cron_pixie_update_example_events_setting', array( $this, 'ajax_update_example_events_setting' ) ); 86 add_action( 'wp_ajax_cron_pixie_update_auto_refresh_setting', array( $this, 'ajax_update_auto_refresh_setting' ) ); 65 87 } 66 88 … … 68 90 * Registers the widget and content callback. 69 91 */ 70 public function add_dashboard_widget() { 71 92 public function add_dashboard_widget(): void { 72 93 wp_add_dashboard_widget( 73 94 $this->plugin_meta['slug'], … … 80 101 * Provides the initial content for the widget. 81 102 */ 82 public function dashboard_widget_content() {103 public function dashboard_widget_content(): void { 83 104 ?> 84 105 <!-- Main content --> … … 90 111 * Enqueues the JS scripts when the main dashboard page is loading. 91 112 * 92 * @param string $hook_page 93 */ 94 public function enqueue_scripts( $hook_page ){113 * @param string $hook_page Current page hook. 114 */ 115 public function enqueue_scripts( string $hook_page ): void { 95 116 if ( 'index.php' !== $hook_page ) { 96 117 return; … … 109 130 $script_handle, 110 131 plugin_dir_url( $this->plugin_meta['file'] ) . 'js/main.js', 111 array(),112 $this->plugin_meta['version'],113 true // Load JS in footer so that templates in DOM can be referenced.114 );115 116 wp_enqueue_script(117 $script_handle . '-build',118 plugin_dir_url( $this->plugin_meta['file'] ) . 'js/CronPixie.js',119 132 array(), 120 133 $this->plugin_meta['version'], … … 138 151 'refresh' => _x( 'Refresh Now', 'Tooltip for refresh now icon', 'wp-cron-pixie' ), 139 152 'schedules' => _x( 'Schedules', 'Title for list of schedules', 'wp-cron-pixie' ), 140 'example_events' => _x( 'Example Events', 'Label for Example Events checkbox', 'wp-cron-pixie' ), 141 'example_events_tooltip' => _x( 'Include some example events in the cron schedule', 'Tooltip for Example Events checkbox', 'wp-cron-pixie' ), 153 'example_events' => _x( 154 'Example Events', 155 'Label for Example Events checkbox', 156 'wp-cron-pixie' 157 ), 158 'example_events_tooltip' => _x( 159 'Include some example events in the cron schedule', 160 'Tooltip for Example Events checkbox', 161 'wp-cron-pixie' 162 ), 142 163 'auto_refresh' => _x( 'Auto Refresh', 'Label for Auto Refresh checkbox', 'wp-cron-pixie' ), 143 'auto_refresh_tooltip' => _x( 'Refresh the display of cron events every 5 seconds', 'Tooltip for Auto Refresh checkbox', 'wp-cron-pixie' ), 164 'auto_refresh_tooltip' => _x( 165 'Refresh the display of cron events every 5 seconds', 166 'Tooltip for Auto Refresh checkbox', 167 'wp-cron-pixie' 168 ), 144 169 ), 145 170 'admin_url' => untrailingslashit( admin_url() ), 146 'nonce' => wp_create_nonce( 'cron-pixie'),171 'nonce' => wp_create_nonce( self::NONCE_CONTEXT ), 147 172 'timer_period' => 5, // How often should display be updated, in seconds. 148 173 'data' => array( 149 'schedules' => $this-> _get_schedules(),174 'schedules' => $this->get_schedules(), 150 175 ), 151 'example_events' => (bool) $this->_get_setting( 'example_events' ), 152 'auto_refresh' => (bool) $this->_get_setting( 'auto_refresh' ), 176 'example_events' => (bool) $this->get_setting( 'example_events' ), 177 'auto_refresh' => (bool) $this->get_setting( 'auto_refresh' ), 178 'version' => $this->plugin_meta['version'], 153 179 ); 154 180 wp_localize_script( $script_handle, 'CronPixie', $data ); … … 158 184 * Returns list of cron schedules. 159 185 * 160 * @return array 161 */ 162 private function _get_schedules() { 186 * @return array<array<string, mixed>> 187 */ 188 private function get_schedules(): array { 189 // If we're getting schedules, widget should be visible. 190 // Therefore we may or may not want our example events available. 191 $this->manage_example_events(); 192 163 193 // Get list of schedules. 164 194 $schedules = wp_get_schedules(); … … 179 209 foreach ( $cron_array as $timestamp => $jobs ) { 180 210 foreach ( $jobs as $hook => $events ) { 181 foreach ( $events as $ key => $event ) {211 foreach ( $events as $event ) { 182 212 $event['hook'] = $hook; 183 213 $event['timestamp'] = $timestamp; … … 193 223 194 224 // We need to change the associative array (map) into an indexed one (set) for easier use in collection. 225 // And if any schedles are empty, might as well drop them too. 195 226 $set = array(); 196 227 foreach ( $schedules as $name => $schedule ) { 228 if ( empty( $schedule['events'] ) ) { 229 continue; 230 } 231 197 232 $schedule['name'] = $name; 198 233 $set[] = $schedule; … … 205 240 * Send a response to ajax request, as JSON. 206 241 * 207 * @param mixed $response 208 */ 209 private function _ajax_return( $response = true ) { 210 echo json_encode( $response ); 211 exit; 242 * @param mixed $response Data to be returned. 243 */ 244 private function ajax_return( $response = true ): void { 245 if ( is_wp_error( $response ) ) { 246 wp_send_json_error( $response ); 247 } 248 249 wp_send_json_success( $response ); 212 250 } 213 251 214 252 /** 215 253 * Displays a JSON encoded list of cron schedules. 216 * 217 * @return mixed|string|void218 */219 public function ajax_schedules() { 220 $this-> _ajax_return( $this->_get_schedules() );254 */ 255 public function ajax_get_schedules(): void { 256 check_ajax_referer( self::NONCE_CONTEXT ); 257 258 $this->ajax_return( $this->get_schedules() ); 221 259 } 222 260 … … 224 262 * Run a cron event now rather than later. 225 263 */ 226 public function ajax_events() { 227 // TODO: Sanitize inputs! 228 $event = json_decode( stripcslashes( $_POST['model'] ), true ); 264 public function ajax_update_event(): void { 265 check_ajax_referer( self::NONCE_CONTEXT ); 266 267 if ( ! isset( $_REQUEST['event'] ) ) { 268 $this->ajax_return( 269 new WP_Error( 270 'cron-pixie-update-event-missing-value', 271 __( 'No event given to be run now.', 'wp-cron-pixie' ) 272 ) 273 ); 274 275 exit; 276 } 277 278 $event = ! empty( $_REQUEST['event'] ) && is_string( $_REQUEST['event'] ) ? $_REQUEST['event'] : ''; 279 280 if ( empty( $event ) ) { 281 $this->ajax_return( 282 new WP_Error( 283 'cron-pixie-update-event-missing-value', 284 __( 'Type invalid for JSON data given for event to be run now.', 'wp-cron-pixie' ) 285 ) 286 ); 287 288 exit; 289 } 290 291 $event = json_decode( stripcslashes( $event ), true ); 292 293 $this->ajax_return( $this->update_event( $event ) ); 294 } 295 296 /** 297 * Update an event. 298 * 299 * @param mixed $event Event data to be updated. 300 * 301 * @return bool|WP_Error 302 */ 303 private function update_event( $event ): bool|WP_Error { 304 if ( ! is_array( $event ) ) { 305 return new WP_Error( 306 'cron-pixie-update-event-missing-value', 307 __( 'JSON data did not decode to an array for given for event to be run now.', 'wp-cron-pixie' ) 308 ); 309 } 310 311 if ( empty( $event['hook'] ) || ! is_string( $event['hook'] ) ) { 312 return new WP_Error( 313 'cron-pixie-update-event-missing-value', 314 __( 'No hook value given for event to be run now.', 'wp-cron-pixie' ) 315 ); 316 } 317 318 if ( ! isset( $event['args'] ) ) { 319 return new WP_Error( 320 'cron-pixie-update-event-missing-value', 321 __( 'No args value given for event to be run now.', 'wp-cron-pixie' ) 322 ); 323 } 324 325 if ( ! isset( $event['schedule'] ) ) { 326 return new WP_Error( 327 'cron-pixie-update-event-missing-value', 328 __( 'No schedule value given for event to be run now.', 'wp-cron-pixie' ) 329 ); 330 } 331 332 if ( ! isset( $event['timestamp'] ) ) { 333 return new WP_Error( 334 'cron-pixie-update-event-missing-value', 335 __( 'No timestamp value given for event to be run now.', 'wp-cron-pixie' ) 336 ); 337 } 338 229 339 $event['args'] = empty( $event['args'] ) ? array() : $event['args']; 230 340 … … 235 345 // If not expecting a schedule, but cron says it's on one, do nothing. 236 346 if ( 'false' === $event['schedule'] && ! empty( $schedule ) ) { 237 $this->_ajax_return( new WP_Error( 'cron-pixie-scheduled-single', __( 'The single event is also in a schedule.', 'wp-cron-pixie' ) ) ); 347 return new WP_Error( 348 'cron-pixie-update-event-scheduled-single', 349 __( 'The single event is also in a schedule.', 'wp-cron-pixie' ) 350 ); 238 351 } 239 352 240 353 // If expecting a schedule, but cron says it's not on one, do nothing. 241 if ( 'false' !== $event['schedule'] && empty( $schedule ) ) { 242 $this->_ajax_return( new WP_Error( 'cron-pixie-schedule-missing', __( 'The scheduled event is not scheduled.', 'wp-cron-pixie' ) ) ); 354 if ( 'false' !== strtolower( $event['schedule'] ) && empty( $schedule ) ) { 355 return new WP_Error( 356 'cron-pixie-update-event-schedule-missing', 357 __( 'The scheduled event is not scheduled.', 'wp-cron-pixie' ) 358 ); 243 359 } 244 360 245 361 // We only want to reschedule an event if it already exists and is in the future. 246 362 if ( false !== $timestamp && $now < $timestamp ) { 247 wp_unschedule_event( $timestamp, $event['hook'], $event['args'] ); 248 249 if ( 'false' === $event['schedule'] ) { 250 wp_schedule_single_event( $event['timestamp'], $event['hook'], $event['args'] ); 363 $unscheduled = wp_unschedule_event( $timestamp, $event['hook'], $event['args'], true ); 364 365 if ( is_wp_error( $unscheduled ) ) { 366 $this->ajax_return( $unscheduled ); 367 } 368 369 if ( 'false' === strtolower( $event['schedule'] ) ) { 370 $scheduled = wp_schedule_single_event( $event['timestamp'], $event['hook'], $event['args'], true ); 251 371 } else { 252 wp_schedule_event( $event['timestamp'], $event['schedule'], $event['hook'], $event['args'] ); 372 $scheduled = wp_schedule_event( $event['timestamp'], $event['schedule'], $event['hook'], $event['args'], true ); 373 } 374 375 if ( is_wp_error( $scheduled ) ) { 376 return $scheduled; 253 377 } 254 378 } … … 257 381 spawn_cron(); 258 382 259 $this->_ajax_return();383 return true; 260 384 } 261 385 … … 263 387 * Update the setting for whether example events should be included in the cron. 264 388 */ 265 public function ajax_example_events() { 266 // TODO: Sanitize inputs! 267 if ( isset( $_POST['example_events'] ) ) { 268 $value = empty( $_POST['example_events'] ) ? false : true; 269 270 $settings = get_site_option( self::SETTINGS_KEY ); 271 272 if ( is_array( $settings ) ) { 273 $settings['example_events'] = $value; 274 } else { 275 $settings = array( 'example_events' => $value ); 276 } 277 278 if ( ! update_site_option( self::SETTINGS_KEY, $settings ) ) { 279 $this->_ajax_return( new WP_Error( 'cron-pixie-example-events-update-settings', __( 'Could not update settings.', 'wp-cron-pixie' ) ) ); 280 } 389 public function ajax_update_example_events_setting(): void { 390 check_ajax_referer( self::NONCE_CONTEXT ); 391 392 if ( ! isset( $_REQUEST['example_events'] ) ) { 393 $this->ajax_return( 394 new WP_Error( 395 'cron-pixie-update-example-events-setting-missing-value', 396 __( 'No value given for whether Example Events should be included in cron.', 'wp-cron-pixie' ) 397 ) 398 ); 399 400 exit; 401 } 402 403 $example_events = ! empty( $_REQUEST['example_events'] ) && is_string( $_REQUEST['example_events'] ); 404 405 $this->ajax_return( $this->update_example_events_setting( $example_events ) ); 406 } 407 408 /** 409 * Update the setting for whether example events should be included in the cron. 410 * 411 * @param bool $example_events Example events setting. 412 * 413 * @return bool|WP_Error 414 */ 415 private function update_example_events_setting( bool $example_events ): bool|WP_Error { 416 $settings = get_site_option( self::SETTINGS_KEY ); 417 418 if ( is_array( $settings ) ) { 419 $settings['example_events'] = $example_events; 281 420 } else { 282 $this->_ajax_return( new WP_Error( 'cron-pixie-example-events-missing-value', __( 'No value given for whether Example Events should be included in cron.', 'wp-cron-pixie' ) ) ); 283 } 284 285 $this->_ajax_return( $value ); 421 $settings = array( 'example_events' => $example_events ); 422 } 423 424 if ( ! update_site_option( self::SETTINGS_KEY, $settings ) ) { 425 return new WP_Error( 426 'cron-pixie-update-example-events-setting-update-settings', 427 __( 'Could not update settings.', 'wp-cron-pixie' ) 428 ); 429 } 430 431 // As we've potentially changed whether example events are needed, 432 // proactively add or remove them. 433 $this->manage_example_events(); 434 435 return true; 286 436 } 287 437 … … 289 439 * Update the setting for whether the display should auto refresh. 290 440 */ 291 public function ajax_auto_refresh() { 292 // TODO: Sanitize inputs! 293 if ( isset( $_POST['auto_refresh'] ) ) { 294 $value = empty( $_POST['auto_refresh'] ) ? false : true; 295 296 $settings = get_site_option( self::SETTINGS_KEY ); 297 298 if ( is_array( $settings ) ) { 299 $settings['auto_refresh'] = $value; 300 } else { 301 $settings = array( 'auto_refresh' => $value ); 302 } 303 304 if ( ! update_site_option( self::SETTINGS_KEY, $settings ) ) { 305 $this->_ajax_return( new WP_Error( 'cron-pixie-auto-refresh-update-settings', __( 'Could not update settings.', 'wp-cron-pixie' ) ) ); 306 } 441 public function ajax_update_auto_refresh_setting(): void { 442 check_ajax_referer( self::NONCE_CONTEXT ); 443 444 if ( ! isset( $_REQUEST['auto_refresh'] ) ) { 445 $this->ajax_return( 446 new WP_Error( 447 'cron-pixie-update-auto-refresh-setting-missing-value', 448 __( 'No value given for whether the display should auto refresh.', 'wp-cron-pixie' ) 449 ) 450 ); 451 452 exit; 453 } 454 455 $auto_refresh = ! empty( $_REQUEST['auto_refresh'] ) && is_string( $_REQUEST['auto_refresh'] ); 456 457 $this->ajax_return( $this->update_auto_refresh_setting( $auto_refresh ) ); 458 } 459 460 /** 461 * Update the setting for whether the display should auto refresh. 462 * 463 * @param bool $auto_refresh Auto refresh setting. 464 * 465 * @return bool|WP_Error 466 */ 467 private function update_auto_refresh_setting( bool $auto_refresh ): bool|WP_Error { 468 $settings = get_site_option( self::SETTINGS_KEY ); 469 470 if ( is_array( $settings ) ) { 471 $settings['auto_refresh'] = $auto_refresh; 307 472 } else { 308 $this->_ajax_return( new WP_Error( 'cron-pixie-auto-refresh-missing-value', __( 'No value given for whether the display should auto refresh.', 'wp-cron-pixie' ) ) ); 309 } 310 311 $this->_ajax_return( $value ); 473 $settings = array( 'auto_refresh' => $auto_refresh ); 474 } 475 476 if ( ! update_site_option( self::SETTINGS_KEY, $settings ) ) { 477 return new WP_Error( 478 'cron-pixie-update-auto-refresh-setting-update-settings', 479 __( 'Could not update settings.', 'wp-cron-pixie' ) 480 ); 481 } 482 483 return true; 312 484 } 313 485 … … 315 487 * Adds an "every_minute" schedule to the Schedules list. 316 488 * 317 * @param array $schedules318 * 319 * @return array 320 */ 321 public function filter_cron_schedules( $schedules = array() ){489 * @param array<string, array<string, mixed>> $schedules Current schedules. 490 * 491 * @return array<string, array<string, mixed>> 492 */ 493 public function filter_cron_schedules( array $schedules = array() ): array { 322 494 $schedules['every_minute'] = array( 323 495 'interval' => 60, … … 329 501 330 502 /** 503 * Reschedules the passed event when due so that it is due in the past again. 504 * 505 * @param mixed $wibble Args for the event. 506 */ 507 public function reschedule_passed_event( $wibble ): void { 508 $args = array( 'wibble' => $wibble ); 509 510 // Remove the event that has already been missed (2 minutes over due). 511 // Elsewhere the event will be recreated if example events are turned on. 512 if ( wp_next_scheduled( 'cron_pixie_passed_event', $args ) ) { 513 wp_clear_scheduled_hook( 'cron_pixie_passed_event', $args ); 514 } 515 } 516 517 /** 518 * Create or remove example events based on setting. 519 */ 520 private function manage_example_events(): void { 521 if ( $this->get_setting( 'example_events' ) ) { 522 $this->create_example_events(); 523 } else { 524 $this->remove_example_events(); 525 } 526 } 527 528 /** 331 529 * Creates test cron events in the cron schedule if they do not already exist. 332 530 */ 333 private function _create_test_events(){531 private function create_example_events(): void { 334 532 $args = array( 'wibble' => 'wobble' ); 335 533 336 // Create an event that has already been missed (2 minutes over due).534 // Create an event that has already been missed (2 minutes overdue). 337 535 if ( ! wp_next_scheduled( 'cron_pixie_passed_event', $args ) ) { 338 536 wp_schedule_event( time() - 120, 'every_minute', 'cron_pixie_passed_event', $args ); … … 353 551 * Remove test cron events from the cron schedule if they already exist. 354 552 */ 355 private function _remove_test_events(){553 private function remove_example_events(): void { 356 554 $args = array( 'wibble' => 'wobble' ); 357 555 358 // Create anevent that has already been missed (2 minutes over due).556 // Remove the event that has already been missed (2 minutes over due). 359 557 if ( wp_next_scheduled( 'cron_pixie_passed_event', $args ) ) { 360 558 wp_clear_scheduled_hook( 'cron_pixie_passed_event', $args ); 361 559 } 362 560 363 // Create anevent that is just coming up (initially 30 seconds until due).364 if ( !wp_next_scheduled( 'cron_pixie_future_event', $args ) ) {561 // Remove the event that is just coming up (initially 30 seconds until due). 562 if ( wp_next_scheduled( 'cron_pixie_future_event', $args ) ) { 365 563 wp_clear_scheduled_hook( 'cron_pixie_future_event', $args ); 366 564 } 367 565 368 // Create asingle event that is in the future (initially 5 minutes until due).369 if ( !wp_next_scheduled( 'cron_pixie_single_event', $args ) ) {566 // Remove the single event that is in the future (initially 5 minutes until due). 567 if ( wp_next_scheduled( 'cron_pixie_single_event', $args ) ) { 370 568 wp_clear_scheduled_hook( 'cron_pixie_single_event', $args ); 371 569 } … … 375 573 * Get a single setting based on its key name. 376 574 * 377 * @param string $key 575 * @param string $key Setting key. 378 576 * 379 577 * @return mixed defaults to false if not found 380 578 */ 381 private function _get_setting($key ) {579 private function get_setting( string $key ) { 382 580 $value = false; 383 581 384 582 $settings = get_site_option( self::SETTINGS_KEY ); 385 583 386 if ( ! empty( $settings ) ) { 387 if ( isset( $settings[ $key ] ) ) { 584 if ( ! empty( $settings ) && is_array( $settings ) && isset( $settings[ $key ] ) ) { 388 585 $value = $settings[ $key ]; 389 }390 586 } 391 587 -
wp-cron-pixie/trunk/js/main.js
r2263440 r3317252 1 document.addEventListener( 'DOMContentLoaded', () => { 2 var $mountPoint = document.getElementById( 'cron-pixie-main' ); 3 var app = Elm.CronPixie.init( { 4 node: $mountPoint, 5 flags: { 6 strings: CronPixie.strings, 7 admin_url: CronPixie.admin_url, 8 nonce: CronPixie.nonce, 9 timer_period: CronPixie.timer_period, 10 schedules: CronPixie.data.schedules, 11 example_events: CronPixie.example_events, 12 auto_refresh: CronPixie.auto_refresh 13 } 14 } ); 15 } ); 1 document.addEventListener('DOMContentLoaded', () => { 2 import('./ui.js?ver=' + CronPixie.version).then((CronPixieUI) => { 3 CronPixieUI.main(JSON.stringify(CronPixie)); 4 }); 5 }); -
wp-cron-pixie/trunk/wp-cron-pixie.php
r3061791 r3317252 1 1 <?php 2 3 2 /** 3 * A little dashboard widget to manage the WordPress cron. 4 * 4 5 * @link https://github.com/ianmjones/wp-cron-pixie 5 6 * @package Cron_Pixie … … 9 10 * Plugin URI: https://github.com/ianmjones/wp-cron-pixie 10 11 * Description: A little dashboard widget to manage the WordPress cron. 11 * Version: 1. 4.412 * Version: 1.5.0 12 13 * Author: Ian M. Jones 13 14 * Author URI: https://ianmjones.com/ 14 * License: GPL-2.0+15 * License URI: http ://www.gnu.org/licenses/gpl-2.0.txt15 * License: MIT 16 * License URI: https://mit-license.org/ 16 17 * Text Domain: wp-cron-pixie 17 18 * Domain Path: /languages 18 19 * Network: False 19 20 */ 21 22 namespace Cron_Pixie; 20 23 21 24 // If this file is called directly, abort. … … 27 30 * Returns info about the plugin. 28 31 * 29 * @return array 32 * @return array<string,string> 30 33 */ 31 function cron_pixie_meta() {34 function cron_pixie_meta(): array { 32 35 return array( 33 36 'slug' => 'wp-cron-pixie', 34 37 'name' => 'WP Cron Pixie', 35 38 'file' => __FILE__, 36 'version' => '1. 4.4',39 'version' => '1.5.0', 37 40 ); 38 41 } … … 43 46 /** 44 47 * Initialize the plugin's functionality once the correct hook fires. 48 * 49 * We create an instance of the main class fairly early so that we can 50 * hook in and create the cron schedule for our example events. 51 * The cron schedule needs to be there to avoid errors when the jobs 52 * are later scheduled. 53 * 54 * Very little else is done at this point, the rest happens in admin_init 55 * as then we know for sure we're in admin mode. 45 56 */ 46 function cron_pixie_admin_init() { 57 function cron_pixie_init(): void { 58 global $cron_pixie; 59 47 60 $cron_pixie = new Cron_Pixie( cron_pixie_meta() ); 48 61 } 49 62 50 add_action( 'admin_init', 'cron_pixie_admin_init' ); 63 add_action( 'init', __NAMESPACE__ . '\cron_pixie_init' ); 64 65 /** 66 * Initialize the plugin's real functionality. 67 */ 68 function cron_pixie_admin_init(): void { 69 global $cron_pixie; 70 71 $cron_pixie->init(); 72 } 73 74 add_action( 'admin_init', __NAMESPACE__ . '\cron_pixie_admin_init' );
Note: See TracChangeset
for help on using the changeset viewer.