Thanks Shofer for reacting to handig !
I just saw this topic.
As for the “bug” to only take 5 posts and once an hour, this is intentional to reduce potential serverloads.
I am working on a new version on which the timeout is 30 minutes and it will clear all posts:
/**
* Uses transient instead of cronjob, will run on wp call in frontend.
*/
function prune() {
$lastrun = get_transient('auto-prune-posts-lastrun');
if (false === $lastrun) {
$force_delete = ($this->conf['settings']['force_delete'] == 0) ? false : true;
// Walk
foreach($this->conf['config'] as $cat_id => $type)
{
foreach($type as $the_type => $values)
{
$period_php = $values['period_php']; // Will be in format so strtotime can handle this [int][space][string] example: "4 day" or "5 month"
// Get all posts for this category
$myposts = get_posts('category=' . $cat_id.'&post_type='.$the_type.'&numberposts=-1');
foreach ($myposts AS $post) {
$post_date_plus_visibleperiod = strtotime($post->post_date . " +" . $period_php);
$now = strtotime("now");
if ($post_date_plus_visibleperiod < $now) {
// GOGOGO !
//$this->delete_post_and_attachments($post->ID,$force_delete);
// Mail admin?
if(!empty($this->conf['settings']['admin_email']))
{
$body = "DEMO, no post is delete DEMO Deleting post ID : ".$post->ID. "\n";
$body .= "Post title : ".$post->post_title. "\n";
$body .= "Settings (Delete or Trash) : ".( ($force_delete) ? 'Delete' : 'Trash' ). "\n";
wp_mail($this->conf['settings']['admin_email'],'Plugin auto prune posts notification',$body);
}
}
}
}
}
//set_transient('auto-prune-posts-lastrun', 'lastrun: '.time(), 60*30); // 60*30 = 30 minutes
}
}