get_id() ]; $group = 'advanced_ads'; $expiry = $ad->get_expiry_date(); as_unschedule_action( Constants::CRON_JOB_AD_EXPIRATION, $args, $group ); if ( 0 === $expiry ) { delete_post_meta( $ad->get_id(), Constants::AD_META_EXPIRATION_TIME ); return; } $datetime = ( new DateTimeImmutable() )->setTimestamp( $expiry ); update_post_meta( $ad->get_id(), Constants::AD_META_EXPIRATION_TIME, $datetime->format( 'Y-m-d H:i:s' ) ); // Schedule new expiration action. as_schedule_single_action( $expiry, Constants::CRON_JOB_AD_EXPIRATION, $args, $group ); } /** * Update post status to expired * * @param int $post_id Post ID. * * @return void */ public function update_ad_status( $post_id ): void { kses_remove_filters(); wp_update_post( [ 'ID' => $post_id, 'post_status' => Constants::AD_STATUS_EXPIRED, ] ); kses_init_filters(); } }