Last active
February 10, 2017 12:35
-
-
Save kish2011/7da4d8abd4206a4823e13d1e7202b061 to your computer and use it in GitHub Desktop.
Delete Expired Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Delete Expired Jobs | |
* @version 0.0.1 | |
* @see http://opentuteplus.com/delete-expired-jobs-locomotive/ | |
*/ | |
/* | |
Plugin Name: Delete Expired Jobs | |
Plugin URI: https://shop.opentuteplus.com | |
Description: Delete Expired Jobs | |
Version: 0.0.1 | |
Author URI: http://iamkisho.re | |
*/ | |
function find_expired_jobs() { | |
register_batch_process( array( | |
'name' => 'Delete Expired Jobs', | |
'type' => 'post', | |
'args' => array( | |
'post_type' => 'job_listing', | |
'post_status' => 'expired' | |
), | |
'callback' => 'delete_expired_jobs', // callback function | |
) ); | |
} | |
add_action( 'locomotive_init', 'find_expired_jobs' ); | |
function delete_expired_jobs( $post ) { | |
$media = get_children(array( | |
'post_parent' => $post->ID, | |
'post_type' => 'attachment' | |
)); | |
if (!empty($media)) { | |
foreach ($media as $file) { | |
wp_delete_attachment($file->ID); // @todo need to check if media file is not attached to other post. | |
} | |
} | |
wp_delete_post( $post->ID, true ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment