Added: Clean Up settings

This commit is contained in:
Hoang Huu
2020-06-04 14:13:29 +07:00
parent c6a75c3b49
commit 13bc6c7ea1
13 changed files with 386 additions and 199 deletions

View File

@@ -353,75 +353,6 @@ function opalestate_hook_callback( $args ) {
do_action( 'opalestate_' . $args['id'] );
}
register_activation_hook( __FILE__, 'opalestate_active_cron_jobs' );
function opalestate_active_cron_jobs() {
if ( ! wp_next_scheduled( 'opalestate_cleanup' ) ) {
wp_schedule_event( time(), 'daily', 'opalestate_cleanup' );
}
}
register_deactivation_hook( __FILE__, 'opalestate_deactive_cron_jobs' );
function opalestate_deactive_cron_jobs() {
wp_clear_scheduled_hook( 'opalestate_cleanup' );
}
function opalestate_cleanup() {
$query = new WP_Query(
[
'post_type' => 'attachment',
'post_status' => 'inherit',
'date_query' => [
'column' => 'post_date',
'before' => date( 'Y-m-d', strtotime( '-1 days' ) ),
],
'meta_query' => [
[
'key' => '_pending_to_use_',
'value' => 1,
'compare' => '>=',
],
],
]
);
// clean up per day
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
wp_delete_attachment( get_the_ID() );
}
}
wp_reset_postdata();
// Change status expired properties.
$expired_query = new WP_Query( [
'post_type' => 'opalestate_property',
'post_status' => [ 'pending', 'publish' ],
'meta_query' => [
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'expired_time',
'value' => time(),
'compare' => '>=',
'type' => 'NUMERIC',
],
],
] );
if ( $expired_query->have_posts() ) {
while ( $expired_query->have_posts() ) {
$expired_query->the_post();
wp_update_post( [
'ID' => get_the_ID(),
'post_status' => 'expired',
] );
}
}
wp_reset_postdata();
}
/**
* Searches for users via ajax and returns a list of results
*