WP Crontrol - Version 1.2.2

Version Description

  • Added crontrol run-event and crontrol delete-event WP-CLI commands

=

Download this release

Release Info

Developer johnbillion
Plugin Icon 128x128 WP Crontrol
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

Files changed (3) hide show
  1. class-wp-cli.php +73 -10
  2. readme.txt +37 -32
  3. wp-crontrol.php +66 -46
class-wp-cli.php CHANGED
@@ -1,14 +1,12 @@
1
  <?php
2
 
3
  /*
4
-
5
- @todo add, delete, run, etc
6
-
7
  */
8
 
9
  class Crontrol_Command extends WP_CLI_Command {
10
 
11
- public $crontrol = null;
12
 
13
  public function __construct() {
14
 
@@ -33,7 +31,7 @@ class Crontrol_Command extends WP_CLI_Command {
33
  die();
34
  }
35
 
36
- $events = array_map( 'self::_map_event', $events );
37
 
38
  $fields = array(
39
  'hook',
@@ -45,6 +43,68 @@ class Crontrol_Command extends WP_CLI_Command {
45
 
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  /**
49
  * List available cron schedules.
50
  *
@@ -55,10 +115,10 @@ class Crontrol_Command extends WP_CLI_Command {
55
  public function list_schedules() {
56
 
57
  $schedules = $this->crontrol->get_schedules();
58
-
59
- $schedules = array_map( 'self::_map_schedule', $schedules );
60
 
61
  $fields = array(
 
62
  'display',
63
  'interval'
64
  );
@@ -83,14 +143,17 @@ class Crontrol_Command extends WP_CLI_Command {
83
 
84
  }
85
 
86
- protected static function _map_event( $event ) {
 
87
  $event->next_run = get_date_from_gmt(date('Y-m-d H:i:s',$event->time),$time_format) . " (".$this->crontrol->time_since(time(), $event->time).")";
88
  $event->recurrence = ($event->schedule ? $this->crontrol->interval($event->interval) : __('Non-repeating', 'crontrol'));
89
  return $event;
90
  }
91
 
92
- protected static function _map_schedule( $schedule ) {
93
- return (object) $schedule;
 
 
94
  }
95
 
96
  }
1
  <?php
2
 
3
  /*
4
+ @todo add-event
 
 
5
  */
6
 
7
  class Crontrol_Command extends WP_CLI_Command {
8
 
9
+ protected $crontrol = null;
10
 
11
  public function __construct() {
12
 
31
  die();
32
  }
33
 
34
+ $events = array_map( array( $this, '_map_event' ), $events );
35
 
36
  $fields = array(
37
  'hook',
43
 
44
  }
45
 
46
+ /**
47
+ * Run the next scheduled cron event for the given hook.
48
+ *
49
+ * @since 1.2.2
50
+ *
51
+ * @synopsis <hook>
52
+ * @subcommand run-event
53
+ */
54
+ public function run_event( $args, $assoc_args ) {
55
+
56
+ $hook = $args[0];
57
+ $result = false;
58
+ $events = $this->crontrol->get_cron_events();
59
+
60
+ if ( is_wp_error( $events ) )
61
+ WP_CLI::error( $events );
62
+
63
+ foreach ( $events as $id => $event ) {
64
+ if ( $event->hook == $hook ) {
65
+ $result = $this->crontrol->run_cron( $event->hook, $event->sig );
66
+ break;
67
+ }
68
+ }
69
+
70
+ if ( $result )
71
+ WP_CLI::success( sprintf( __( 'Successfully executed the cron event %s', 'crontrol' ), "'" . $hook . "'" ) );
72
+ else
73
+ WP_CLI::error( sprintf( __( 'Failed to the execute the cron event %s', 'crontrol' ), "'" . $hook . "'" ) );
74
+
75
+ }
76
+
77
+ /**
78
+ * Delete the next scheduled cron event for the given hook.
79
+ *
80
+ * @since 1.2.2
81
+ *
82
+ * @synopsis <hook>
83
+ * @subcommand delete-event
84
+ */
85
+ public function delete_event( $args, $assoc_args ) {
86
+
87
+ $hook = $args[0];
88
+ $result = false;
89
+ $events = $this->crontrol->get_cron_events();
90
+
91
+ if ( is_wp_error( $events ) )
92
+ WP_CLI::error( $events );
93
+
94
+ foreach ( $events as $id => $event ) {
95
+ if ( $event->hook == $hook ) {
96
+ $result = $this->crontrol->delete_cron( $event->hook, $event->sig, $event->time );
97
+ break;
98
+ }
99
+ }
100
+
101
+ if ( $result )
102
+ WP_CLI::success( sprintf( __( 'Successfully deleted the cron event %s', 'crontrol' ), "'" . $hook . "'" ) );
103
+ else
104
+ WP_CLI::error( sprintf( __( 'Failed to the delete the cron event %s', 'crontrol' ), "'" . $hook . "'" ) );
105
+
106
+ }
107
+
108
  /**
109
  * List available cron schedules.
110
  *
115
  public function list_schedules() {
116
 
117
  $schedules = $this->crontrol->get_schedules();
118
+ $schedules = array_map( array( $this, '_map_schedule' ), $schedules, array_keys( $schedules ) );
 
119
 
120
  $fields = array(
121
+ 'name',
122
  'display',
123
  'interval'
124
  );
143
 
144
  }
145
 
146
+ protected function _map_event( $event ) {
147
+ $time_format = 'Y/m/d H:i:s';
148
  $event->next_run = get_date_from_gmt(date('Y-m-d H:i:s',$event->time),$time_format) . " (".$this->crontrol->time_since(time(), $event->time).")";
149
  $event->recurrence = ($event->schedule ? $this->crontrol->interval($event->interval) : __('Non-repeating', 'crontrol'));
150
  return $event;
151
  }
152
 
153
+ protected function _map_schedule( $schedule, $name ) {
154
+ $schedule = (object) $schedule;
155
+ $schedule->name = $name;
156
+ return $schedule;
157
  }
158
 
159
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: scompt, johnbillion
3
  Tags: admin, cron, plugin, control, wp-cron, crontrol, wp-cli
4
  Requires at least: 3.0
5
  Tested up to: 3.6
6
- Stable tag: 1.2.1
7
 
8
  WP Crontrol lets you view and control what's happening in the WP-Cron system.
9
 
@@ -11,15 +11,15 @@ WP Crontrol lets you view and control what's happening in the WP-Cron system.
11
 
12
  WP Crontrol lets you view and control what's happening in the WP-Cron system. From the admin screen you can:
13
 
14
- * View all cron entries along with their arguments, recurrence and when they are next due.
15
- * Edit, delete, and immediately run any cron entries.
16
- * Add new cron entries.
17
 
18
- The admin screen will show you a warning message if your cron system doesn't appear to be working (for example if your server can't connect to itself to fire scheduled cron entries).
19
 
20
  From the settings screen you can also add, edit and remove cron schedues.
21
 
22
- Now supports [wp-cli](http://wp-cli.org/)!
23
 
24
  == Installation ==
25
 
@@ -34,26 +34,26 @@ Alternatively, see the guide to [Manually Installing Plugins](http://codex.wordp
34
 
35
  = Usage =
36
 
37
- 1. Go to the Tools -> Crontrol menu to see what cron entries are scheduled and to add some new ones.
38
  2. Go to the Settings -> Cron Schedules menu to add new cron schedules.
39
 
40
  == Frequently Asked Questions ==
41
 
42
  = What's the use of adding new cron schedules? =
43
 
44
- Cron schedules are used by WordPress and WordPress plugins to allow you to schedule commands to be executed at regular intervals. Intervals must be provided by the WordPress core or a plugin in order to be used. An example of a plugin that uses these schedules is [WordPress Database Backup](http://www.ilfilosofo.com/blog/wp-db-backup/). Out of the box, only daily and hourly backups are supported. In order to do a weekly backup, a weekly cron schedule must be entered into WP Crontrol first and then the backup plugin can take advantage of it as an interval.
45
 
46
- = How do I create a new PHP cron entry? =
47
 
48
- In the Tools -> Crontrol admin panel, click on the "add new PHP entry" link underneath the cron entry table. In the form that appears, enter the schedule and next run time in the boxes. Next run is the next time that the hook will execute. This can be entered in using [GNU Date Input Formats](http://www.gnu.org/software/tar/manual/html_node/tar_113.html), but often *now* is good enough. The entry schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings -> Crontrol admin panel. In the "Hook code" area, enter the PHP code that should be run when your cron entry is executed. You don't need to provide the PHP opening tag (`<?php`).
49
 
50
- = How do I create a new regular cron entry? =
51
 
52
- There are two steps to getting a functioning cron entry that executes regularly. The first step is telling WordPress about the hook. This is the part that WP Crontrol was created to provide. The second step is calling your function when your hook is executed. You've got to do that on your own, but I'll explain how below.
53
 
54
  *Step One: Adding the hook*
55
 
56
- In the Tools -> Crontrol admin panel, enter the details of the hook. You're best off having a hookname that conforms to normal PHP variable naming conventions. This could save you trouble later. Other than that, the hookname can be whatever you want it to be. Next run is the next time that the hook will execute. This can be entered in using [GNU Date Input Formats](http://www.gnu.org/software/tar/manual/html_node/tar_113.html), but often *now* is good enough. The entry schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings -> Crontrol admin panel.
57
 
58
  *Step Two: Writing the function*
59
 
@@ -69,53 +69,59 @@ The next step is to write your function. Here's a simple example:
69
 
70
  = Do I really need the entire `wp-crontrol` directory? =
71
 
72
- No, you can get rid of the whole directory and just use `wp-crontrol.php` if you wish. If you want to use wp-cli then you'll need to include `class-wp-cli.php` too.
73
 
74
- = Which wp-cli commands are available? =
75
 
76
- * `wp crontrol list` Lists the scheduled events on your site.
77
- * `wp crontrol test` Performs a WP-Cron spawning test to make sure WP-Cron can function as expected.
78
  * `wp crontrol list-schedules` Lists the available WP-Cron schedules on your site.
 
 
 
79
 
80
- Note that wp-cli support was only recently added. This will be improved over time. Feedback welcome!
81
 
82
  == Screenshots ==
83
 
84
- 1. New cron entries can be added, modified, and deleted. In addition, they can be executed on-demand.
85
- 1. New cron schedules can be added to WordPress, giving plugin developers more options when scheduling commands.
86
 
87
  == Upgrade Notice ==
88
 
89
- = 1.2.1 =
90
- * Correctly display the local time when listing cron entries
91
 
92
  == Changelog ==
93
 
 
 
 
 
94
  = 1.2.1 =
95
- * Correctly display the local time when listing cron entries
96
  * Remove a PHP notice
97
- * Pass the WP-Cron spawn check through the same filter as the actual spawner.
98
 
99
  = 1.2 =
100
- * Added support for [wp-cli](http://wp-cli.org/)
101
  * Removed some PHP4 code that's no longer relevant
102
 
103
  = 1.1 =
104
- * Bug fixes for running cron jobs and adding cron schedules
105
  * Added a cron spawn test to check for errors when spawning cron
106
  * Various small tweaks
107
  * WordPress 3.4 compatibility
108
 
109
  = 1.0 =
110
- * Input of PHP code for cron entries
111
- * Non-repeating cron entries
112
- * Handles cron entries with arguments
113
 
114
  = 0.3 =
115
  * Internationalization
116
- * Editing/deleting/execution of cron entries
117
  * More text, status messages, etc.
118
- * Allow a user to enter a schedule entry in a human manner
119
  * Looks better on WordPress 2.5
120
 
121
  = 0.2 =
@@ -126,4 +132,3 @@ Note that wp-cli support was only recently added. This will be improved over tim
126
 
127
  = 0.1 =
128
  * Super basic, look at what's in WP-Cron functionality.
129
-
3
  Tags: admin, cron, plugin, control, wp-cron, crontrol, wp-cli
4
  Requires at least: 3.0
5
  Tested up to: 3.6
6
+ Stable tag: 1.2.2
7
 
8
  WP Crontrol lets you view and control what's happening in the WP-Cron system.
9
 
11
 
12
  WP Crontrol lets you view and control what's happening in the WP-Cron system. From the admin screen you can:
13
 
14
+ * View all cron events along with their arguments, recurrence and when they are next due.
15
+ * Edit, delete, and immediately run any cron events.
16
+ * Add new cron events.
17
 
18
+ The admin screen will show you a warning message if your cron system doesn't appear to be working (for example if your server can't connect to itself to fire scheduled cron events).
19
 
20
  From the settings screen you can also add, edit and remove cron schedues.
21
 
22
+ Now supports [WP-CLI](http://wp-cli.org/)!
23
 
24
  == Installation ==
25
 
34
 
35
  = Usage =
36
 
37
+ 1. Go to the Tools -> Crontrol menu to see what cron events are scheduled and to add some new ones.
38
  2. Go to the Settings -> Cron Schedules menu to add new cron schedules.
39
 
40
  == Frequently Asked Questions ==
41
 
42
  = What's the use of adding new cron schedules? =
43
 
44
+ Cron schedules are used by WordPress and WordPress plugins to allow you to schedule events to be executed at regular intervals. Intervals must be provided by the WordPress core or a plugin in order to be used. An example of a plugin that uses these schedules is [WordPress Database Backup](http://www.ilfilosofo.com/blog/wp-db-backup/). Out of the box, only daily and hourly backups are supported. In order to do a weekly backup, a weekly cron schedule must be entered into WP Crontrol first and then the backup plugin can take advantage of it as an interval.
45
 
46
+ = How do I create a new PHP cron event? =
47
 
48
+ In the Tools -> Crontrol admin panel, click on the "Add new PHP event" link underneath the cron event table. In the form that appears, enter the schedule and next run time in the boxes. Next run is the next time that the hook will execute. This can be entered in using [GNU Date Input Formats](http://www.gnu.org/software/tar/manual/html_node/tar_113.html), but often *now* is good enough. The event schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings -> Cron Schedules admin panel. In the "Hook code" area, enter the PHP code that should be run when your cron event is executed. You don't need to provide the PHP opening tag (`<?php`).
49
 
50
+ = How do I create a new regular cron event? =
51
 
52
+ There are two steps to getting a functioning cron event that executes regularly. The first step is telling WordPress about the hook. This is the part that WP Crontrol was created to provide. The second step is calling your function when your hook is executed. You've got to do that on your own, but I'll explain how below.
53
 
54
  *Step One: Adding the hook*
55
 
56
+ In the Tools -> Crontrol admin panel, enter the details of the hook. You're best off having a hookname that conforms to normal PHP variable naming conventions. This could save you trouble later. Other than that, the hookname can be whatever you want it to be. Next run is the next time that the hook will execute. This can be entered in using [GNU Date Input Formats](http://www.gnu.org/software/tar/manual/html_node/tar_113.html), but often *now* is good enough. The event schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings -> Cron Schedules admin panel.
57
 
58
  *Step Two: Writing the function*
59
 
69
 
70
  = Do I really need the entire `wp-crontrol` directory? =
71
 
72
+ No, you can get rid of the whole directory and just use `wp-crontrol.php` if you wish. If you want to use WP-CLI then you'll need to include `class-wp-cli.php` too.
73
 
74
+ = Which WP-CLI commands are available? =
75
 
76
+ * `wp crontrol list-events` Lists the scheduled events on your site.
 
77
  * `wp crontrol list-schedules` Lists the available WP-Cron schedules on your site.
78
+ * `wp crontrol test` Performs a WP-Cron spawning test to make sure WP-Cron can function as expected.
79
+ * `wp crontrol run-event <hook>` Runs the next scheduled WP-Cron event for the given hook
80
+ * `wp crontrol delete-event <hook>` Deletes the next scheduled WP-Cron event for the given hook
81
 
82
+ Note that WP-CLI support is a work in progress and will be improved over time. Feedback welcome!
83
 
84
  == Screenshots ==
85
 
86
+ 1. New cron events can be added, modified, and deleted. In addition, they can be executed on-demand.
87
+ 1. New cron schedules can be added to WordPress, giving plugin developers more options when scheduling events.
88
 
89
  == Upgrade Notice ==
90
 
91
+ = 1.2.2 =
92
+ * Added `crontrol run-event` and `crontrol delete-event` WP-CLI commands
93
 
94
  == Changelog ==
95
 
96
+ = 1.2.2 =
97
+ * Added `crontrol run-event` and `crontrol delete-event` WP-CLI commands
98
+ * Clarify language regarding hooks/entries/events
99
+
100
  = 1.2.1 =
101
+ * Correctly display the local time when listing cron events
102
  * Remove a PHP notice
103
+ * Pass the WP-Cron spawn check through the same filter as the actual spawner
104
 
105
  = 1.2 =
106
+ * Added support for [WP-CLI](http://wp-cli.org/)
107
  * Removed some PHP4 code that's no longer relevant
108
 
109
  = 1.1 =
110
+ * Bug fixes for running cron events and adding cron schedules
111
  * Added a cron spawn test to check for errors when spawning cron
112
  * Various small tweaks
113
  * WordPress 3.4 compatibility
114
 
115
  = 1.0 =
116
+ * Input of PHP code for cron events
117
+ * Non-repeating cron events
118
+ * Handles cron events with arguments
119
 
120
  = 0.3 =
121
  * Internationalization
122
+ * Editing/deleting/execution of cron events
123
  * More text, status messages, etc.
124
+ * Allow a user to enter a schedule event in a human manner
125
  * Looks better on WordPress 2.5
126
 
127
  = 0.2 =
132
 
133
  = 0.1 =
134
  * Super basic, look at what's in WP-Cron functionality.
 
wp-crontrol.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://wordpress.org/plugins/wp-crontrol/
5
  * Description: WP Crontrol lets you view and control what's happening in the WP-Cron system.
6
  * Author: <a href="http://www.scompt.com/">Edward Dale</a> & <a href="http://lud.icro.us/">John Blackbourn</a>
7
- * Version: 1.2.1
8
  * Text Domain: crontrol
9
  * Domain Path: /gettext/
10
  */
@@ -55,13 +55,13 @@ class Crontrol {
55
  add_action($activate_action, array(&$this, 'action_activate'));
56
 
57
  add_filter('cron_schedules', array(&$this, 'filter_cron_schedules'));
58
- add_action('crontrol_cron_job', array(&$this, 'action_php_cron_entry'));
59
  }
60
 
61
  /**
62
  * Evaluates the provided code using eval.
63
  */
64
- function action_php_cron_entry($code) {
65
  eval($code);
66
  }
67
 
@@ -171,11 +171,11 @@ class Crontrol {
171
  }
172
 
173
  /**
174
- * Executes a cron entry immediately.
175
  *
176
- * Executes an entry by scheduling a new single event with the same arguments.
177
  *
178
- * @param string $hookname The hookname of the cron entry to run
179
  */
180
  function run_cron($hookname, $sig) {
181
  $crons = _get_cron_array();
@@ -192,12 +192,12 @@ class Crontrol {
192
  }
193
 
194
  /**
195
- * Adds a new cron entry.
196
  *
197
- * @param string $next_run A human-readable (strtotime) time that the entry should be run at
198
- * @param string $schedule The recurrence of the cron entry
199
  * @param string $hookname The name of the hook to execute
200
- * @param array $args Arguments to add to the cron entry
201
  */
202
  function add_cron($next_run, $schedule, $hookname, $args) {
203
  $next_run = strtotime($next_run);
@@ -211,9 +211,9 @@ class Crontrol {
211
  }
212
 
213
  /**
214
- * Deletes a cron entry.
215
  *
216
- * @param string $name The hookname of the entry to delete.
217
  */
218
  function delete_cron($to_delete, $sig, $next_run) {
219
  $crons = _get_cron_array();
@@ -258,7 +258,7 @@ class Crontrol {
258
  $extra_scheds = array('twicedaily'=>array('interval'=>43200, 'display'=>__('Twice Daily', 'crontrol')));
259
  add_option('crontrol_schedules', $extra_scheds);
260
 
261
- // if there's never been a cron entry, _get_cron_array will return FALSE
262
  if( _get_cron_array() === FALSE ) {
263
  _set_cron_array(array());
264
  }
@@ -354,16 +354,16 @@ class Crontrol {
354
  <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
355
  <tbody>
356
  <tr>
357
- <th width="33%" valign="top" scope="row"><label for="internal_name"><?php _e('Internal name', 'crontrol'); ?>:</label></th>
358
- <td width="67%"><input type="text" size="40" value="" id="internal_name" name="internal_name"/></td>
359
  </tr>
360
  <tr>
361
- <th width="33%" valign="top" scope="row"><label for="interval"><?php _e('Interval', 'crontrol'); ?>:</label></th>
362
- <td width="67%"><input type="text" size="40" value="" id="interval" name="interval"/></td>
363
  </tr>
364
  <tr>
365
- <th width="33%" valign="top" scope="row"><label for="display_name"><?php _e('Display name', 'crontrol'); ?>:</label></th>
366
- <td width="67%"><input type="text" size="40" value="" id="display_name" name="display_name"/></td>
367
  </tr>
368
  </tbody></table>
369
  <p class="submit"><input id="schedadd-submit" type="submit" class="button-primary" value="<?php _e('Add Cron Schedule &raquo;', 'crontrol'); ?>" name="new_schedule"/></p>
@@ -389,14 +389,16 @@ class Crontrol {
389
  */
390
  function schedules_dropdown($current=false) {
391
  $schedules = $this->get_schedules();
392
- echo '<select class="postform" name="schedule">';
393
- foreach( $schedules as $sched_name=>$sched_data ) { ?>
 
 
394
  <option <?php selected($current, $sched_name) ?> value="<?php echo $sched_name ?>">
395
  <?php echo $sched_data['display'] ?> (<?php echo $this->interval($sched_data['interval']) ?>)
396
  </option>
397
  <?php } ?>
398
- <option <?php selected($current, '_oneoff') ?> value="_oneoff"><?php _e('Non-repeating', 'crontrol') ?></option>
399
- </select><?php
400
  }
401
 
402
  /**
@@ -457,18 +459,18 @@ class Crontrol {
457
  }
458
 
459
  /**
460
- * Shows the form used to add/edit cron entries.
461
  *
462
- * @param boolean $is_php Whether this is a PHP cron entry
463
- * @param mixed $existing An array of existing values for the cron entry, or NULL
464
  */
465
  function show_cron_form($is_php, $existing) {
466
  if( $is_php ) {
467
- $helper_text = __('Cron entries trigger actions in your code. Using the form below, you can enter the schedule of the action, as well as the PHP code for the action itself. Alternatively, the schedule can be specified from within WordPress and the code for the action in a file on on your server using <a href="tools.php?page=crontrol_admin_manage_page&action=new-cron#crontrol_form">this form</a>.', 'crontrol');
468
- $link = ' (<a href="tools.php?page=crontrol_admin_manage_page#crontrol_form">'. __('Add new entry', 'crontrol') .'</a>)';
469
  } else {
470
- $helper_text = __('Cron entries trigger actions in your code. A cron entry added using the form below needs a corresponding action hook somewhere in code, perhaps the <code>functions.php</code> file in your theme. It is also possible to create your action hook from within WordPress using <a href="tools.php?page=crontrol_admin_manage_page&action=new-php-cron#crontrol_form">this form</a>.', 'crontrol');
471
- $link = ' (<a href="tools.php?page=crontrol_admin_manage_page&amp;action=new-php-cron#crontrol_form">'. __('Add new PHP entry', 'crontrol') .'</a>)';
472
  }
473
  if( is_array($existing) ) {
474
  $other_fields = wp_nonce_field( "edit-cron_{$existing['hookname']}_{$existing['sig']}_{$existing['next_run']}", "_wpnonce", true, false );
@@ -476,15 +478,15 @@ class Crontrol {
476
  $other_fields .= '<input name="original_sig" type="hidden" value="'. $existing['sig'] .'" />';
477
  $other_fields .= '<input name="original_next_run" type="hidden" value="'. $existing['next_run'] .'" />';
478
  $existing['args'] = $is_php ? $existing['args']['code'] : json_encode($existing['args']);
479
- $existing['next_run'] = strftime("%D %T", $existing['next_run']);
480
  $action = $is_php ? 'edit_php_cron' : 'edit_cron';
481
- $button = $is_php ? __('Modify PHP Cron Entry', 'crontrol') : __('Modify Cron Entry', 'crontrol');
482
  $link = false;
483
  } else {
484
  $other_fields = wp_nonce_field( "new-cron", "_wpnonce", true, false );
485
  $existing = array('hookname'=>'','hookcode'=>'','args'=>'','next_run'=>'now','schedule'=>false);
486
  $action = $is_php ? 'new_php_cron' : 'new_cron';
487
- $button = $is_php ? __('Add PHP Cron Entry', 'crontrol') : __('Add Cron Entry', 'crontrol');
488
  }
489
  ?>
490
  <div id="crontrol_form" class="wrap narrow">
@@ -497,7 +499,7 @@ class Crontrol {
497
  <?php if( $is_php ): ?>
498
  <tr>
499
  <th width="33%" valign="top" scope="row"><label for="hookcode"><?php _e('Hook code', 'crontrol'); ?>:</label></th>
500
- <td width="67%"><textarea style="width:95%" name="hookcode"><?php echo esc_textarea( $existing['args'] ); ?></textarea></td>
501
  </tr>
502
  <?php else: ?>
503
  <tr>
@@ -510,10 +512,10 @@ class Crontrol {
510
  </tr>
511
  <?php endif; ?>
512
  <tr>
513
- <th width="33%" valign="top" scope="row"><label for="next_run"><?php _e('Next run', 'crontrol'); ?>:</label><br /><span style="font-size:xx-small"><?php _e('e.g., "now", "tomorrow", "+2 days", or "06/04/08 15:27:09"', 'crontrol') ?></th>
514
  <td width="67%"><input type="text" size="40" id="next_run" name="next_run" value="<?php echo esc_attr( $existing['next_run'] ); ?>"/></td>
515
  </tr><tr>
516
- <th valign="top" scope="row"><label for="schedule"><?php _e('Entry schedule', 'crontrol'); ?>:</label></th>
517
  <td>
518
  <?php $this->schedules_dropdown($existing['schedule']) ?>
519
  </td>
@@ -533,7 +535,7 @@ class Crontrol {
533
  if ( empty( $crons ) ) {
534
  return new WP_Error(
535
  'no_events',
536
- __( 'You currently have no cron entries.', 'crontrol' )
537
  );
538
  }
539
 
@@ -564,12 +566,12 @@ class Crontrol {
564
  */
565
  function admin_manage_page() {
566
  if( isset($_GET['crontrol_message']) ) {
567
- $messages = array( '1' => __('Successfully executed the cron entry <b>%s</b>', 'crontrol'),
568
- '4' => __('Successfully edited the cron entry <b>%s</b>', 'crontrol'),
569
- '5' => __('Successfully created the cron entry <b>%s</b>', 'crontrol'),
570
- '6' => __('Successfully deleted the cron entry <b>%s</b>', 'crontrol'),
571
- '7' => __('Failed to the delete the cron entry <b>%s</b>', 'crontrol'),
572
- '8' => __('Failed to the execute the cron entry <b>%s</b>', 'crontrol'));
573
  $hook = $_GET['crontrol_name'];
574
  $msg = sprintf($messages[$_GET['crontrol_message']], $hook);
575
 
@@ -578,11 +580,24 @@ class Crontrol {
578
  $events = $this->get_cron_events();
579
  $doing_edit = (isset( $_GET['action']) && $_GET['action']=='edit-cron') ? $_GET['id'] : false ;
580
  $time_format = 'Y/m/d H:i:s';
 
 
 
 
 
 
 
 
 
 
 
 
581
  $this->show_cron_status();
 
582
  ?>
583
  <div class="wrap">
584
  <?php screen_icon(); ?>
585
- <h2><?php _e('WP-Cron Entries', 'crontrol'); ?></h2>
586
  <p></p>
587
  <table class="widefat">
588
  <thead>
@@ -631,8 +646,13 @@ class Crontrol {
631
  </tbody>
632
  </table>
633
 
634
- <p class="description"><?php printf(__('UTC time is <code>%s</code>', 'crontrol'), date_i18n($time_format, false, true)); ?></p>
635
- <p class="description"><?php printf(__('Local time is <code>%s</code>', 'crontrol'), date_i18n($time_format)); ?></p>
 
 
 
 
 
636
 
637
  </div>
638
  <?php
4
  * Plugin URI: http://wordpress.org/plugins/wp-crontrol/
5
  * Description: WP Crontrol lets you view and control what's happening in the WP-Cron system.
6
  * Author: <a href="http://www.scompt.com/">Edward Dale</a> & <a href="http://lud.icro.us/">John Blackbourn</a>
7
+ * Version: 1.2.2
8
  * Text Domain: crontrol
9
  * Domain Path: /gettext/
10
  */
55
  add_action($activate_action, array(&$this, 'action_activate'));
56
 
57
  add_filter('cron_schedules', array(&$this, 'filter_cron_schedules'));
58
+ add_action('crontrol_cron_job', array(&$this, 'action_php_cron_event'));
59
  }
60
 
61
  /**
62
  * Evaluates the provided code using eval.
63
  */
64
+ function action_php_cron_event($code) {
65
  eval($code);
66
  }
67
 
171
  }
172
 
173
  /**
174
+ * Executes a cron event immediately.
175
  *
176
+ * Executes an event by scheduling a new single event with the same arguments.
177
  *
178
+ * @param string $hookname The hookname of the cron event to run
179
  */
180
  function run_cron($hookname, $sig) {
181
  $crons = _get_cron_array();
192
  }
193
 
194
  /**
195
+ * Adds a new cron event.
196
  *
197
+ * @param string $next_run A human-readable (strtotime) time that the event should be run at
198
+ * @param string $schedule The recurrence of the cron event
199
  * @param string $hookname The name of the hook to execute
200
+ * @param array $args Arguments to add to the cron event
201
  */
202
  function add_cron($next_run, $schedule, $hookname, $args) {
203
  $next_run = strtotime($next_run);
211
  }
212
 
213
  /**
214
+ * Deletes a cron event.
215
  *
216
+ * @param string $name The hookname of the event to delete.
217
  */
218
  function delete_cron($to_delete, $sig, $next_run) {
219
  $crons = _get_cron_array();
258
  $extra_scheds = array('twicedaily'=>array('interval'=>43200, 'display'=>__('Twice Daily', 'crontrol')));
259
  add_option('crontrol_schedules', $extra_scheds);
260
 
261
+ // if there's never been a cron event, _get_cron_array will return FALSE
262
  if( _get_cron_array() === FALSE ) {
263
  _set_cron_array(array());
264
  }
354
  <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
355
  <tbody>
356
  <tr>
357
+ <th width="33%" valign="top" scope="row"><label for="cron_internal_name"><?php _e('Internal name', 'crontrol'); ?>:</label></th>
358
+ <td width="67%"><input type="text" size="40" value="" id="cron_internal_name" name="internal_name"/></td>
359
  </tr>
360
  <tr>
361
+ <th width="33%" valign="top" scope="row"><label for="cron_interval"><?php _e('Interval (seconds)', 'crontrol'); ?>:</label></th>
362
+ <td width="67%"><input type="text" size="40" value="" id="cron_interval" name="interval"/></td>
363
  </tr>
364
  <tr>
365
+ <th width="33%" valign="top" scope="row"><label for="cron_display_name"><?php _e('Display name', 'crontrol'); ?>:</label></th>
366
+ <td width="67%"><input type="text" size="40" value="" id="cron_display_name" name="display_name"/></td>
367
  </tr>
368
  </tbody></table>
369
  <p class="submit"><input id="schedadd-submit" type="submit" class="button-primary" value="<?php _e('Add Cron Schedule &raquo;', 'crontrol'); ?>" name="new_schedule"/></p>
389
  */
390
  function schedules_dropdown($current=false) {
391
  $schedules = $this->get_schedules();
392
+ ?>
393
+ <select class="postform" name="schedule">
394
+ <option <?php selected($current, '_oneoff') ?> value="_oneoff"><?php _e('Non-repeating', 'crontrol') ?></option>
395
+ <?php foreach( $schedules as $sched_name=>$sched_data ) { ?>
396
  <option <?php selected($current, $sched_name) ?> value="<?php echo $sched_name ?>">
397
  <?php echo $sched_data['display'] ?> (<?php echo $this->interval($sched_data['interval']) ?>)
398
  </option>
399
  <?php } ?>
400
+ </select>
401
+ <?php
402
  }
403
 
404
  /**
459
  }
460
 
461
  /**
462
+ * Shows the form used to add/edit cron events.
463
  *
464
+ * @param boolean $is_php Whether this is a PHP cron event
465
+ * @param mixed $existing An array of existing values for the cron event, or NULL
466
  */
467
  function show_cron_form($is_php, $existing) {
468
  if( $is_php ) {
469
+ $helper_text = __('Cron events trigger actions in your code. Using the form below, you can enter the schedule of the action, as well as the PHP code for the action itself. Alternatively, the schedule can be specified from within WordPress and the code for the action in a file on on your server using <a href="tools.php?page=crontrol_admin_manage_page&action=new-cron#crontrol_form">this form</a>.', 'crontrol');
470
+ $link = ' (<a href="tools.php?page=crontrol_admin_manage_page#crontrol_form">'. __('Add new event', 'crontrol') .'</a>)';
471
  } else {
472
+ $helper_text = __('Cron events trigger actions in your code. A cron event added using the form below needs a corresponding action hook somewhere in code, perhaps the <code>functions.php</code> file in your theme. It is also possible to create your action hook from within WordPress using <a href="tools.php?page=crontrol_admin_manage_page&action=new-php-cron#crontrol_form">this form</a>.', 'crontrol');
473
+ $link = ' (<a href="tools.php?page=crontrol_admin_manage_page&amp;action=new-php-cron#crontrol_form">'. __('Add new PHP event', 'crontrol') .'</a>)';
474
  }
475
  if( is_array($existing) ) {
476
  $other_fields = wp_nonce_field( "edit-cron_{$existing['hookname']}_{$existing['sig']}_{$existing['next_run']}", "_wpnonce", true, false );
478
  $other_fields .= '<input name="original_sig" type="hidden" value="'. $existing['sig'] .'" />';
479
  $other_fields .= '<input name="original_next_run" type="hidden" value="'. $existing['next_run'] .'" />';
480
  $existing['args'] = $is_php ? $existing['args']['code'] : json_encode($existing['args']);
481
+ $existing['next_run'] = date('Y-m-d H:i:s', $existing['next_run']);
482
  $action = $is_php ? 'edit_php_cron' : 'edit_cron';
483
+ $button = $is_php ? __('Modify PHP Cron Event', 'crontrol') : __('Modify Cron Event', 'crontrol');
484
  $link = false;
485
  } else {
486
  $other_fields = wp_nonce_field( "new-cron", "_wpnonce", true, false );
487
  $existing = array('hookname'=>'','hookcode'=>'','args'=>'','next_run'=>'now','schedule'=>false);
488
  $action = $is_php ? 'new_php_cron' : 'new_cron';
489
+ $button = $is_php ? __('Add PHP Cron Event', 'crontrol') : __('Add Cron Event', 'crontrol');
490
  }
491
  ?>
492
  <div id="crontrol_form" class="wrap narrow">
499
  <?php if( $is_php ): ?>
500
  <tr>
501
  <th width="33%" valign="top" scope="row"><label for="hookcode"><?php _e('Hook code', 'crontrol'); ?>:</label></th>
502
+ <td width="67%"><textarea style="width:95%" class="code" rows="5" name="hookcode"><?php echo esc_textarea( $existing['args'] ); ?></textarea></td>
503
  </tr>
504
  <?php else: ?>
505
  <tr>
512
  </tr>
513
  <?php endif; ?>
514
  <tr>
515
+ <th width="33%" valign="top" scope="row"><label for="next_run"><?php _e('Next run (UTC)', 'crontrol'); ?>:</label><br /><span style="font-size:xx-small"><?php _e('e.g., "now", "tomorrow", "+2 days", or "06/04/08 15:27:09"', 'crontrol') ?></th>
516
  <td width="67%"><input type="text" size="40" id="next_run" name="next_run" value="<?php echo esc_attr( $existing['next_run'] ); ?>"/></td>
517
  </tr><tr>
518
+ <th valign="top" scope="row"><label for="schedule"><?php _e('Event schedule', 'crontrol'); ?>:</label></th>
519
  <td>
520
  <?php $this->schedules_dropdown($existing['schedule']) ?>
521
  </td>
535
  if ( empty( $crons ) ) {
536
  return new WP_Error(
537
  'no_events',
538
+ __( 'You currently have no scheduled cron events.', 'crontrol' )
539
  );
540
  }
541
 
566
  */
567
  function admin_manage_page() {
568
  if( isset($_GET['crontrol_message']) ) {
569
+ $messages = array( '1' => __('Successfully executed the cron event <b>%s</b>', 'crontrol'),
570
+ '4' => __('Successfully edited the cron event <b>%s</b>', 'crontrol'),
571
+ '5' => __('Successfully created the cron event <b>%s</b>', 'crontrol'),
572
+ '6' => __('Successfully deleted the cron event <b>%s</b>', 'crontrol'),
573
+ '7' => __('Failed to the delete the cron event <b>%s</b>', 'crontrol'),
574
+ '8' => __('Failed to the execute the cron event <b>%s</b>', 'crontrol'));
575
  $hook = $_GET['crontrol_name'];
576
  $msg = sprintf($messages[$_GET['crontrol_message']], $hook);
577
 
580
  $events = $this->get_cron_events();
581
  $doing_edit = (isset( $_GET['action']) && $_GET['action']=='edit-cron') ? $_GET['id'] : false ;
582
  $time_format = 'Y/m/d H:i:s';
583
+
584
+ $tzstring = get_option( 'timezone_string' );
585
+ $current_offset = get_option( 'gmt_offset' );
586
+
587
+ if ( $current_offset >= 0 )
588
+ $current_offset = '+' . $current_offset;
589
+
590
+ if ( '' === $tzstring )
591
+ $tz = sprintf( 'UTC%s', $current_offset );
592
+ else
593
+ $tz = sprintf( '%s (UTC%s)', str_replace( '_', ' ', $tzstring ), $current_offset );
594
+
595
  $this->show_cron_status();
596
+
597
  ?>
598
  <div class="wrap">
599
  <?php screen_icon(); ?>
600
+ <h2><?php _e('WP-Cron Events', 'crontrol'); ?></h2>
601
  <p></p>
602
  <table class="widefat">
603
  <thead>
646
  </tbody>
647
  </table>
648
 
649
+ <div class="tablenav">
650
+ <p class="description">
651
+ <?php printf(__('Local timezone is <code>%s</code>', 'crontrol'), $tz ); ?>
652
+ <span id="utc-time"><?php printf(__('UTC time is <code>%s</code>', 'crontrol'), date_i18n($time_format, false, true)); ?></span>
653
+ <span id="local-time"><?php printf(__('Local time is <code>%s</code>', 'crontrol'), date_i18n($time_format)); ?></span>
654
+ </p>
655
+ </div>
656
 
657
  </div>
658
  <?php