-
Notifications
You must be signed in to change notification settings - Fork 3
/
snapshot.php
executable file
·8932 lines (7306 loc) · 330 KB
/
snapshot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Snapshot Pro
Version: 3.3.3
Description: This plugin allows you to take quick on-demand backup snapshots of your working WordPress database. You can select from the default WordPress tables as well as custom plugin tables within the database structure. All snapshots are logged, and you can restore the snapshot as needed.
Author: WPMU DEV
Author URI: https://premium.wpmudev.org/
Plugin URI: https://premium.wpmudev.org/project/snapshot/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: snapshot
Domain Path: languages
Network: true
WDP ID: 257
*/
/**
* @copyright Incsub (http://incsub.com/)
*
* Authors: WPMU DEV
* Contributors: Rheinard Korf (Incsub), Cvetan Cvetanov (Incsub), Paul Menard, Vladislav Bailovic, Aaron Edwards
*
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (GPL-2.0)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*
*/
define('SNAPSHOT_VERSION', '3.3.3');
if ( ! defined( 'SNAPSHOT_I18N_DOMAIN' ) ) {
define( 'SNAPSHOT_I18N_DOMAIN', 'snapshot' );
}
if ( ! defined( 'SNAPSHOT_TD' ) ) {
define( 'SNAPSHOT_TD', 'snapshot' );
}
/* Load important file functions (and everything that goes with it). */
require_once ABSPATH . 'wp-admin/includes/admin.php';
/* Load shared-ui */
require_once 'assets/shared-ui/plugin-ui.php';
require_once 'new-ui-tester.php';
if ( ! class_exists( 'WPMUDEVSnapshot' ) ) {
class WPMUDEVSnapshot {
const OPTION_V4_ADMIN_NOTICE_DISMISSED = 'snapshot3_v4_admin_notice_dismissed';
const OPTION_V4_ADMIN_NOTICE_HIDDEN_UNTIL = 'snapshot3_v4_admin_notice_hidden_until';
const OPTION_V4_MODAL_DISMISSED = 'snapshot3_v4_modal_dismissed';
const OPTION_V4_MODAL_HIDDEN_UNTIL = 'snapshot3_v4_modal_hidden_until';
const OPTION_V4_NOTICE_HIDDEN_UNTIL = 'snapshot3_v4_notice_hidden_until';
const SNAPSHOT_V4_PROJECT_ID = 3760011;
const SNAPSHOT_V4_PLUGIN_FILE = 'snapshot-backups/snapshot-backups.php';
const SNAPSHOT_V4_PAGE_URL = 'admin.php?page=snapshot';
/**
* Singleton instance of the plugin.
*
* @since 2.5
*
* @access private
* @var WPMUDEVSnapshot
*/
private static $instance = null;
public $DEBUG = false;
private $_pagehooks = array(); // A list of our various nav items. Used when hooking into the page load actions.
private $_messages = array(); // Message set during the form processing steps for add, edit, udate, delete, restore actions
private $_settings = array(); // These are global dynamic settings NOT stores as part of the config options
private $_admin_header_error; // Set during processing will contain processing errors to display back to the user
private $snapshot_logger;
private $_session;
public $_snapshot_admin_metaboxes;
public $_new_ui_tester;
private $plugin_path;
private $plugins_dir;
private $plugins_folder;
private $content_folder;
private $plugin_url;
private $plugin_file;
public $form_errors;
public $config_data;
protected function __construct() {
// Creates the class autoloader.
spl_autoload_register( array( $this, 'class_loader' ) );
$this->plugin_file = __FILE__;
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
$this->DEBUG = false;
$this->_settings['SNAPSHOT_VERSION'] = SNAPSHOT_VERSION;
if ( is_multisite() ) {
$this->_settings['SNAPSHOT_MENU_URL'] = network_admin_url() . 'admin.php?page=';
} else {
$this->_settings['SNAPSHOT_MENU_URL'] = get_admin_url() . 'admin.php?page=';
}
if ( defined( 'WP_PLUGIN_DIR' ) && WP_PLUGIN_DIR ) {
$this->plugins_dir = WP_PLUGIN_DIR;
$plugin_folder = str_replace( WP_CONTENT_DIR, '', WP_PLUGIN_DIR );
$this->plugins_folder = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
$this->content_folder = str_replace( $plugin_folder, '', $this->plugins_folder );
} else {
$this->plugins_dir = trailingslashit( WP_CONTENT_DIR ) . 'plugins/';
$this->plugins_folder = 'wp-content/plugins';
$this->content_folder = 'wp-content/';
}
$this->_settings['SNAPSHOT_PLUGIN_URL'] = trailingslashit( WP_PLUGIN_URL ) . basename( dirname( __FILE__ ) );
$this->_settings['SNAPSHOT_PLUGIN_BASE_DIR'] = dirname( __FILE__ );
$this->_settings['admin_menu_label'] = __( "Snapshot", SNAPSHOT_I18N_DOMAIN ); // Used as the 'option_name' for wp_options table
$this->_settings['options_key'] = "wpmudev_snapshot";
$this->_settings['recover_table_prefix'] = "_snap_rcv_";
$this->_settings['backupBaseFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupBackupFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupRestoreFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['destinationClasses'] = array(); // Will be set during page load
$this->_settings['backupLogFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupSessionFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupLockFolderFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupURLFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backupLogURLFull'] = ""; // Will be set during page load in $this->set_backup_folder();
$this->_settings['backup_cron_hook'] = "snapshot_backup_cron"; // Used to identify WP Cron items
$this->_settings['remote_file_cron_hook'] = "snapshot_remote_file_cron"; // Used to identify WP Cron items
//$this->_settings['remote_file_cron_interval'] = "snapshot-15minutes";
$this->_settings['remote_file_cron_interval'] = "snapshot-5minutes";
$this->_admin_header_error = "";
// Add support for new WPMUDEV Dashboard Notices
global $wpmudev_notices;
$wpmudev_notices[] = array(
'id' => 257,
'name' => 'Snapshot',
'screens' => array(
'toplevel_page_snapshot_pro_dashboard',
'toplevel_page_snapshot_pro_dashboard-network',
'snapshot_page_snapshot_pro_snapshots',
'snapshot_page_snapshot_pro_snapshots-network',
'snapshot_page_snapshot_pro_destinations',
'snapshot_page_snapshot_pro_destinations-network',
'snapshot_page_snapshot_pro_managed_backups',
'snapshot_page_snapshot_pro_managed_backups-network',
'snapshot_page_snapshot_pro_import',
'snapshot_page_snapshot_pro_import-network',
'snapshot_page_snapshot_pro_settings',
'snapshot_page_snapshot_pro_settings-network'
),
);
if ( Snapshot_Helper_Utility::is_pro() ) {
include_once dirname( __FILE__ ) . '/lib/WPMUDEV/Dashboard/wpmudev-dash-notification.php';
}
add_action( 'admin_head', array( $this, 'enqueue_shared_ui' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_icon_admin_style' ) );
/* Setup the tetdomain for i18n language handling see http://codex.wordpress.org/Function_Reference/load_plugin_textdomain */
load_plugin_textdomain( SNAPSHOT_I18N_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
/* Standard activation hook for all WordPress plugins see http://codex.wordpress.org/Function_Reference/register_activation_hook */
register_activation_hook( __FILE__, array( $this, 'snapshot_plugin_activation_proc' ) );
register_deactivation_hook( __FILE__, array( $this, 'snapshot_plugin_deactivation_proc' ) );
//add_action('plugins_loaded', array( $this, 'snapshot_plugin_activation_proc' ) );
/* Register admin actions */
add_action( 'init', array( $this, 'snapshot_init_proc' ) );
add_action( 'admin_init', array( $this, 'snapshot_admin_init_proc' ) );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'snapshot_admin_menu_proc' ) );
add_action( 'admin_init', array( $this, 'redirect_old_admin_menus' ) );
if ( Snapshot_Helper_Utility::is_wpmu_hosting() ) {
add_filter( 'submenu_file', array( $this, 'snapshot_remove_managed_page' ) );
add_action( 'current_screen', array( $this, 'snapshot_redirect_managed_page' ) );
}
/* Hook into the WordPress AJAX systems. */
add_action( 'wp_ajax_snapshot_backup_ajax', array( $this, 'snapshot_ajax_backup_proc' ) );
add_action( 'wp_ajax_snapshot_show_blog_tables', array( $this, 'snapshot_ajax_show_blog_tables' ) );
add_action( 'wp_ajax_snapshot_get_blog_restore_info', array( $this, 'snapshot_get_blog_restore_info' ) );
add_action( 'wp_ajax_snapshot_restore_ajax', array( $this, 'snapshot_ajax_restore_proc' ) );
add_action( 'wp_ajax_snapshot_view_log_ajax', array( $this, 'snapshot_ajax_view_log_proc' ) );
add_action( 'wp_ajax_snapshot_item_abort_ajax', array( $this, 'snapshot_ajax_item_abort_proc' ) );
add_action( 'wp_ajax_snapshot_disable_notif_ajax', array( $this, 'snapshot_ajax_disable_notif_proc' ) );
add_action( 'wp_ajax_dismiss_snapshot_aws_comp_notice', array( $this, 'snapshot_ajax_dismiss_aws_comp_notice' ) );
add_action( 'wp_ajax_snapshot_save_key', array( $this, 'snapshot_save_key_proc' ) );
add_action( 'wp_ajax_dismiss_hosting_backups_notice', array( $this, 'dismiss_hosting_backups_notice' ) );
add_action( 'wp_ajax_dismiss_managed_backups_notice', array( $this, 'dismiss_managed_backups_notice' ) );
/* Cron related functions */
add_filter( 'cron_schedules', array( 'Snapshot_Helper_Utility', 'add_cron_schedules' ), 99 );
add_action( $this->_settings['backup_cron_hook'], array( $this, 'snapshot_backup_cron_proc' ) );
add_action( $this->_settings['remote_file_cron_hook'], array( $this, 'snapshot_remote_file_cron_proc' ) );
/* Snapshot Destination AJAX */
add_action( 'snapshot_register_destination', array( $this, 'destination_register_proc' ) );
add_action( 'activated_plugin', array( $this, 'snapshot_activated' ), 10, 2 );
$this->_new_ui_tester = new WPMUDEVSnapshot_New_Ui_Tester();
// Fix home path when integrating with Domain Mapping
add_filter( 'snapshot_home_path', array( $this, 'snapshot_check_home_path' ) );
// Fix DOMAIN_CURRENT_SITE if not configured
add_filter( 'snapshot_current_domain', array( $this, 'snapshot_check_current_domain' ) );
// Fix PATH_CURRENT_SITE if not configured
add_filter( 'snapshot_current_path', array( $this, 'snapshot_check_current_path' ) );
// Run the compat layer for Cron jobs
Snapshot_Controller_Full_Cron::get()->run_compat();
// Run the Hub integration controller
Snapshot_Controller_Full_Hub::get()->run();
// Run Hub reporter controller
Snapshot_Controller_Full_Reporter::get()->run();
add_filter( 'admin_body_class', array( $this, 'snapshot_maybe_add_body_classes' ) );
// Whitelabel plugin pages
add_filter( 'wpmudev_whitelabel_plugin_pages', array( $this, 'snapshot_whitelabel_pages' ) );
/**
* Check should I run cron
*
* @since 3.2.1
*/
add_filter( 'snapshot_maybe_should_it_stop', array( $this, 'maybe_should_it_stop' ) );
// Allow WP Heartbeat API on WP Engine for Snapshot pages
add_filter( 'wpe_heartbeat_allowed_pages', array( $this, 'wpe_allow_heartbeat' ) );
// "Upgrade to 4.0" prompt
add_action( is_multisite() ? 'network_admin_notices' : 'admin_notices', array( $this, 'snapshot_admin_notices_v4_prompt' ) );
add_action( 'wp_ajax_snapshot_admin_notice_v4_dismiss', array( $this, 'ajax_admin_notice_v4_dismiss' ) );
add_action( 'wp_ajax_snapshot_admin_notice_v4_install', array( $this, 'ajax_admin_notice_v4_install' ) );
add_action( 'wp_ajax_snapshot_upgrade_to_v4_modal_dismiss', array( $this, 'ajax_upgrade_to_v4_modal_dismiss' ) );
add_action( 'wp_ajax_snapshot_upgrade_to_v4_notice_dismiss', array( $this, 'ajax_upgrade_to_v4_notice_dismiss' ) );
require_once dirname( __FILE__ ) . '/lib/Snapshot/Helper/Privacy.php';
Snapshot_Gdpr::serve();
if ( ! class_exists( 'Snapshot_Local_Backups' ) ) {
require_once dirname( __FILE__ ) . '/lib/Snapshot/Helper/Local_Backups.php';
}
Snapshot_Local_Backups::serve();
}
public function snapshot_check_home_path( $path ) {
if ( '/' === $path || 2 > strlen( $path ) ) {
$path = ABSPATH;
}
// Flywheel fix.
if ( defined( 'FLYWHEEL_CONFIG_DIR' ) ) {
$path = trailingslashit( dirname( WP_CONTENT_DIR ) );
}
return $path;
}
public function snapshot_check_current_domain( $path ) {
if ( empty( $path ) ) {
$path = preg_replace( '/(http|https):\/\/|\/$/', '', network_home_url() );
}
return $path;
}
public function snapshot_check_current_path( $path ) {
if ( ! defined( $path ) ) {
$blog_details = get_blog_details();
$path = $blog_details->path;
}
return $path;
}
public function snapshot_init_proc() {
if ( ! is_multisite() ) {
$role = get_role( 'administrator' );
if ( $role ) {
$role->add_cap( 'manage_snapshots_items' );
$role->add_cap( 'manage_snapshots_destinations' );
$role->add_cap( 'manage_snapshots_settings' );
$role->add_cap( 'manage_snapshots_import' );
}
$this->load_config();
$this->set_backup_folder();
$this->set_log_folders();
if ( Snapshot_Helper_Utility::is_pro() ) {
Snapshot_Model_Destination::load_destinations();
}
} else {
global $current_site, $current_blog;
if ( $current_site->blog_id == $current_blog->blog_id ) {
$this->load_config();
$this->set_backup_folder();
$this->set_log_folders();
if ( Snapshot_Helper_Utility::is_pro() ) {
Snapshot_Model_Destination::load_destinations();
}
}
}
Snapshot_Controller_Full::get()->run();
if ( Snapshot_Helper_Utility::is_wpmu_hosting() ) {
Snapshot_Controller_Hosting::get()->run();
$model = new Snapshot_Model_Full_Backup();
if ( ! $model->get_config( 'disable_cron', false ) ) {
// Disable any managed backup scheduling.
$model->set_config( 'frequency', false );
$model->set_config( 'schedule_time', false );
$model->set_config( 'disable_cron', true );
Snapshot_Controller_Full_Cron::get()->stop();
// Let the service know
$model->update_remote_schedule();
}
} else {
// Replace the ajax handler fetching hosting backups list, that runs with every page load in the Snapshot dashboard.
add_action( 'wp_ajax_snapshot-hosting_backup-dashboard-list', array( $this, 'json_hosting_backup_dashboard_list_mock' ) );
}
if ( version_compare(PHP_VERSION, '5.5.0', '<') ) {
if ( ! isset ( $this->config_data['transitioned_sdk_incompat'] ) || ! $this->config_data['transitioned_sdk_incompat'] ) {
// Disable existing scheduled managed backups, due to PHP version incompatibility.
$model = new Snapshot_Model_Full_Backup();
$model->set_config( 'frequency', false );
$model->set_config( 'schedule_time', false );
$model->set_config( 'disable_cron', true );
Snapshot_Controller_Full_Cron::get()->stop();
// Let the service know
$model->update_remote_schedule();
if ( isset( $this->config_data['items'] ) ) {
// Also, disable any existing scheduled aws snapshots, due to PHP version incompatibility
foreach ( $this->config_data['items'] as $item_key => $item ) {
$destination = $this->config_data['destinations'][ $item['destination'] ];
if ( 'aws' === $destination['type'] ){
$item['interval'] = 'immediate';
$item['interval-offset'] = array();
$this->add_update_config_item( $item_key, $item );
$timestamp = wp_next_scheduled( $this->_settings['backup_cron_hook'], array( intval( $item_key ) ) );
if ( $timestamp ) {
wp_unschedule_event( $timestamp, $this->_settings['backup_cron_hook'], array( intval( $item_key ) ) );
}
}
}
}
$this->config_data['transitioned_sdk_incompat'] = true;
$this->save_config();
}
} else {
if ( is_main_site() && ( ! isset ( $this->config_data['transitioned_sdk'] ) || ! $this->config_data['transitioned_sdk'] ) ) {
// Before instantiate the S3MultiRegionClient, we check the setup to see if there are older versions of the libs used in the SDK.
if ( ( ! class_exists( 'GuzzleHttp\Client' ) || class_exists( 'GuzzleHttp\Psr7\Response' ) ) && ( ! class_exists( 'Aws\S3\S3Client' ) || class_exists( 'Aws\S3\S3MultiRegionClient' ) ) ) {
// Update the regions of the existing AWS destinations to the new SDK format.
$current_destinations = $this->config_data['destinations'];
if ( ! empty( $current_destinations ) ) {
foreach ( $current_destinations as $key => $destination ) {
if ( 'aws' !== $destination['type']) {
continue;
}
$destination_object = $this->_settings['destinationClasses'][ $destination['type'] ];
$updated_region = $destination_object->get_updated_region( $destination );
if ( $updated_region ) {
$this->config_data['destinations'][ $key ]['region'] = $updated_region;
$this->save_config();
}
}
}
}
$this->config_data['transitioned_sdk'] = true;
$this->save_config();
}
}
}
/**
* Called from WordPress when the admin page init process is invoked.
* Sets up other action and filter needed within the admin area for
* our page display.
* @since 1.0.0
**
* @return void
*/
public function snapshot_admin_init_proc() {
if ( is_multisite() || ! current_user_can( 'manage_snapshots_items' ) ) {
return;
}
/* Hook into the Plugin listing display logic. This will call the function which adds the 'Settings' link on the row for our plugin. */
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'snapshot_plugin_settings_link_proc' ) );
}
/**
* Called when when our plugin is activated. Sets up the initial settings
* and creates the initial Snapshot instance.
*
* @since 1.0.0
* @uses $this->config_data Our class-level config data
* @see $this->__construct() when the action is setup to reference this function
*
* @param none
*
* @return void
*/
public function snapshot_plugin_activation_proc() {
if ( ! is_main_site() ) {
return;
}
$this->load_config();
$this->set_backup_folder();
$this->set_log_folders();
$this->snapshot_scheduler();
}
public function snapshot_plugin_deactivation_proc() {
$this->load_config();
$this->set_backup_folder();
$this->set_log_folders();
$crons = _get_cron_array();
if ( $crons ) {
foreach ( $crons as $cron_time => $cron_set ) {
foreach ( $cron_set as $cron_callback_function => $cron_item ) {
if ( "snapshot_backup_cron" === $cron_callback_function ) {
foreach ( $cron_item as $cron_key => $cron_details ) {
if ( isset( $cron_details['args'][0] ) ) {
$item_key = intval( $cron_details['args'][0] );
$timestamp = wp_next_scheduled( $this->_settings['backup_cron_hook'], array( intval( $item_key ) ) );
wp_unschedule_event( $timestamp, $this->_settings['backup_cron_hook'], array( intval( $item_key ) ) );
}
}
} else if ( $this->_settings['remote_file_cron_hook'] === $cron_callback_function ) {
$timestamp = wp_next_scheduled( $this->_settings['remote_file_cron_hook'] );
wp_unschedule_event( $timestamp, $this->_settings['remote_file_cron_hook'] );
}
}
}
}
Snapshot_Controller_Full::get()->deactivate();
if ( ! class_exists( 'Snapshot_Local_Backups' ) ) {
require_once dirname( __FILE__ ) . '/lib/Snapshot/Helper/Local_Backups.php';
}
Snapshot_Local_Backups::stop();
}
/**
* Display our message on the Snapshot page(s) header for actions taken
*
* @since 1.0.0
* @uses $this->_messages Set in form processing functions
*
* @param string $local_type
* @param string $local_message
*
* @return void
*/
public function snapshot_admin_notices_proc( $local_type = '', $local_message = '' ) {
$message_types = array( 'success', 'warning', 'error' );
$message_type = 'success';
$message_text = '';
// phpcs:ignore
if ( isset( $_REQUEST['message'], $this->_messages[ $_REQUEST['message'] ] ) ) {
$message_type = 'success';
// phpcs:ignore
$message_text = $this->_messages[ $_REQUEST['message'] ];
} elseif ( ! empty( $this->_admin_header_error ) ) {
$message_type = 'error';
$message_text = $this->_admin_header_error;
} elseif ( ! empty( $local_message ) && in_array( $local_type, $message_types, true ) ) {
$message_type = $local_type;
$message_text = $local_message;
}
$message_format = sprintf(
'<div class="%%1$s snapshot-three wps-message wps-%%2$s-message" title="%s">
<div class="wps-%%2$s-message-wrap"><p>%%3$s</p></div>
</div>',
esc_attr__( 'Click to dismiss', SNAPSHOT_I18N_DOMAIN )
);
if ( $message_text && $message_type ) {
echo wp_kses_post( sprintf( $message_format, 'show', esc_attr( $message_type ), $message_text ) );
}
foreach ( $message_types as $message_type ) {
echo wp_kses_post( sprintf( $message_format, 'hide', esc_attr( $message_type ), '' ) );
}
}
/**
* Adds a 'settings' link on the plugin row
*
* @since 1.0.0
* @see $this->admin_init_proc where this function is referenced
*
* @param array links The default links for this plugin.
*
* @return array the same links array as was passed into function but with possible changes.
*/
public function snapshot_plugin_settings_link_proc( $links ) {
$settings_link = sprintf(
'<a href="%s">%s</a>',
esc_url( $this->snapshot_get_pagehook_url( 'snapshots-newui-new-snapshot' ) . '&snapshot-noonce-field=' . esc_attr( wp_create_nonce ( 'snapshot-nonce' ) ) ),
esc_html__( 'Settings', SNAPSHOT_I18N_DOMAIN )
);
array_unshift( $links, $settings_link );
return $links;
}
/**
* Add the new Menu to the Tools section in the WordPress main nav
*
* @since 1.0.0
* @uses $this->_pagehooks
* @see $this->__construct where this function is referenced
*
* @param none
*
* @return void
*/
public function snapshot_admin_menu_proc() {
add_menu_page(
_x( 'Snapshot Pro', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Snapshot', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_dashboard',
array( $this->_new_ui_tester, 'dashboard' ),
'div'
);
$this->_pagehooks['snapshots-newui-dashboard'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Dashboard', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Dashboard', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_dashboard',
array( $this->_new_ui_tester, 'dashboard' )
);
$this->_pagehooks['snapshots-newui-snapshots'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Snapshots', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Snapshots', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_snapshots',
array( $this->_new_ui_tester, 'snapshots' )
);
$this->_pagehooks['snapshots-newui-destinations'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Destinations', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Destinations', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_destinations',
array( $this->_new_ui_tester, 'destinations' )
);
if ( Snapshot_Helper_Utility::is_wpmu_hosting() ) {
$this->_pagehooks['snapshots-newui-hosting-backups'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Backups', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Backups', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_hosting_backups',
array( $this->_new_ui_tester, 'hosting_backups' )
);
}
$this->_pagehooks['snapshots-newui-managed-backups'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Managed Backups', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Managed Backups', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_managed_backups',
array( $this->_new_ui_tester, 'managed_backups' )
);
$this->_pagehooks['snapshots-newui-import'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Import', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Import', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_import',
array( $this->_new_ui_tester, 'import' )
);
$this->_pagehooks['snapshots-newui-settings'] = add_submenu_page(
'snapshot_pro_dashboard',
_x( 'Settings', 'page label', SNAPSHOT_I18N_DOMAIN ),
_x( 'Settings', 'menu label', SNAPSHOT_I18N_DOMAIN ),
'manage_options',
'snapshot_pro_settings',
array( $this->_new_ui_tester, 'settings' )
);
// Hook into the WordPress load page action for our new nav items. This is better then checking page query_str values.
if ( Snapshot_Helper_Utility::is_wpmu_hosting() ) {
$panels = array( 'dashboard', 'snapshots', 'destinations', 'managed-backups', 'hosting-backups', 'import', 'settings' );
} else {
$panels = array( 'dashboard', 'snapshots', 'destinations', 'managed-backups', 'import', 'settings' );
}
$extra_actions = array(
'destinations' => 'on_load_destination_panels',
'managed-backups' => 'on_load_managed_backups_panels'
);
foreach ( $panels as $panel ) {
add_action( 'load-' . $this->_pagehooks[ 'snapshots-newui-' . $panel ], array( $this, 'snapshot_on_load_panels' ) );
if ( isset( $extra_actions[ $panel ] ) ) {
add_action( 'load-' . $this->_pagehooks[ 'snapshots-newui-' . $panel ], array( $this, $extra_actions[ $panel ] ) );
}
}
}
/**
* Redirect old menu slugs to the new menus
*/
public function redirect_old_admin_menus() {
if ( ! isset( $GLOBALS['pagenow'], $_GET['page'] ) || 'admin.php' !== $GLOBALS['pagenow'] ) {
return;
}
/* old menu slug mapped to new menu slug */
$page_map = array(
'snapshots_edit_panel' => 'snapshots-newui-dashboard',
'snapshots_new_panel' => 'snapshots-newui-new-snapshot',
'snapshots_destinations_panel' => 'snapshots-newui-destinations',
'snapshots_import_panel' => 'snapshots-newui-import',
'snapshots_settings_panel' => 'snapshots-newui-settings',
'snapshots_full_backup_panel' => 'snapshots-newui-managed-backups',
);
if ( isset( $page_map[ $_GET['page'] ] ) ) {
if ( ! isset( $_REQUEST['snapshot-noonce-field'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['snapshot-noonce-field'], 'snapshot-nonce' ) ) {
return;
}
wp_redirect( esc_url_raw( $this->snapshot_get_pagehook_url( $page_map[ $_GET['page'] ] ) ) );
}
}
/**
* Set up the common items used on all Snapshot pages.
*
* @since 1.0.0
*
* @return void
*/
public function snapshot_on_load_panels() {
/* These messages are displayed as part of the admin header message see 'admin_notices' WordPress action */
$this->_messages['success-update'] = __( 'The Snapshot has been updated.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-add'] = __( 'The Snapshot has been created.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-delete'] = __( 'Snapshot successfully deleted.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-delete-bulk'] = __( 'Selected Snapshots successfully deleted.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-restore'] = __( 'The Snapshot has been restored.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-settings'] = __( 'Settings have been updated.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-runonce'] = __( 'Item scheduled to run.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-snapshot-key'] = __( 'Your Snapshot Key has been successfully added.', SNAPSHOT_I18N_DOMAIN );
$this->snapshot_scheduler();
$this->snapshot_process_actions();
add_thickbox();
add_action( 'admin_notices', array( $this, 'snapshot_admin_notices_proc' ) );
add_action( 'network_admin_notices', array( $this, 'snapshot_admin_notices_proc' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_action( 'admin_footer', array( $this, 'snapshot_admin_panels_footer' ) );
if ( version_compare(PHP_VERSION, '5.5.0', '<') && ! get_option( 'snapshot-aws-combat-dismissed' ) ) {
add_action( 'admin_notices', array( 'Snapshot_Helper_UI', 'snapshot_aws_compatibility_notices' ) );
add_action( 'network_admin_notices', array( 'Snapshot_Helper_UI', 'snapshot_aws_compatibility_notices' ) );
}
if ( isset( $_GET['dismiss_hosting_modal'], $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'dismiss_notice' ) && 1 === absint( $_GET['dismiss_hosting_modal'] ) ) {
$this->dismiss_hosting_backups_notice( false );
}
}
/**
* Set up for the Managed Backups pages
*/
public function on_load_managed_backups_panels() {
$this->_messages['success-update'] = __( 'The Backup has been updated.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-add'] = __( 'The Backup has been created.', SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-delete'] = __( "Backup successfully deleted.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-delete-bulk'] = __( "Selected Backups successfully deleted.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-restore'] = __( "The Backup has been restored.", SNAPSHOT_I18N_DOMAIN );
}
/**
* Set up the page with needed items for the Destinations metaboxes.
*
* @since 1.0.7
* @uses none
*
* @param none
*
* @return void
*/
public function on_load_destination_panels() {
// These messages are displayed as part of the admin header message see 'admin_notices' WordPress action
$this->_messages['success-update'] = __( "The Destination has been updated.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-add'] = __( "The Destination has been added.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-delete'] = __( "The Destination has been deleted.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-restore'] = __( "The Destination has been restored.", SNAPSHOT_I18N_DOMAIN );
$this->_messages['success-settings'] = __( "Settings have been updated.", SNAPSHOT_I18N_DOMAIN );
$this->process_snapshot_destination_actions();
add_action( 'admin_notices', array( $this, 'snapshot_admin_notices_proc' ) );
add_action( 'network_admin_notices', array( $this, 'snapshot_admin_notices_proc' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_action( 'admin_footer', array( $this, 'snapshot_admin_panels_footer' ) );
}
/**
* Enqueue the CSS for the menu icon
*/
public function enqueue_icon_admin_style() {
wp_enqueue_style(
'snapshot-menu-icon',
plugins_url( 'assets/css/menu-icon.css', __FILE__ ),
false, $this->_settings['SNAPSHOT_VERSION']
);
}
/**
* Enqueue scripts and styles for the plugin admin
*/
public function enqueue_admin_scripts() {
wp_enqueue_style(
'snapshots-admin-stylesheet', plugins_url( '/css/snapshots-admin-styles.css', __FILE__ ),
false, $this->_settings['SNAPSHOT_VERSION']
);
wp_enqueue_script(
'snapshot-admin', plugins_url( '/js/snapshot-admin.js', __FILE__ ),
array( 'jquery' ), $this->_settings['SNAPSHOT_VERSION']
);
wp_localize_script(
'snapshot-admin', 'snapshot_admin_messages', array(
'log_viewer_title' => esc_html__( 'Snapshot Log Viewer', SNAPSHOT_I18N_DOMAIN ),
'select_all' => esc_html__( 'Select all', SNAPSHOT_I18N_DOMAIN ),
'unselect_all' => esc_html__( 'Unselect all', SNAPSHOT_I18N_DOMAIN ),
'loading' => esc_html__( 'Loading...', SNAPSHOT_I18N_DOMAIN ),
'snapshot_initializing' => esc_html__( 'Snapshot initializing', SNAPSHOT_I18N_DOMAIN ),
'destination_type_dropbox' => esc_html__( 'Dropbox', SNAPSHOT_I18N_DOMAIN ),
'memory' => esc_html__( 'Memory: ', SNAPSHOT_I18N_DOMAIN ),
'memory_limit' => esc_html__( 'Limit', SNAPSHOT_I18N_DOMAIN ),
'memory_usage' => esc_html__( 'Usage:', SNAPSHOT_I18N_DOMAIN ),
'memory_peak' => esc_html__( 'Peak:', SNAPSHOT_I18N_DOMAIN ),
'abort' => esc_html__( 'Abort', SNAPSHOT_I18N_DOMAIN ),
'database' => esc_html__( 'Database:', SNAPSHOT_I18N_DOMAIN ),
'files_label' => esc_html__( 'Files: ', SNAPSHOT_I18N_DOMAIN ),
'finishing_snapshot' => esc_html__( 'Snapshot Finishing', SNAPSHOT_I18N_DOMAIN ),
'snapshot_failed' => esc_html__( 'An unknown response returned from Snapshot backup attempt. Aborting. Double check Snapshot settings.', SNAPSHOT_I18N_DOMAIN ),
'finding_filestables' => esc_html__( 'Snapshot determining tables/files to restore', SNAPSHOT_I18N_DOMAIN ),
'files' => esc_html__( 'Files', SNAPSHOT_I18N_DOMAIN ),
'backup_aborted' => esc_html__( 'Snapshot backup aborted', SNAPSHOT_I18N_DOMAIN ),
'no_tables_selected' => esc_html__( 'You must select at least one table', SNAPSHOT_I18N_DOMAIN ),
'no_files_tables_selected' => esc_html__( 'You must select which Files and/or Tables to backup in this Snapshot', SNAPSHOT_I18N_DOMAIN ),
'missing_snapshot_timekey' => esc_html__( 'ERROR: The Snapshot timekey is not set. Try reloading the page', SNAPSHOT_I18N_DOMAIN ),
)
);
/* new_ui styles and js */
wp_enqueue_style(
'snapshot-pro-admin-stylesheet', plugins_url( '/assets/css/admin.css', __FILE__ ),
array( 'wdev-plugin-ui' ), $this->_settings['SNAPSHOT_VERSION']
);
wp_enqueue_script(
'snapshot-pro-admin', plugins_url( '/assets/js/admin.min.js', __FILE__ ),
array( 'jquery' ), $this->_settings['SNAPSHOT_VERSION']
);
wp_localize_script(
'snapshot-pro-admin', 'snapshot_messages', array(
'snapshot_key' => esc_html__( 'Snapshot Key', SNAPSHOT_I18N_DOMAIN ),
'snapshot_failed' => esc_html__( 'An unknown response returned from Snapshot backup attempt. Aborting. Double check Snapshot settings.', SNAPSHOT_I18N_DOMAIN ),
'no_files_selected' => esc_html__( 'You must select at least one Files backup option.', SNAPSHOT_I18N_DOMAIN ),
'no_tables_selected' => esc_html__( 'You must select at least one database table to include.', SNAPSHOT_I18N_DOMAIN ),
'no_files_tables' => esc_html__( "You haven't included any files or database tables in this Snapshot. Please select what to include and try again.", SNAPSHOT_I18N_DOMAIN ),
'loading' => esc_html__( 'Loading...', SNAPSHOT_I18N_DOMAIN ),
'working' => esc_html__( 'Working...', SNAPSHOT_I18N_DOMAIN ),
'snapshot_aborted' => esc_html__( 'Snapshot backup aborted', SNAPSHOT_I18N_DOMAIN ),
'restore_aborted' => esc_html__( 'Snapshot restore aborted', SNAPSHOT_I18N_DOMAIN ),
'restore_backup_aborted' => esc_html__( 'Backup aborted. Please try restoring again.', SNAPSHOT_I18N_DOMAIN ),
'missing_timekey' => esc_html__( 'ERROR: The Snapshot timekey is not set. Try reloading the page', SNAPSHOT_I18N_DOMAIN ),
'determine' => esc_html__( 'Determine tables & files', SNAPSHOT_I18N_DOMAIN ),
'determining' => esc_html__( 'Determining tables & files to restore', SNAPSHOT_I18N_DOMAIN ),
'determined' => esc_html__( 'Determined', SNAPSHOT_I18N_DOMAIN ),
'restoring_files' => esc_html__( 'Restoring files', SNAPSHOT_I18N_DOMAIN ),
'files_restored' => esc_html__( 'Files restored', SNAPSHOT_I18N_DOMAIN ),
'restoring_database' => esc_html__( 'Restoring database', SNAPSHOT_I18N_DOMAIN ),
'database_restored' => esc_html__( 'Database restored', SNAPSHOT_I18N_DOMAIN ),
'finalizing_restoration' => esc_html__( 'Finalizing restoration', SNAPSHOT_I18N_DOMAIN ),
'finalized_restoration' => esc_html__( 'Finalized restoration', SNAPSHOT_I18N_DOMAIN ),
'hide_full_log' => esc_html__( 'Hide full log', SNAPSHOT_I18N_DOMAIN ),
'show_full_log' => esc_html__( 'Show full log', SNAPSHOT_I18N_DOMAIN ),
'restore_fail' => esc_html__( 'Error restoring backup', SNAPSHOT_I18N_DOMAIN ),
'fail_restore_start' => esc_html__( 'Your backup failed to restore while', SNAPSHOT_I18N_DOMAIN ),
'fail_restore_end' => sprintf( __( 'Please try again, and if the issue persist, you can <a href="%s" target="_blank">contact our support</a> for help.', SNAPSHOT_I18N_DOMAIN ), 'https://premium.wpmudev.org/get-support/' ),
)
);
}
/**
* Retrieve the ID of the current admin screen, sans the -network suffix
*/
public function get_current_screen_id() {
$screen = get_current_screen();
if ( ! $screen ) {
return '';
}
$screen_id = $screen->id;
if ( '-network' === substr( $screen_id, -8, 8 ) ) {
$screen_id = substr( $screen_id, 0, -8 );
}
return $screen_id;
}
/**
* Enqueue the shared-ui if within our plugin screens
*/
public function enqueue_shared_ui() {
if ( ! in_array( $this->get_current_screen_id(), $this->_pagehooks, true ) ) {
return;
}
WDEV_Plugin_Ui::load( plugin_dir_url( plugin_basename( __FILE__ ) ) . 'assets/shared-ui', 'wpmud' );
}
public function snapshot_admin_panels_footer() {
?>
<div style="display: none;" id="snapshot-log-view-container">
<div id="snapshot-log-viewer"></div>
<br /><br /></div>
<?php
}
/**
* Plugin main action processing function. Will filter the action called then
* pass on to other sub-functions
*
* @since 1.0.0
* @uses $_REQUEST global PHP object
*
* @param none
*
* @return void
*/
public function snapshot_process_actions() {
if ( is_multisite() ) {
if ( ! is_super_admin() ) {
return;
}
} else {
if ( ! current_user_can( 'manage_snapshots_items' ) ) {
return;
}
}
$ACTION_FOUND = false;
if ( isset( $_REQUEST['snapshot-action'] ) ) {
$snapshot_action = sanitize_text_field( $_REQUEST['snapshot-action'] );
switch ( $snapshot_action ) {
case 'add':
if ( empty( $_POST ) || ( isset( $_POST['snapshot-noonce-field'] ) && ! wp_verify_nonce( $_POST['snapshot-noonce-field'], 'snapshot-nonce' ) ) ) {
return;
} else {
$this->snapshot_add_update_action_proc( $_POST );
}
$ACTION_FOUND = true;
break;
case 'delete-bulk':
if ( empty( $_POST ) || ( isset( $_POST['snapshot-noonce-field'] ) && ! wp_verify_nonce( $_POST['snapshot-noonce-field'], 'snapshot-delete' ) ) ) {
return;
} else if ( ( isset( $_POST['delete-bulk'] ) ) && ( count( $_POST['delete-bulk'] ) ) ) {
$this->snapshot_delete_bulk_action_proc();
$ACTION_FOUND = true;
} else {
return;
}
$return_url = wp_get_referer();
if ( ! isset( $_GET['page'] ) ) {
$_GET['page'] = 'snapshots_edit_panel';
}
if ( 'snapshots_edit_panel' === $_GET['page'] ) {
$return_url = remove_query_arg( array( 'item' ), $return_url );
}
$return_url = remove_query_arg(
array(
'snapshot-action',
'snapshot-noonce-field',
), $return_url
);
$return_url = add_query_arg( 'page', sanitize_text_field( $_GET['page'] ), $return_url );
$return_url = add_query_arg( 'message', 'success-delete-bulk', $return_url );
$return_url = esc_url_raw( $return_url );
if ( $return_url ) {
wp_redirect( $return_url );
}
die();
case 'delete-item':
if ( empty( $_GET ) || ( isset( $_POST['snapshot-noonce-field'] ) && ! wp_verify_nonce( $_GET['snapshot-noonce-field'], 'snapshot-delete-item' ) ) ) {
return;
} else {
$this->snapshot_delete_item_action_proc();
$ACTION_FOUND = true;
$return_url = wp_get_referer();
if ( ! isset( $_GET['page'] ) ) {
$_GET['page'] = 'snapshots_edit_panel';
}
if ( 'snapshots_edit_panel' === $_GET['page'] ) {
$return_url = remove_query_arg( array( 'item' ), $return_url );