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 | Drafts Scheduler |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- draft-scheduler.php +55 -38
- 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.
|
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 =
|
247 |
|
248 |
$randInterval = (strtotime($endTime) - strtotime($startTime));
|
249 |
|
250 |
-
$findDrafts = "SELECT
|
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 =
|
261 |
}
|
262 |
|
263 |
$thisDraft = array_pop( $draftList );
|
264 |
$postRandom = rand( 0, $randInterval );
|
265 |
-
$postTime =
|
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->
|
272 |
);
|
273 |
-
|
|
|
|
|
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
|
307 |
|
308 |
$draftList = $wpdb->get_results($findDrafts);
|
309 |
|
310 |
-
|
|
|
|
|
|
|
|
|
311 |
|
|
|
|
|
312 |
foreach ($draftList as $thisDraft){
|
313 |
-
$
|
314 |
-
|
315 |
-
'
|
316 |
-
|
|
|
|
|
317 |
);
|
318 |
-
|
319 |
-
|
|
|
|
|
320 |
}
|
321 |
//$query = "update";
|
322 |
-
return
|
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
|
339 |
|
340 |
$draftList = $wpdb->get_results($findDrafts);
|
341 |
|
342 |
-
|
|
|
|
|
|
|
|
|
343 |
|
344 |
foreach ($draftList as $thisDraft){
|
345 |
-
$
|
346 |
-
$
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
}
|
349 |
-
|
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.
|
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.
|