-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathclass-boldgrid-backup-admin-core.php
More file actions
3230 lines (2718 loc) · 91.4 KB
/
class-boldgrid-backup-admin-core.php
File metadata and controls
3230 lines (2718 loc) · 91.4 KB
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
/**
* File: class-boldgrid-backup-admin-core.php
*
* @link https://www.boldgrid.com
* @since 1.0
*
* @package Boldgrid_Backup
* @subpackage Boldgrid_Backup/admin
* @copyright BoldGrid
* @version $Id$
* @author BoldGrid <support@boldgrid.com>
*
* phpcs:disable WordPress.VIP
*/
/**
* Class: Boldgrid_Backup_Admin_Core
*
* @since 1.0
*/
class Boldgrid_Backup_Admin_Core {
/**
* Archiver Utility class.
*
* @since 1.9.0
* @var Boldgrid_Backup_Admin_Archiver_Utility
*/
public $archiver_utility;
/**
* Auto Rollback class.
*
* @since 1.5.2
* @var Boldgrid_Backup_Admin_Auto_Rollback
*/
public $auto_rollback;
/**
* An instance of Boldgrid_Backup_Admin_Dashboard
*
* @since 1.11.0
* @var Boldgrid_Backup_Admin_Dashboard
*/
public $dashboard;
/**
* Dashboard widget.
*
* @since 1.10.0
* @var Boldgrid_Backup_Admin_Dashboard_Widget
*/
public $dashboard_widget;
/**
* The settings class object.
*
* @since 1.0
* @var Boldgrid_Backup_Admin_Settings
*/
public $settings;
/**
* The configuration class object.
*
* @since 1.0
* @var Boldgrid_Backup_Admin_Config
*/
public $config;
/**
* Plugin configs.
*
* @since 1.3.4
* @var array
*/
public $configs;
/**
* Plugin class.
*
* @since 1.13.0
* @var Boldgrid\Library\Library\Plugin\Plugin
*/
public $plugin;
/**
* Core Files class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Core_Files
*/
public $core_files;
/**
* Whether or not we're in ajax.
*
* When we're on the archives page and click "Backup Site Now", when
* this->archive_files runs, it reports doing_ajax as true.
*
* @since 1.5.2
* @var bool
*/
public $doing_ajax;
/**
* Whether or not we're doing cron.
*
* Please see $this->set_doing_cron() for further clarification.
*
* @since 1.5.1
* @var bool
*/
public $doing_cron;
/**
* Whether or not we're doing wp_cron.
*
* In WordPress' wp-cron.php DOING_CRON is defined as true. In several of
* our files, we define DOING_CRON as well. When we want to tell the
* difference between (1)wp-cron.php and (2)cron / cli, it's difficult.
* This property is solely to know if we're in wp-cron.php.
*
* @todo Within our plugins, DOING_CRON should be cleaned up.
*
* @since 1.6.0
*
* @var bool
*/
public $doing_wp_cron;
/**
* Email.
*
* @since 1.5.2
* @var Boldgrid_Backup_Admin_Email
*/
public $email;
/**
* Elements.
*
* Common elements used throughout admin pages. Usually a combination of
* language strings.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Email
*/
public $elements = [];
/**
* The functionality test class object.
*
* @since 1.0
* @var Boldgrid_Backup_Admin_Test
*/
public $test;
/**
* The Time class object.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Time
*/
public $time;
/**
* An instance of Boldgrid_Backup_Admin_Tools.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Tools
*/
public $tools;
/**
* An instance of Boldgrid_Backup_Admin_Transfers.
*
* @since 1.11.0
* @var Boldgrid_Backup_Admin_Transfers
*/
public $transfers;
/**
* An instance of Boldgrid_Backup_Admin_Support.
*
* @since 1.10.1
* @var Boldgrid_Backup_Admin_Support
*/
public $support;
/**
* An instance of Boldgrid_Backup_Admin_Premium.
*
* @since 1.12.4
* @var Boldgrid_Backup_Admin_Premium_Features
*/
public $premium_page;
/**
* An instance of Boldgrid_Backup_Admin_Utility.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Utility
*/
public $utility;
/**
* The admin notice class object.
*
* @since 1.0
* @var Boldgrid_Backup_Admin_Notice
*/
public $notice;
/**
* WordPress' global pagenow.
*
* @since 1.6.0
* @var string
*/
public $pagenow;
/**
* A bool indicating at the time of archivign files whether or not the
* current_filter() was pre_auto_update (the action ran immediately before
* WordPress does an auto upgrade).
*
* @since 1.6.0
* @var bool
*/
public $pre_auto_update = false;
/**
* The admin cron class object.
*
* @since 1.0
* @var Boldgrid_Backup_Admin_Cron
*/
public $cron;
/**
* Cron log class.
*
* @since 1.6.5
* @var Boldgrid_Backup_Admin_Cron_Log
*/
public $cron_log;
/**
* Cron test class.
*
* @since 1.6.5
* @var Boldgrid_Backup_Admin_Cron_Test
*/
public $cron_test;
/**
* The admin xhprof class object.
*
* @since 1.2
* @var Boldgrid_Backup_Admin_Xhprof
*/
public $xhprof;
/**
* WP Cron class.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_WP_Cron
*/
public $wp_cron;
/**
* An instance of the filesystem.
*
* @since 1.5.1
* @var WP_Filesystem
*/
public $wp_filesystem;
/**
* An instance of the Boldgrid_Backup_Admin_Archive class.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Archive
*/
public $archive;
/**
* An instance of the Boldgrid_Backup_Admin_Archives class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Archives
*/
public $archives;
/**
* An instance of the Boldgrid_Backup_Admin_Archives_All class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Archives_All
*/
public $archives_all;
/**
* An instance of the Boldgrid_Backup_Admin_Archive_Actions class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Archive_Actions
*/
public $archive_actions;
/**
* An instance of the Boldgrid_Backup_Admin_Archive_Browser class.
*
* @since 1.5.2
* @var Boldgrid_Backup_Admin_Archive_Browser
*/
public $archive_browser;
/**
* An instance of the Archive Log class.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Archive_Log
*/
public $archive_log;
/**
* An instance of the Archive Details class.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Archive_Details
*/
public $archive_details;
/**
* An instance of the Archive Fail class.
*
* @since 1.5.2
* @var Boldgrid_Backup_Admin_Archive_Fail
*/
public $archive_fail;
/**
* Archive filepath.
*
* This is similar to $db_dump_filepath, but holds the path to the archive instead of the .sql file.
* This is being added in 1.14.13 to handle the scenario of a user canceling a backup. If the
* user does cancel the backup, we need to delete it (which is handled in archive-fail).
*
* @since 1.14.13
* @var string
*/
public $archive_filepath;
/**
* Whether or not we're in the middle of archiving files.
*
* This is set at the beginning and end of self::archive_files().
*
* @since 1.13.4
* @var bool
*/
public $archiving_files = false;
/**
* Db Dump.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Db_Dump
*/
public $db_dump;
/**
* Database backup file path.
*
* @since 1.0
* @var string
*/
public $db_dump_filepath = '';
/**
* Db Get.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Db_Dump
*/
public $db_get;
/**
* An instance of Boldgrid_Backup_Admin_Db_Omit.
*
* @since 1.5.3
* @var Boldgrid_Backup_Admin_Db_Omit
*/
public $db_omit;
/**
* Database Restoration errro
*
* @since 1.14.0
* @var string
*/
public $db_restore_error;
/**
* An instance of Boldgrid_Backup_Admin_Filelist.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Filelist
*/
public $filelist;
/**
* Base directory for the get_filelist method.
*
* @since 1.0
* @access private
* @var string
*/
private $filelist_basedir = null;
/**
* An instance of the Boldgrid_Backup_Admin_Folder_Exclusion class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Folder_Exclusion
*/
public $folder_exclusion;
/**
* An instance of the Boldgrid_Backup_Admin_Ftp class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Ftp
*/
public $ftp;
/**
* An instance of the Boldgrid_Backup_Admin_Go_Pro class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_Go_Pro
*/
public $go_pro;
/**
* An instance of Boldgrid_Backup_Admin_Backup_Dir.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Backup_Dir
*/
public $backup_dir;
/**
* A unique identifier for backups of this WordPress installation.
*
* @since 1.0.1
* @access private
* @var string
*/
private $backup_identifier = null;
/**
* Value indicating we are in the Backup Site Now callback and the user is
* choosing a full backup.
*
* @since 1.6.0
* @var bool
*/
public $is_backup_full = false;
/**
* Value indicating we are in the Backup Site Now callback.
*
* @since 1.6.0
* @var bool
*/
public $is_backup_now = false;
/**
* An instance of Boldgrid_Backup_Admin_Home_Dir.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Home_Dir
*/
public $home_dir;
/**
* An instance of the In Progress class.
*
* @since 1.6.0
* @var Boldgrid_Backup_Admin_In_Progress object.
*/
public $in_progress;
/**
* Value indicating whether or not we're creating a backup for update
* protection.
*
* @since 1.6.0
* @var bool
*/
public $is_archiving_update_protection = false;
/**
* Whether or not we are in a scheduled backup (IE a cron backup).
*
* @since 1.9.0
* @var bool
*/
public $is_scheduled_backup;
/**
* Common elements.
*
* @since 1.5.3
* @var array
*/
public $lang = [];
/**
* Local storage.
*
* @since 1.5.2
* @var Boldgrid_Backup_Admin_Storage_Local
*/
public $local;
/**
* Log page.
*
* @since 1.12.5
* @var Boldgrid_Backup_Admin_Log_Page
*/
public $log_page;
/**
* Logger.
*
* @since 1.12.5
* @var Boldgrid_Backup_Admin_Log
*/
public $logger;
/**
* Path to our config.rating-prompt.php file.
*
* @since 1.7.2
* @var string
*/
public $rating_prompt_config;
/**
* The Restore Helper class.
*
* @since 1.6.1
* @var Boldgrid_Backup_Admin_Restore_Helper
*/
public $restore_helper;
/**
* Whether or not we are in the middle of restoring an archive.
*
* @since 1.13.5
* @var bool
*
* @see self::archiving_files
*/
public $restoring_archive_file = false;
/**
* The scheduler class object.
*
* @since 1.5.1
* @var Boldgrid_Backup_Admin_Scheduler
*/
public $scheduler;
/**
* The public download class object.
*
* @since 1.7.0
* @var Boldgrid_Backup_Download
*/
public $download;
/**
* An instance of the Boldgrid\Library\Library\Activity class.
*
* @since 1.7.2
* @var Boldgrid\Library\Library\Activity
*/
public $activity;
/**
* An instance of the Auto Updates class
*
* @since 1.14.0
* @var Boldgrid_Backup_Admin_Auto_Updates
*/
public $auto_updates;
/**
* Constructor.
*
* @since 1.0
*
* @global $wp_filesystem
*/
public function __construct() {
/*
* Moves the definition of 'boldgrid_backup_get_core' from Boldgrid_Backup here.
* This should help prevent issues where this filter doesn't work in some places.
*/
add_filter( 'boldgrid_backup_get_core', array( $this, 'get_core' ), 10, 1 );
WP_Filesystem();
global $wp_filesystem;
global $pagenow;
$this->set_doing_cron();
$this->doing_ajax = is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX;
$this->doing_wp_cron = ! empty( $_SERVER['SCRIPT_FILENAME'] ) &&
trailingslashit( ABSPATH ) . 'wp-cron.php' === $_SERVER['SCRIPT_FILENAME'];
$this->wp_filesystem = $wp_filesystem;
$this->pagenow = $pagenow;
// Instantiate Configs Array
$this->configs = Boldgrid_Backup_Admin::get_configs();
// Instantiate Boldgrid_Backup_Admin_Settings.
$this->settings = new Boldgrid_Backup_Admin_Settings( $this );
// Instantiate Boldgrid_Backup_Admin_Config.
$this->config = new Boldgrid_Backup_Admin_Config( $this );
// Instantiate Boldgrid_Backup_Admin_Test.
$this->test = new Boldgrid_Backup_Admin_Test( $this );
// Instantiate Boldgrid_Backup_Admin_Notice.
$this->notice = new Boldgrid_Backup_Admin_Notice( $this );
// Instantiate Boldgrid_Backup_Admin_Cron.
$this->cron = new Boldgrid_Backup_Admin_Cron( $this );
// Instantiate Boldgrid_Backup_Admin_Upload.
$this->upload = new Boldgrid_Backup_Admin_Upload( $this );
// Instantiate Boldgrid_Backup_Admin_Xhprof.
// Starts profiling and saves a report, if enabled in the "config.local.php" file.
$this->xhprof = new Boldgrid_Backup_Admin_Xhprof();
$this->restore_helper = new Boldgrid_Backup_Admin_Restore_Helper();
$this->restore_git = new Boldgrid_Backup_Admin_Restore_Git();
$this->filelist = new Boldgrid_Backup_Admin_Filelist( $this );
$this->backup_dir = new Boldgrid_Backup_Admin_Backup_Dir( $this );
$this->home_dir = new Boldgrid_Backup_Admin_Home_Dir( $this );
$this->compressors = new Boldgrid_Backup_Admin_Compressors( $this );
$this->archive_browser = new Boldgrid_Backup_Admin_Archive_Browser( $this );
$this->archive = new Boldgrid_Backup_Admin_Archive( $this );
$this->archive_actions = new Boldgrid_Backup_Admin_Archive_Actions( $this );
$this->archives = new Boldgrid_Backup_Admin_Archives( $this );
$this->archives_all = new Boldgrid_Backup_Admin_Archives_All( $this );
$this->archive_log = new Boldgrid_Backup_Admin_Archive_Log( $this );
$this->archive_details = new Boldgrid_Backup_Admin_Archive_Details( $this );
$this->archive_fail = new Boldgrid_Backup_Admin_Archive_Fail( $this );
$this->archiver_utility = new Boldgrid_Backup_Admin_Archiver_Utility( $this );
$this->wp_cron = new Boldgrid_Backup_Admin_WP_Cron( $this );
$this->scheduler = new Boldgrid_Backup_Admin_Scheduler( $this );
$this->auto_rollback = new Boldgrid_Backup_Admin_Auto_Rollback( $this );
$this->remote = new Boldgrid_Backup_Admin_Remote( $this );
$this->jobs = new Boldgrid_Backup_Admin_Jobs( $this );
$this->local = new Boldgrid_Backup_Admin_Storage_Local( $this );
$this->email = new Boldgrid_Backup_Admin_Email( $this );
$this->db_omit = new Boldgrid_Backup_Admin_Db_Omit( $this );
$this->db_dump = new Boldgrid_Backup_Admin_Db_Dump( $this );
$this->db_get = new Boldgrid_Backup_Admin_Db_get( $this );
$this->utility = new Boldgrid_Backup_Admin_Utility();
$this->folder_exclusion = new Boldgrid_Backup_Admin_Folder_Exclusion( $this );
$this->core_files = new Boldgrid_Backup_Admin_Core_Files( $this );
$this->in_progress = new Boldgrid_Backup_Admin_In_Progress( $this );
$this->ftp = new Boldgrid_Backup_Admin_Ftp( $this );
$this->go_pro = new Boldgrid_Backup_Admin_Go_Pro( $this );
$this->tools = new Boldgrid_Backup_Admin_Tools( $this );
$this->transfers = new Boldgrid_Backup_Admin_Transfers( $this );
$this->support = new Boldgrid_Backup_Admin_Support( $this );
$this->time = new Boldgrid_Backup_Admin_Time( $this );
$this->cron_test = new Boldgrid_Backup_Admin_Cron_Test( $this );
$this->cron_log = new Boldgrid_Backup_Admin_Cron_Log( $this );
$this->download = new Boldgrid_Backup_Download( $this );
$this->dashboard_widget = new Boldgrid_Backup_Admin_Dashboard_Widget( $this );
$this->dashboard = new Boldgrid_Backup_Admin_Dashboard( $this );
/**
* For backwards compatibility with plugins using previous versions of the Library, this will
* allow the plugins to be instantiated without using the new Factory methods.
*/
$this->plugin = new \Boldgrid\Library\Library\Plugin\Plugin( 'boldgrid-backup', $this->configs );
$this->premium_page = new Boldgrid_Backup_Admin_Premium_Features( $this );
// Instantiate Boldgrid_Backup_Admin_Auto_Updates.
if ( Boldgrid_Backup_Admin_Utility::is_active() ) {
$this->auto_updates = new Boldgrid_Backup_Admin_Auto_Updates();
new Boldgrid_Backup_Admin_Auto_Updates_Logger();
}
// Ensure there is a backup identifier.
$this->get_backup_identifier();
$this->set_lang();
// Log system.
$this->logger = new Boldgrid_Backup_Admin_Log( $this );
$this->log_page = new Boldgrid_Backup_Admin_Log_Page( $this );
// Need to construct class so necessary filters are added.
if ( class_exists( '\Boldgrid\Library\Library\Ui' ) ) {
$ui = new \Boldgrid\Library\Library\Ui();
}
// Setup library's Activity and RatingPrompt classes; init RatingPrompt to add necessary filters.
$this->rating_prompt_config = BOLDGRID_BACKUP_PATH . '/includes/config/config.rating-prompt.php';
if ( class_exists( '\Boldgrid\Library\Library\RatingPrompt' ) ) {
new \Boldgrid\Library\Library\RatingPrompt();
}
if ( class_exists( '\Boldgrid\Library\Library\Activity' ) ) {
$this->activity = new \Boldgrid\Library\Library\Activity( BOLDGRID_BACKUP_KEY );
}
}
/**
* Get the unique identifier for backups of this WordPress installation.
*
* @since 1.0.1
*
* @return string A unique identifier for backups.
*/
public function get_backup_identifier() {
// If the id was already stored, then return it.
if ( ! empty( $this->backup_identifier ) ) {
return $this->backup_identifier;
}
// Check wp_options for the id.
$backup_identifier = get_site_option( 'boldgrid_backup_id' );
// If the id was already stored in WP options, then save and return it.
if ( ! empty( $backup_identifier ) ) {
$this->backup_identifier = $backup_identifier;
return $backup_identifier;
}
// Generate a new backup id.
$admin_email = $this->config->get_admin_email();
$unique_string = site_url() . ' <' . $admin_email . '>';
$backup_identifier = hash( 'crc32', hash( 'sha512', $unique_string ) );
// If something went wrong with hashing, then just use a random string to make the id.
if ( empty( $backup_identifier ) ) {
$random_string = '';
for ( $i = 0; $i <= 32; $i ++ ) {
$random_string .= chr( mt_rand( 40, 126 ) );
}
$backup_identifier = hash( 'crc32', $random_string );
}
// Save and return the id.
$this->backup_identifier = $backup_identifier;
update_site_option( 'boldgrid_backup_id', $backup_identifier );
return $backup_identifier;
}
/**
* Get core.
*
* Callable via the boldgrid_backup_get_core filter.
*
* @since 1.7.2
*
* @return Boldgrid_Backup_Admin_Core object.
*/
public function get_core() {
return $this;
}
/**
* Initialize the premium version of the plugin.
*
* @since 1.5.2
*
* @global string $pagenow
*/
public function init_premium() {
global $pagenow;
$premium_class = 'Boldgrid_Backup_Premium';
/*
* Only initialize premium if both the plugin exists, is activated, and
* we have a premium key.
*/
if ( ! class_exists( $premium_class ) || ! $this->config->get_is_premium() ) {
return;
}
/*
* If this version of the backup plugin is not compatible with the premium version:
* 1. Don't init the premium extension.
* 2. Display an admin notice telling the user to upgrade.
*/
if ( ! $this->support->is_premium_compatible() ) {
if ( 'update-core.php' !== $pagenow ) {
add_action( 'admin_notices', function() {
$message = wp_kses(
sprintf(
// Translators: 1 The minimum version required, 2 an opening strong tag, 3 its closing strong tag, 4 an opening anchor to the updates page, 5 its closing anchor, 6: Plugin title, 7: Premium plugin title.
__(
'The version of the %2$s%7$s%3$s plugin you have installed requires %2$s%6$s%3$s version %1$s or higher. Don\'t worry, the fix is simple. Please go to your %4$sUpdates page%5$s and update the %2$s%6$s%3$s plugin.',
'boldgrid-backup'
),
BOLDGRID_BACKUP_MIN_VERSION_FOR_PREMIUM,
'<strong>',
'</strong>',
'<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
'</a>',
BOLDGRID_BACKUP_TITLE,
BOLDGRID_BACKUP_TITLE . ' Premium'
),
[
'strong' => [],
'a' => [
'href' => [],
],
]
);
$notice_markup = $this->notice->get_notice_markup(
'notice notice-error is-dismissible',
$message,
BOLDGRID_BACKUP_TITLE . ' - ' . esc_html__( 'Update required', 'boldgrid-backup' )
);
echo $notice_markup; // phpcs:ignore
});
}
return;
}
$this->premium = new $premium_class( $this );
$this->premium->run();
}
/**
* Execute a system command using an array of execution functions.
*
* @since 1.0
*
* @see Boldgrid_Backup_Admin_Cli::call_command()
*
* @param string $command A command string to be executed.
* @param bool $success Success or failure of the operation, passed back.
* @param int $return_var If present, the return_var, passed back.
* @param string $filepath An optional file path to write the output.
* @return string|bool Returns the command output or FALSE on error.
*/
public function execute_command( $command, &$success = false, &$return_var = 0, $filepath = null ) {
// If no command was passed, then fail.
if ( empty( $command ) ) {
return false;
}
// If an output filepath is supplied, and the directory is writable, then write to file.
if ( $filepath && $this->wp_filesystem->is_writable( dirname( $filepath ) ) ) {
$command .= ' > ' . wp_normalize_path( $filepath );
}
// Disable stderr.
if ( ! $this->test->is_windows() && false === strpos( $command, '2>/dev/null' ) ) {
$command .= ' 2>/dev/null';
}
$output = Boldgrid_Backup_Admin_Cli::call_command( $command, $success, $return_var );
return $output;
}
/**
* Add menu items.
*
* @since 1.0
*
* @global array $submenu
*/
public function add_menu_items() {
global $submenu;
$lang = [
'backup_archive' => esc_html__( 'Backup Archives', 'boldgrid-backup' ),
'boldgrid_backup' => BOLDGRID_BACKUP_TITLE,
'get_premium' => esc_html__( 'Get Premium', 'boldgrid-bacukp' ),
'preflight_check' => esc_html__( 'Preflight Check', 'boldgrid-backup' ),
'settings' => esc_html__( 'Settings', 'boldgrid-backup' ),
'tools' => esc_html__( 'Tools', 'boldgrid-backup' ),
'transfers' => esc_html__( 'Transfers', 'boldgrid-backup' ),
'support' => esc_html__( 'Support', 'boldgrid-backup' ),
'premium' => esc_html__( 'Premium Features', 'boldgrid-backup' ),
];
// The main slug all sub menu items are children of.
$main_slug = 'boldgrid-backup-dashboard';
// The capability required for these menu items to be displayed to the user.
$capability = 'administrator';
// Add the main menu item.
add_menu_page(
$lang['boldgrid_backup'],
// This value is escaped already by Library\Plugin\Page::getUnreadMarkup
$lang['boldgrid_backup'],
$capability,
$main_slug,
[
$this->dashboard,
'page',
],
'none'
);
// Add our "Dashboard" page.
add_submenu_page(
$main_slug,
__( 'Dashboard', 'boldgrid-backup' ),
__( 'Dashboard', 'boldgrid-backup' ),
$capability,
'boldgrid-backup-dashboard',
[
$this->dashboard,
'page',
]
);
// Add "Backup Archive page".
add_submenu_page(
$main_slug,
'BoldGrid ' . $lang['backup_archive'],
$lang['backup_archive'],