Drafts Scheduler - Version 1.1

Version Description

Bug fixes: - Proper calculation of time for intervals - Proper scheduling of future posts (big oops) - Update options page to remember settings after updating - Remove debugging code on update - Display message if there are no drafts to update

Download this release

Release Info

Developer talus
Plugin Icon wp plugin Drafts Scheduler
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. draft-scheduler.php +55 -38
  2. readme.txt +9 -1
draft-scheduler.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Drafts Scheduler
4
  Plugin URI: http://www.installedforyou.com/draftscheduler
5
  Description: Allows WordPress admins to bulk schedule posts currently saved as drafts
6
  Author: Jeff Rose
7
- Version: 1.0
8
  Author URI: http://www.installedforyou.com
9
 
10
  */
@@ -211,15 +211,15 @@ if (!class_exists('DraftScheduler')) {
211
  <td>
212
  <input type="radio" name="randomness" value="fullrandom" <?php if ($_POST['randomness'] == "fullrandom") echo " checked " ?>> Surprise me <em>(posts entirely randomly after the date above, but within the times below)</em><br />
213
  Post up to <input type="text" name="postsperday" id="postsperda" value="<?php echo $_POST['postsperday']; ?>" size="3" maxlength="3" /> posts per day<br />
214
- Randomly after:
215
  <select name="startTime" id="startTime">
216
  <option value="">Choose a time</option>
217
- <?php echo self::createDateTimeDropDowns($startTime); ?>
218
  </select><br />
219
  And before:
220
  <select name="endTime" id="endTime">
221
  <option value="">Choose a time</option>
222
- <?php echo self::createDateTimeDropDowns($endTime); ?>
223
  </select><br />
224
  </td>
225
  </tr>
@@ -243,48 +243,44 @@ if (!class_exists('DraftScheduler')) {
243
 
244
  $postsToday = rand( 0, $dailyMax * 100 ) / 100;
245
 
246
- $startPosts = date( 'Y-n-j g:i:s', strtotime($startDate . ' ' . $startTime));
247
 
248
  $randInterval = (strtotime($endTime) - strtotime($startTime));
249
 
250
- $findDrafts = "SELECT id FROM " .$wpdb->prefix . "posts WHERE post_status = 'draft' ORDER BY rand()";
251
 
252
  $draftList = $wpdb->get_results($findDrafts);
253
 
 
 
 
 
254
  $finished = false;
255
 
256
  while ( ! $finished ):
257
 
258
  if ( 0 >= $postsToday ){
259
  $postsToday = rand( 0, $dailyMax * 100 ) / 100;
260
- $startPosts = date( 'Y-n-j g:i:s', strtotime( "+1 day", strtotime($startPosts) ) );
261
  }
262
 
263
  $thisDraft = array_pop( $draftList );
264
  $postRandom = rand( 0, $randInterval );
265
- $postTime = date('Y-n-j G:i:s', strtotime( "+" . $postRandom . " seconds", strtotime($startPosts)));
266
 
267
- echo $postsToday . " --- " . $thisDraft->id . " to " . $startPosts . " .... " . $postTime . "<br />";
268
- //$wpdb->show_errors();
269
  $wpdb->update( $wpdb->prefix . 'posts', array( 'post_date' => $postTime ,
270
  'post_date_gmt' => get_gmt_from_date( $postTime),
271
- 'post_status' => 'future' ), array( 'ID' => $thisDraft->id )
272
  );
273
- //$wpdb->print_error();
 
 
274
  if ( 0 == count($draftList) ){
275
  $finished = true;
276
  }
277
  $postsToday --;
278
  endwhile;
279
 
280
- // foreach ($draftList as $thisDraft){
281
- //
282
- // $wpdb->update( $wpdb->prefix . 'posts', array( 'post_date' => '(' . $startPosts . ' + interval rand()*' . $randInterval .' second)' ,
283
- // 'post_date_gmt' => get_gmt_from_date(date('Y-n-j G:i:s', $postDate)),
284
- // 'post_status' => 'future' ), array( 'ID' => $thisDraft->id )
285
- // );
286
- // };
287
-
288
  return "Drafts updated!";
289
  //return $query;
290
  }
@@ -303,23 +299,33 @@ if (!class_exists('DraftScheduler')) {
303
 
304
  $intvSecs = ($intvHours * 60 * 60) + ($intvMins * 60);
305
 
306
- $findDrafts = "SELECT id FROM " .$wpdb->prefix . "posts WHERE post_status = 'draft' ORDER BY rand()";
307
 
308
  $draftList = $wpdb->get_results($findDrafts);
309
 
310
- $postDate = strtotime($startDate);
 
 
 
 
311
 
 
 
312
  foreach ($draftList as $thisDraft){
313
- $wpdb->update( $wpdb->prefix . 'posts', array( 'post_date' => date('Y-n-j G:i:s', $postDate),
314
- 'post_date_gmt' => get_gmt_from_date(date('Y-n-j G:i:s', $postDate)),
315
- 'post_status' => 'future' ),
316
- array( 'ID' => $thisDraft->id )
 
 
317
  );
318
- $postDate = $postDate + $intvSecs;
319
- $drafts .= ' ' . date('Y-n-j G:i:s', $postDate) . ' ';
 
 
320
  }
321
  //$query = "update";
322
- return $drafts;
323
  } // End Function draftScheduler_random_post_by_interval
324
 
325
  /*
@@ -335,19 +341,30 @@ if (!class_exists('DraftScheduler')) {
335
  */
336
  $intvSecs = ($intvHours * 60 * 60) + ($intvMins * 60);
337
 
338
- $findDrafts = "SELECT id FROM " .$wpdb->prefix . "posts WHERE post_status = 'draft' ORDER BY id ASC";
339
 
340
  $draftList = $wpdb->get_results($findDrafts);
341
 
342
- $postDate = strtotime($startDate);
 
 
 
 
343
 
344
  foreach ($draftList as $thisDraft){
345
- $wpdb->update( $wpdb->prefix . 'posts', array( 'post_date' => date('Y-n-j G:i:s', $postDate), 'post_date_gmt' => get_gmt_from_date(date('Y-n-j G:i:s', $postDate)), 'post_status' => 'future' ), array( 'ID' => $thisDraft->id ) );
346
- $postDate = $postDate + $intvSecs;
347
- $drafts .= ' ' . date('Y-n-j G:i:s', $postDate) . ' ';
 
 
 
 
 
 
 
 
348
  }
349
- //$query = "update";
350
- return $drafts;
351
 
352
  } // End Function draftScheduler_sequential_post_by_interval
