PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / 2.0.6
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF v2.0.6
2.0.6 2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / admin / ajax / backup.php
robin-image-optimizer / admin / ajax Last commit date
backup.php 7 months ago index.php 3 years ago logs.php 7 months ago meta-migrations.php 7 months ago multisite-update-current-blog.php 7 months ago settings.php 7 months ago
backup.php
109 lines
1 <?php
2 /**
3 * Back-up related filters.
4 *
5 * @version 1.0
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * AJAX обработчик восстановления из резервной копии
15 */
16 add_action(
17 'wp_ajax_wio_restore_backup',
18 function () {
19 check_admin_referer( 'wio-iph' );
20
21 if ( ! current_user_can( 'manage_options' ) ) {
22 wp_die( - 1 );
23 }
24
25 $max_process_per_request = 25;
26
27 // $blog_id = WRIO_Plugin::app()->request->post( 'blog_id', null, true );
28
29 /*
30 if ( $blog_id !== null ) {
31 switch_to_blog( $blog_id );
32 }*/
33
34 // Total number of remained images to restore
35 $remane_count = 0;
36
37 $total = 0;
38
39 $filter_results = apply_filters( 'wbcr/rio/backup/restore_filter', $max_process_per_request );
40
41 if ( isset( $filter_results['remane'] ) ) {
42 $remane_count += $filter_results['remane'];
43 }
44
45 if ( isset( $filter_results['total'] ) ) {
46 $total += $filter_results['total'];
47 }
48
49 $media_library = WRIO_Media_Library::get_instance();
50
51 $total += $media_library->getOptimizedCount();
52
53 $restored_data = $media_library->restoreAllFromBackup( $max_process_per_request );
54
55 if ( isset( $restored_data['remain'] ) ) {
56 $remane_count += $restored_data['remain'];
57 }
58
59 /*
60 if ( $blog_id !== null ) {
61 restore_current_blog();
62 }*/
63
64 $restored_data['total'] = $total;
65
66 if ( $total > 0 ) {
67 $restored_data['percent'] = 100 - ( $remane_count * 100 / $total );
68 } else {
69 $restored_data['percent'] = 0;
70 }
71
72 // если изображения закончились - посылаем команду завершения
73 if ( $remane_count <= 0 ) {
74 $restored_data['end'] = true;
75 }
76
77 wp_send_json( $restored_data );
78 }
79 );
80
81 /**
82 * AJAX обработчик очистки папки с бекапами
83 */
84 add_action(
85 'wp_ajax_wio_clear_backup',
86 function () {
87 check_admin_referer( 'wio-iph' );
88
89 if ( ! current_user_can( 'manage_options' ) ) {
90 wp_die( - 1 );
91 }
92
93 $backup = WIO_Backup::get_instance();
94 $blogs = WRIO_Plugin::app()->request->post( 'blogs', [], true );
95
96 if ( ! empty( $blogs ) ) {
97 foreach ( $blogs as $blog_id ) {
98 switch_to_blog( intval( $blog_id ) );
99 $backup->removeBlogBackupDir();
100 restore_current_blog();
101 }
102 } else {
103 $backup->removeBackupDir();
104 }
105
106 wp_send_json( true );
107 }
108 );
109