Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin/Cron/
?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin
<?php
namespace KS_PAC_DCFH\Admin\Cron;
if (!defined('ABSPATH')) {
exit;
}
class Entries_Auto_Delete
{
private $hook;
private $recurrence;
private $interval;
public function init(): void
{
if (ks_pac_dcfh_db()::is_setting_enabled('pwh_dcfh_delete_entries_enabled')) {
$schedule = ks_pac_dcfh_db()::get_setting('pwh_dcfh_delete_entries_schedule');
if (!empty($schedule)) {
$this->hook = 'dcfh_delete_entries_'.$schedule;
$this->interval = $schedule;
$this->recurrence = 'recurrence_'.$schedule;
add_filter('cron_schedules', [$this, 'maybe_add_custom_schedules']);
add_action('init', [$this, 'maybe_schedule_event']);
add_action($this->hook, [$this, 'maybe_process_cron']);
}
}
}
public function maybe_add_custom_schedules($schedules)
{
$schedules[$this->recurrence] = [
'interval' => ($this->interval * DAY_IN_SECONDS),
'display' => sprintf('Every %s Days', $this->interval),
];
return $schedules;
}
public function maybe_schedule_event(): void
{
if (!wp_next_scheduled($this->hook)) {
wp_schedule_event(time(), $this->recurrence, $this->hook);
}
}
public function maybe_process_cron(): void
{
$statuses = (array)ks_pac_dcfh_db()::get_setting('pwh_dcfh_delete_entries_status');
if (!empty($statuses)) {
$statuses = array_filter($statuses, static function ($e) {
return ($e !== 'off');
});
$statuses = array_keys($statuses);
if (!empty($statuses)) {
$posts_ids = get_posts([
'fields' => 'ids',
'post_type' => 'pwh_dcfh',
'post_status' => [$statuses],
'posts_per_page' => -1,
'date_query' => [['before' => "$this->interval day ago"]],
]);
if (!empty($posts_ids)) {
$upload_tmp_dir = ks_pac_dcfh_file_helper()::get_tmp_upload_dir();
foreach ($posts_ids as $post_id) {
$post_excerpt = get_post_field('post_excerpt', $post_id);
if (is_serialized($post_excerpt)) {
$form_entries = ks_pac_dcfh_general_helper()::maybe_unserialize($post_excerpt);
if (!empty($form_entries) && is_array($form_entries)) {
$contact_form_id = ks_pac_dcfh_post_meta()::get_contact_form_id_meta_value($post_id);
foreach ($form_entries as $form_entry) {
if ('file' === $form_entry['type'] || 'signature_pad' === $form_entry['type']) {
$attachments = explode(',', $form_entry['value']);
if (!empty($attachments) && is_array($attachments)) {
foreach ($attachments as $attachment) {
if (isset($form_entry['is_media_library']) && $form_entry['is_media_library']) {
$attached_medias = get_attached_media('', $post_id);
foreach ($attached_medias as $attached_media) {
wp_delete_attachment($attached_media->ID, 'true');
}
} else {
$subdir = $form_entry['subdir'] ?? '';
$upload_dir = ks_pac_dcfh_file_helper()::get_form_upload_dir($contact_form_id, $subdir, $attachment);
if (et_()->WPFS()->is_file($upload_dir) && et_()->WPFS()->exists($upload_dir)) {
wp_delete_file($upload_dir);
}
}
// Delete From Temp Directory
$upload_tmp_dir = path_join($upload_tmp_dir, $attachment);
if (et_()->WPFS()->is_file($upload_tmp_dir) && et_()->WPFS()->exists($upload_tmp_dir)) {
wp_delete_file($upload_tmp_dir);
}
}
}
}
}
wp_delete_post($post_id);
// Delete Sent Email Logs
ks_pac_dcfh_logger()->delete_logs('sent_email_log', $post_id);
}
}
}
}
}
}
}
}