353
 
@@ -365,12 +382,12 @@ if (!class_exists('DraftScheduler')) {
365
  }
366
  $outputHTML .= '<option value="'.$hourTime.':00"';
367
  if ($hourTime . ":00" == $selected) {
368
- $outputHTML .= " selected ";
369
  }
370
  $outputHTML .= '>'.$hourTime.':00</option>';
371
  $outputHTML .= '<option value="'.$hourTime.':30"';
372
  if ($hourTime . ":30" == $selected) {
373
- $outputHTML .= " selected ";
374
  }
375
  $outputHTML .= '>'.$hourTime.':30</option>';
376
  }
4
  Plugin URI: http://www.installedforyou.com/draftscheduler
5
  Description: Allows WordPress admins to bulk schedule posts currently saved as drafts
6
  Author: Jeff Rose
7
+ Version: 1.1
8
  Author URI: http://www.installedforyou.com
9
 
10
  */
211
  <td>
212
  <input type="radio" name="randomness" value="fullrandom" <?php if ($_POST['randomness'] == "fullrandom") echo " checked " ?>> Surprise me <em>(posts entirely randomly after the date above, but within the times below)</em><br />
213
  Post up to <input type="text" name="postsperday" id="postsperda" value="<?php echo $_POST['postsperday']; ?>" size="3" maxlength="3" /> posts per day<br />
214
+ Randomly after:
215
  <select name="startTime" id="startTime">
216
  <option value="">Choose a time</option>
217
+ <?php echo self::createDateTimeDropDowns($_POST['startTime']); ?>
218
  </select><br />
219
  And before:
220
  <select name="endTime" id="endTime">
221
  <option value="">Choose a time</option>
222
+ <?php echo self::createDateTimeDropDowns($_POST['endTime']); ?>
223
  </select><br />
224
  </td>
225
  </tr>
243
 
244
  $postsToday = rand( 0, $dailyMax * 100 ) / 100;
245
 
246
+ $startPosts = date_i18n( 'Y-n-j g:i:s', strtotime($startDate . ' ' . $startTime));
247
 
248
  $randInterval = (strtotime($endTime) - strtotime($startTime));
249
 
250
+ $findDrafts = "SELECT ID FROM " .$wpdb->prefix . "posts WHERE post_status = 'draft' ORDER BY rand()";
251
 
252
  $draftList = $wpdb->get_results($findDrafts);
253
 
254
+ if ( empty($draftList) ) {
255
+ return "No drafts were found";
256
+ }
257
+
258
  $finished = false;
259
 
260
  while ( ! $finished ):
261
 
262
  if ( 0 >= $postsToday ){
263
  $postsToday = rand( 0, $dailyMax * 100 ) / 100;
264
+ $startPosts = date_i18n( 'Y-n-j g:i:s', strtotime( "+1 day", strtotime($startPosts) ) );
265
  }
266
 
267
  $thisDraft = array_pop( $draftList );
268
  $postRandom = rand( 0, $randInterval );
