?? GreyFile — Mystic File Browser

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

?? Viewing: Delete_Tmp_Files.php

<?php

namespace KS_PAC_DCFH\Admin\Cron;

if (!defined('ABSPATH')) {
    exit;
}

class Delete_Tmp_Files
{
    private const EXPIRY_TIME = 7200;

    private $hook = 'dcfh_delete_tmp_files';

    private $recurrence = 'twicedaily';

    public function init(): void
    {
        add_action('init', [$this, 'next_scheduled']);
        add_action($this->hook, [$this, 'schedule_event']);
    }

    public function next_scheduled(): void
    {
        if (!wp_next_scheduled($this->hook)) {
            wp_schedule_event(time(), $this->recurrence, $this->hook);
        }
    }

    public function schedule_event(): void
    {
        if (!function_exists('list_files')) {
            require_once(ABSPATH.'wp-admin/includes/file.php');
        }
        $upload_tmp_dir = ks_pac_dcfh_file_helper()::get_tmp_upload_dir();
        $files = list_files($upload_tmp_dir, 100, ['index.php', '.htaccess']);
        if (!empty($files)) {
            usort($files, static function ($a, $b) {
                return filemtime($b) - filemtime($a);
            });
            $now = time();
            foreach ($files as $file) {
                if (is_file($file) && file_exists($file)) {
                    $file_explode = explode('-', pathinfo($file, PATHINFO_FILENAME));
                    if (is_array($file_explode)) {
                        $file_timestamp = end($file_explode);
                        if (1 === preg_match('~^[1-9][0-9]*$~', $file_timestamp)) {
                            if (($now - $file_timestamp) > self::EXPIRY_TIME) {
                                wp_delete_file($file);
                            }
                        }
                    }
                }
            }
        }
    }
}


??

??