| 1 |
<?php |
| 2 |
namespace FileBird\Classes; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Schedule { |
| 7 |
public function __construct() { |
| 8 |
add_action( 'filebird_remove_zip_files', array( $this, 'actionRemoveZipFiles' ) ); |
| 9 |
} |
| 10 |
|
| 11 |
public static function registerSchedule() { |
| 12 |
if ( ! wp_next_scheduled( 'filebird_remove_zip_files' ) ) { |
| 13 |
wp_schedule_event( time(), 'daily', 'filebird_remove_zip_files' ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
public static function clearSchedule() { |
| 18 |
wp_clear_scheduled_hook( 'filebird_remove_zip_files' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function actionRemoveZipFiles() { |
| 22 |
$saved_downloads = get_option( 'filebird_saved_downloads', array() ); |
| 23 |
if ( ! is_array( $saved_downloads ) ) { |
| 24 |
$saved_downloads = array(); |
| 25 |
} |
| 26 |
foreach ( $saved_downloads as $time => $path ) { |
| 27 |
if ( ( time() - $time ) >= ( 24 * 60 * 60 ) ) { |
| 28 |
$wp_dir = wp_upload_dir(); |
| 29 |
if ( file_exists( $wp_dir['basedir'] . $path ) ) { |
| 30 |
unlink( $wp_dir['basedir'] . $path ); |
| 31 |
} |
| 32 |
unset( $saved_downloads[ $time ] ); |
| 33 |
} |
| 34 |
} |
| 35 |
update_option( 'filebird_saved_downloads', $saved_downloads ); |
| 36 |
} |
| 37 |
} |
| 38 |
|