269
+ $postTime = date_i18n('Y-n-j G:i:s', strtotime( "+" . $postRandom . " seconds", strtotime($startPosts)));
270
 
 
 
271
  $wpdb->update( $wpdb->prefix . 'posts', array( 'post_date' => $postTime ,
272
  'post_date_gmt' => get_gmt_from_date( $postTime),
273
+ 'post_status' => 'future' ), array( 'ID' => $thisDraft->ID )
274
  );
275
+ $wpdb->print_error();
276
+ check_and_publish_future_post($thisDraft->ID);
277
+
278
  if ( 0 == count($draftList) ){
279
  $finished = true;
280
  }
281
  $postsToday --;
282
  endwhile;
283
 
 
 
 
 
 
 
 
 
284
  return "Drafts updated!";
285
  //return $query;
286
  }
299
 
300
  $intvSecs = ($intvHours * 60 * 60) + ($intvMins * 60);
301
 
302
+ $findDrafts = "SELECT * FROM " .$wpdb->posts . " WHERE post_status = 'draft' ORDER BY rand()";
303
 
304
  $draftList = $wpdb->get_results($findDrafts);
305
 
306
+ if ( empty($draftList) ) {
307
+ return "No drafts were found";
308
+ }
309
+
310
+ $startDate = $startDate;
311
 
312
+ $ds_postDate = strtotime($startDate);
313
+
314
  foreach ($draftList as $thisDraft){
315
+ $ds_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $ds_postDate));
316
+ $wpdb->update( $wpdb->posts, array( 'post_date' => date_i18n('Y-n-j G:i:s', $ds_postDate),
317
+ 'post_date_gmt' => $ds_gmt,
318
+ 'post_status' => 'future'
319
+ ),
320
+ array( 'ID' => $thisDraft->ID )
321
  );
322
+
323
+ check_and_publish_future_post($thisDraft->ID);
324
+
325
+ $ds_postDate += $intvSecs;
326
  }
327
  //$query = "update";
328
+ return "Drafts updated!";
329
  } // End Function draftScheduler_random_post_by_interval
330
 
331
  /*
341
  */
342
  $intvSecs = ($intvHours * 60 * 60) + ($intvMins * 60);
343
 
344
+ $findDrafts = "SELECT ID FROM " .$wpdb->posts . " WHERE post_status = 'draft' ORDER BY id ASC";
345
 
346
  $draftList = $wpdb->get_results($findDrafts);
347
 
348
+ if ( empty( $draftList ) ) {
349
+ return "No drafts were found";
350
+ }
351
+
352
+ $ds_postDate = strtotime($startDate);
353
 
354
  foreach ($draftList as $thisDraft){
355
+ $ds_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $ds_postDate));
356
+ $wpdb->update( $wpdb->posts, array( 'post_date' => date_i18n('Y-n-j G:i:s', $ds_postDate),
357
+ 'post_date_gmt' => $ds_gmt,
358
+ 'post_status' => 'future'
359
+ ),
360
+ array( 'ID' => $thisDraft->ID )
361
+ );
362
+
363
+ check_and_publish_future_post($thisDraft->ID);
364
+
365
+ $ds_postDate += $intvSecs;
366
  }
367
+ return "Drafts updated!";
 
368
 
369
  } // End Function draftScheduler_sequential_post_by_interval
370
 
382
  }
383
  $outputHTML .= '<option value="'.$hourTime.':00"';
384
  if ($hourTime . ":00" == $selected) {
385
+ $outputHTML .= " selected='selected' ";
386
  }
387
  $outputHTML .= '>'.$hourTime.':00</option>';
388
  $outputHTML .= '<option value="'.$hourTime.':30"';
389
  if ($hourTime . ":30" == $selected) {
390
+ $outputHTML .= " selected='selected' ";
391
  }
392
  $outputHTML .= '>'.$hourTime.':30</option>';
393
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.installedforyou.com/wordpress/drafts-scheduler-plugin/
4
  Tags: drafts, scheduling, posts, schedule
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
- Stable tag: 1.0
8
 
9
  Sequentially or randomly schedule ALL draft posts for posting.
10
 
@@ -47,5 +47,13 @@ Again, sorry, not in this version. In the future, it would be easy to add.
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
 
 
50
  = 1.0 =
51
  * First version released.
4
  Tags: drafts, scheduling, posts, schedule
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
+ Stable tag: 1.1
8
 
9
  Sequentially or randomly schedule ALL draft posts for posting.
10
 
47
 
48
  == Changelog ==
49
 
50
+ = 1.1 =
51
+ Bug fixes:
52
+ - Proper calculation of time for intervals
53
+ - Proper scheduling of future posts (big oops)
54
+ - Update options page to remember settings after updating
55
+ - Remove debugging code on update
56
+ - Display message if there are no drafts to update
57
+
58
  = 1.0 =
59
  * First version released.