PluginProbe
FileBird – WordPress Media Library Folders & File Manager / 6.3.4
FileBird – WordPress Media Library Folders & File Manager v6.3.4
6.5.8 6.5.7 6.5.5 6.5.4 trunk 4.3.1 5.1.6 5.3 5.3.2 5.4.3 5.4.4 5.4.5 5.5 5.5.3 5.5.5 5.5.8 5.5.8.1 5.6 5.6.1 5.6.2 5.6.3 5.6.4 6.2.3 6.2.5 6.3 All 36 releases
filebird / includes / Classes / Schedule.php

Schedule.php in FileBird – WordPress Media Library Folders & File Manager 6.3.4, at includes/Classes/Schedule.php

53 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FileBird\Classes;
3
4 defined( 'ABSPATH' ) || exit;
5
6 use FileBird\Model\Folder as FolderModel;
7 class Schedule {
8 public function __construct() {
9 add_action( 'filebird_remove_zip_files', array( $this, 'actionRemoveZipFiles' ) );
10 add_action( 'filebird_every_12_hours_jobs', array( $this, 'backupFileBird' ) );
11 }
12
13 public static function registerSchedule() {
14 if ( ! wp_next_scheduled( 'filebird_remove_zip_files' ) ) {
15 wp_schedule_event( time(), 'daily', 'filebird_remove_zip_files' );
16 }
17 if ( ! wp_next_scheduled( 'filebird_every_12_hours_jobs' ) ) {
18 wp_schedule_event( time(), 'twicedaily', 'filebird_every_12_hours_jobs' );
19 }
20 }
21
22 public static function clearSchedule() {
23 wp_clear_scheduled_hook( 'filebird_remove_zip_files' );
24 wp_clear_scheduled_hook( 'filebird_every_12_hours_jobs' );
25 }
26
27 public function actionRemoveZipFiles() {
28 $saved_downloads = get_option( 'filebird_saved_downloads', array() );
29 if ( ! is_array( $saved_downloads ) ) {
30 $saved_downloads = array();
31 }
32 foreach ( $saved_downloads as $time => $path ) {
33 if ( ( time() - $time ) >= ( 24 * 60 * 60 ) ) {
34 $wp_dir = wp_upload_dir();
35 if ( file_exists( $wp_dir['basedir'] . $path ) ) {
36 unlink( $wp_dir['basedir'] . $path );
37 }
38 unset( $saved_downloads[ $time ] );
39 }
40 }
41 update_option( 'filebird_saved_downloads', $saved_downloads );
42 }
43 public function backupFileBird() {
44 global $wpdb;
45 $keep = 29;
46 $count_backup = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->options} WHERE `option_name` LIKE 'filebird_backup_%'" );
47 if( $count_backup > $keep ) {
48 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE 'filebird_backup_%' ORDER BY `option_id` ASC LIMIT " . (int)($count_backup - $keep) );
49 }
50 $folders = FolderModel::exportAll();
51 update_option( 'filebird_backup_' . date('Y_m_d_H_i_s'), $folders, false );
52 }
53 }