Version Description
- 12-3-20 =
- Fixed: An issue with publishing custom post type content
- Fixed: An issue with loading BackWPup backups
- Fixed: An issue with searching Posts and Pages
- Fixed: Multiple usability issues
- Fixed: An issue with saving custom branding settings
- Updated: Support for new Wordfence options
Download this release
Release Info
Developer | mainwp |
Plugin | MainWP Child |
Version | 4.1.3 |
Comparing to | |
See all releases |
Code changes from version 4.1.2 to 4.1.3
- class/class-mainwp-backup.php +1367 -1349
- class/class-mainwp-child-back-up-buddy.php +3859 -3856
- class/class-mainwp-child-back-up-wordpress.php +1428 -1430
- class/class-mainwp-child-back-wp-up.php +1954 -1974
- class/class-mainwp-child-branding-render.php +380 -376
- class/class-mainwp-child-branding.php +1392 -1356
- class/class-mainwp-child-bulk-settings-manager.php +314 -310
- class/class-mainwp-child-callable.php +991 -865
- class/class-mainwp-child-comments.php +238 -231
- class/class-mainwp-child-db.php +210 -210
- class/class-mainwp-child-install.php +499 -485
- class/class-mainwp-child-ithemes-security.php +1591 -1591
- class/class-mainwp-child-links-checker.php +0 -596
class/class-mainwp-backup.php
CHANGED
@@ -1,1349 +1,1367 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Backup
|
4 |
-
*
|
5 |
-
* This file handles all Child Site backup functions.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
//phpcs:disable WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Backup
|
16 |
-
*
|
17 |
-
* Handle all Child Site backup functions.
|
18 |
-
*/
|
19 |
-
class MainWP_Backup {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Whether to exclude zip archives.
|
23 |
-
*
|
24 |
-
* @var bool true|false
|
25 |
-
*/
|
26 |
-
protected $excludeZip;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Container for zip file.
|
30 |
-
*
|
31 |
-
* @var resource ZIP file
|
32 |
-
*/
|
33 |
-
protected $zip;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Backup files count.
|
37 |
-
*
|
38 |
-
* @var int Files count.
|
39 |
-
*/
|
40 |
-
protected $zipArchiveFileCount;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Backup archive file size.
|
44 |
-
*
|
45 |
-
* @var float File size.
|
46 |
-
*/
|
47 |
-
protected $zipArchiveSizeCount;
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Backup archive file name.
|
51 |
-
*
|
52 |
-
* @var string File name.
|
53 |
-
*/
|
54 |
-
protected $zipArchiveFileName;
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Backup file descriptors.
|
58 |
-
*
|
59 |
-
* @var int File descriptors.
|
60 |
-
*/
|
61 |
-
protected $file_descriptors;
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Whether to load file before zip.
|
65 |
-
*
|
66 |
-
* @var bool true|false
|
67 |
-
*/
|
68 |
-
protected $loadFilesBeforeZip;
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Hold the current timeout length.
|
72 |
-
*
|
73 |
-
* @var int Timeout length.
|
74 |
-
*/
|
75 |
-
protected $timeout;
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Last time a backup has been run.
|
79 |
-
*
|
80 |
-
* @var string Last backup run.
|
81 |
-
*/
|
82 |
-
protected $lastRun;
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Garbage collection count.
|
86 |
-
*
|
87 |
-
* @var int Garbage collection count.
|
88 |
-
*/
|
89 |
-
protected $gcCnt = 0;
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Archive test content.
|
93 |
-
*
|
94 |
-
* @var bool Test backup content.
|
95 |
-
*/
|
96 |
-
protected $testContent;
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Backup process archiver.
|
100 |
-
*
|
101 |
-
* @var object Backup process archiver.
|
102 |
-
*/
|
103 |
-
protected $archiver = null;
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Protected static variable to hold the single instance of the class.
|
107 |
-
*
|
108 |
-
* @var mixed Default null
|
109 |
-
*/
|
110 |
-
protected static $instance = null;
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Create a public static instance.
|
114 |
-
*
|
115 |
-
* @return mixed Class instance.
|
116 |
-
*/
|
117 |
-
public static function get() {
|
118 |
-
if ( null === self::$instance ) {
|
119 |
-
self::$instance = new self();
|
120 |
-
}
|
121 |
-
return self::$instance;
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Create full backup.
|
126 |
-
*
|
127 |
-
* @param array $excludes Files to exclude from the backup.
|
128 |
-
* @param string $filePrefix Backup archive file prefix.
|
129 |
-
* @param bool $addConfig Add config file to backup.
|
130 |
-
* @param bool $includeCoreFiles Include WordPress core files.
|
131 |
-
* @param int $file_descriptors Number of backup archive file descriptors.
|
132 |
-
* @param bool $fileSuffix Backup archive file suffix.
|
133 |
-
* @param bool $excludezip Exclude zip files from the backup.
|
134 |
-
* @param bool $excludenonwp Exclude non-WordPress directories in site root.
|
135 |
-
* @param bool $loadFilesBeforeZip Load files before zip.
|
136 |
-
* @param string $ext Backup file extension.
|
137 |
-
* @param bool $pid PID true|false.
|
138 |
-
* @param bool $append Append to backup file name.
|
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 |
-
* @uses
|
309 |
-
* @
|
310 |
-
*
|
311 |
-
* @uses WP_Filesystem_Base::
|
312 |
-
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/
|
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 |
-
if (
|
420 |
-
$
|
421 |
-
}
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
$information['
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
$information['
|
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 |
-
$newExcludes[] =
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
517 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
518 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
519 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
520 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
521 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
522 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
523 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
524 |
-
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/
|
525 |
-
$newExcludes[] =
|
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 |
-
* @param
|
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 |
-
'wp-
|
803 |
-
'wp-
|
804 |
-
'wp-
|
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 |
-
'wp-
|
998 |
-
'wp-
|
999 |
-
'wp-
|
1000 |
-
'
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
*
|
1124 |
-
*
|
1125 |
-
* @param
|
1126 |
-
* @param string $
|
1127 |
-
*
|
1128 |
-
* @return bool true|false.
|
1129 |
-
*/
|
1130 |
-
public function
|
1131 |
-
$
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
$this->
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
$this->zip
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
$this->
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
*
|
1240 |
-
*
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
*
|
1255 |
-
*
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
$query =
|
1318 |
-
$row
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
}
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Backup
|
4 |
+
*
|
5 |
+
* This file handles all Child Site backup functions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Backup
|
16 |
+
*
|
17 |
+
* Handle all Child Site backup functions.
|
18 |
+
*/
|
19 |
+
class MainWP_Backup {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Whether to exclude zip archives.
|
23 |
+
*
|
24 |
+
* @var bool true|false
|
25 |
+
*/
|
26 |
+
protected $excludeZip;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Container for zip file.
|
30 |
+
*
|
31 |
+
* @var resource ZIP file
|
32 |
+
*/
|
33 |
+
protected $zip;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Backup files count.
|
37 |
+
*
|
38 |
+
* @var int Files count.
|
39 |
+
*/
|
40 |
+
protected $zipArchiveFileCount;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Backup archive file size.
|
44 |
+
*
|
45 |
+
* @var float File size.
|
46 |
+
*/
|
47 |
+
protected $zipArchiveSizeCount;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Backup archive file name.
|
51 |
+
*
|
52 |
+
* @var string File name.
|
53 |
+
*/
|
54 |
+
protected $zipArchiveFileName;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Backup file descriptors.
|
58 |
+
*
|
59 |
+
* @var int File descriptors.
|
60 |
+
*/
|
61 |
+
protected $file_descriptors;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Whether to load file before zip.
|
65 |
+
*
|
66 |
+
* @var bool true|false
|
67 |
+
*/
|
68 |
+
protected $loadFilesBeforeZip;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Hold the current timeout length.
|
72 |
+
*
|
73 |
+
* @var int Timeout length.
|
74 |
+
*/
|
75 |
+
protected $timeout;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Last time a backup has been run.
|
79 |
+
*
|
80 |
+
* @var string Last backup run.
|
81 |
+
*/
|
82 |
+
protected $lastRun;
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Garbage collection count.
|
86 |
+
*
|
87 |
+
* @var int Garbage collection count.
|
88 |
+
*/
|
89 |
+
protected $gcCnt = 0;
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Archive test content.
|
93 |
+
*
|
94 |
+
* @var bool Test backup content.
|
95 |
+
*/
|
96 |
+
protected $testContent;
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Backup process archiver.
|
100 |
+
*
|
101 |
+
* @var object Backup process archiver.
|
102 |
+
*/
|
103 |
+
protected $archiver = null;
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Protected static variable to hold the single instance of the class.
|
107 |
+
*
|
108 |
+
* @var mixed Default null
|
109 |
+
*/
|
110 |
+
protected static $instance = null;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Create a public static instance.
|
114 |
+
*
|
115 |
+
* @return mixed Class instance.
|
116 |
+
*/
|
117 |
+
public static function get() {
|
118 |
+
if ( null === self::$instance ) {
|
119 |
+
self::$instance = new self();
|
120 |
+
}
|
121 |
+
return self::$instance;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Create full backup.
|
126 |
+
*
|
127 |
+
* @param array $excludes Files to exclude from the backup.
|
128 |
+
* @param string $filePrefix Backup archive file prefix.
|
129 |
+
* @param bool $addConfig Add config file to backup.
|
130 |
+
* @param bool $includeCoreFiles Include WordPress core files.
|
131 |
+
* @param int $file_descriptors Number of backup archive file descriptors.
|
132 |
+
* @param bool $fileSuffix Backup archive file suffix.
|
133 |
+
* @param bool $excludezip Exclude zip files from the backup.
|
134 |
+
* @param bool $excludenonwp Exclude non-WordPress directories in site root.
|
135 |
+
* @param bool $loadFilesBeforeZip Load files before zip.
|
136 |
+
* @param string $ext Backup file extension.
|
137 |
+
* @param bool $pid PID true|false.
|
138 |
+
* @param bool $append Append to backup file name.
|
139 |
+
*
|
140 |
+
* @return array|bool Action results on success, false on failure.
|
141 |
+
*
|
142 |
+
* @used-by MainWP_Backup::backup_full()
|
143 |
+
*
|
144 |
+
* @uses \MainWP\Child\Tar_Archiver()
|
145 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
146 |
+
* @uses \MainWP\Child\MainWP_Helper::error()
|
147 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit()
|
148 |
+
*/
|
149 |
+
public function create_full_backup(
|
150 |
+
$excludes,
|
151 |
+
$filePrefix = '',
|
152 |
+
$addConfig = false,
|
153 |
+
$includeCoreFiles = false,
|
154 |
+
$file_descriptors = 0,
|
155 |
+
$fileSuffix = false,
|
156 |
+
$excludezip = false,
|
157 |
+
$excludenonwp = false,
|
158 |
+
$loadFilesBeforeZip = true,
|
159 |
+
$ext = 'zip',
|
160 |
+
$pid = false,
|
161 |
+
$append = false ) {
|
162 |
+
|
163 |
+
$this->file_descriptors = $file_descriptors;
|
164 |
+
$this->loadFilesBeforeZip = $loadFilesBeforeZip;
|
165 |
+
|
166 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
167 |
+
$backupdir = $dirs[0];
|
168 |
+
if ( ! defined( 'PCLZIP_TEMPORARY_DIR' ) ) {
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Defines PCLZIP temporary directory.
|
172 |
+
*
|
173 |
+
* @const ( string ) Temporary backup directory.
|
174 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Backup.html
|
175 |
+
*/
|
176 |
+
define( 'PCLZIP_TEMPORARY_DIR', $backupdir );
|
177 |
+
}
|
178 |
+
|
179 |
+
if ( false !== $pid ) {
|
180 |
+
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
181 |
+
}
|
182 |
+
|
183 |
+
// Verify if another backup is running, if so, return an error.
|
184 |
+
$files = glob( $backupdir . '*.pid' );
|
185 |
+
foreach ( $files as $file ) {
|
186 |
+
if ( basename( $file ) == basename( $pid ) ) {
|
187 |
+
continue;
|
188 |
+
}
|
189 |
+
|
190 |
+
if ( ( time() - filemtime( $file ) ) < 160 ) {
|
191 |
+
MainWP_Helper::error( __( 'Another backup process is running. Please, try again later.', 'mainwp-child' ) );
|
192 |
+
}
|
193 |
+
}
|
194 |
+
|
195 |
+
$timestamp = time();
|
196 |
+
if ( '' !== $filePrefix ) {
|
197 |
+
$filePrefix .= '-';
|
198 |
+
}
|
199 |
+
|
200 |
+
if ( 'zip' == $ext ) {
|
201 |
+
$this->archiver = null;
|
202 |
+
$ext = '.zip';
|
203 |
+
} else {
|
204 |
+
$this->archiver = new Tar_Archiver( $this, $ext, $pid );
|
205 |
+
$ext = $this->archiver->get_extension();
|
206 |
+
}
|
207 |
+
|
208 |
+
if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) {
|
209 |
+
// Append already contains extension!
|
210 |
+
$file = $fileSuffix . ( true === $append ? '' : $ext );
|
211 |
+
} else {
|
212 |
+
$file = 'backup-' . $filePrefix . $timestamp . $ext;
|
213 |
+
}
|
214 |
+
$filepath = $backupdir . $file;
|
215 |
+
$fileurl = $file;
|
216 |
+
|
217 |
+
if ( ! $addConfig ) {
|
218 |
+
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes, true ) && ! in_array( 'wp-admin', $excludes, true ) && ! in_array( WPINC, $excludes, true ) ) {
|
219 |
+
$addConfig = true;
|
220 |
+
$includeCoreFiles = true;
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
$this->timeout = 20 * 60 * 60;
|
225 |
+
$mem = '512M';
|
226 |
+
MainWP_Helper::set_limit( $this->timeout, $mem );
|
227 |
+
|
228 |
+
if ( null !== $this->archiver ) {
|
229 |
+
$success = $this->archiver->create_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
|
230 |
+
} elseif ( $this->check_zip_support() ) {
|
231 |
+
$success = $this->create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
232 |
+
} elseif ( $this->check_zip_console() ) {
|
233 |
+
$success = $this->create_zip_console_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
234 |
+
} else {
|
235 |
+
$success = $this->create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
236 |
+
}
|
237 |
+
|
238 |
+
return ( $success ) ? array(
|
239 |
+
'timestamp' => $timestamp,
|
240 |
+
'file' => $fileurl,
|
241 |
+
'filesize' => filesize( $filepath ),
|
242 |
+
) : false;
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Check whether the file is an archive or not & create a json_encoded, serialized, base64_encoded string.
|
247 |
+
*
|
248 |
+
* @uses \MainWP\Child\MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
249 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
250 |
+
* @uses \MainWP\Child\MainWP_Clone::is_archive()
|
251 |
+
*/
|
252 |
+
public function backup_poll() {
|
253 |
+
$fileNameUID = ( isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : '' );
|
254 |
+
$fileName = ( isset( $_POST['fileName'] ) ? wp_unslash( $_POST['fileName'] ) : '' );
|
255 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
256 |
+
|
257 |
+
if ( 'full' === $type ) {
|
258 |
+
if ( '' !== $fileName ) {
|
259 |
+
$backupFile = $fileName;
|
260 |
+
} else {
|
261 |
+
$backupFile = 'backup-' . $fileNameUID . '-';
|
262 |
+
}
|
263 |
+
|
264 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
265 |
+
$backupdir = $dirs[0];
|
266 |
+
$result = glob( $backupdir . $backupFile . '*' );
|
267 |
+
|
268 |
+
// Check if archive, set $archiveFile = $file & break.
|
269 |
+
$archiveFile = false;
|
270 |
+
foreach ( $result as $file ) {
|
271 |
+
if ( MainWP_Clone::is_archive( $file, $backupFile, '(.*)' ) ) {
|
272 |
+
$archiveFile = $file;
|
273 |
+
break;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
// When not an archive.
|
278 |
+
if ( false === $archiveFile ) {
|
279 |
+
MainWP_Helper::write( array() );
|
280 |
+
}
|
281 |
+
|
282 |
+
// When archive found.
|
283 |
+
MainWP_Helper::write( array( 'size' => filesize( $archiveFile ) ) );
|
284 |
+
} else {
|
285 |
+
// When not an archive.
|
286 |
+
$backupFile = 'dbBackup-' . $fileNameUID . '-*.sql';
|
287 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
288 |
+
$backupdir = $dirs[0];
|
289 |
+
$result = glob( $backupdir . $backupFile . '*' );
|
290 |
+
|
291 |
+
if ( 0 === count( $result ) ) {
|
292 |
+
MainWP_Helper::write( array() );
|
293 |
+
}
|
294 |
+
|
295 |
+
$size = 0;
|
296 |
+
foreach ( $result as $f ) {
|
297 |
+
$size += filesize( $f );
|
298 |
+
}
|
299 |
+
MainWP_Helper::write( array( 'size' => $size ) );
|
300 |
+
exit();
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Check if backup already exists or is in the process of backing up.
|
306 |
+
*
|
307 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
308 |
+
* @uses MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
309 |
+
* @uses MainWP_Helper::get_wp_filesystem() Get the WordPress filesystem.
|
310 |
+
*
|
311 |
+
* @uses WP_Filesystem_Base::is_file() Checks if resource is a file.
|
312 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/is_file/
|
313 |
+
*
|
314 |
+
* @uses WP_Filesystem_Base::mtime() Gets the file modification time.
|
315 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/mtime/
|
316 |
+
*
|
317 |
+
* @uses WP_Filesystem_Base::get_contents() Reads entire file into a string.
|
318 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/get_contents/
|
319 |
+
*/
|
320 |
+
public function backup_checkpid() {
|
321 |
+
$pid = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : 0;
|
322 |
+
|
323 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
324 |
+
$backupdir = $dirs[0];
|
325 |
+
|
326 |
+
$information = array();
|
327 |
+
|
328 |
+
/**
|
329 |
+
* WordPress files system object.
|
330 |
+
*
|
331 |
+
* @global object
|
332 |
+
*/
|
333 |
+
global $wp_filesystem;
|
334 |
+
|
335 |
+
MainWP_Helper::get_wp_filesystem();
|
336 |
+
|
337 |
+
$pidFile = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
338 |
+
$doneFile = trailingslashit( $backupdir ) . 'backup-' . $pid . '.done';
|
339 |
+
if ( $wp_filesystem->is_file( $pidFile ) ) {
|
340 |
+
$time = $wp_filesystem->mtime( $pidFile );
|
341 |
+
|
342 |
+
$minutes = date( 'i', time() ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
343 |
+
$seconds = date( 's', time() ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
344 |
+
|
345 |
+
$file_minutes = date( 'i', $time ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
346 |
+
$file_seconds = date( 's', $time ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
347 |
+
|
348 |
+
$minuteDiff = $minutes - $file_minutes;
|
349 |
+
if ( 59 === $minuteDiff ) {
|
350 |
+
$minuteDiff = 1;
|
351 |
+
}
|
352 |
+
$secondsdiff = ( $minuteDiff * 60 ) + $seconds - $file_seconds;
|
353 |
+
|
354 |
+
$file = $wp_filesystem->get_contents( $pidFile );
|
355 |
+
$information['file'] = basename( $file );
|
356 |
+
if ( $secondsdiff < 80 ) {
|
357 |
+
$information['status'] = 'busy';
|
358 |
+
} else {
|
359 |
+
$information['status'] = 'stalled';
|
360 |
+
}
|
361 |
+
} elseif ( $wp_filesystem->is_file( $doneFile ) ) {
|
362 |
+
$file = $wp_filesystem->get_contents( $doneFile );
|
363 |
+
$information['status'] = 'done';
|
364 |
+
$information['file'] = basename( $file );
|
365 |
+
$information['size'] = filesize( $file );
|
366 |
+
} else {
|
367 |
+
$information['status'] = 'invalid';
|
368 |
+
}
|
369 |
+
|
370 |
+
MainWP_Helper::write( $information );
|
371 |
+
}
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Perform a backup.
|
375 |
+
*
|
376 |
+
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
377 |
+
*
|
378 |
+
* @return array Array of information on the backup containing the type of backup performed, full, or DB & whether or not it was successful.
|
379 |
+
*
|
380 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit() Set PHP Memory Limit and PHP Max Execution time values.
|
381 |
+
* @uses \MainWP\Child\MainWP_Helper::end_session() End session and flush the output buffer.
|
382 |
+
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem() Get the WordPress filesystem.
|
383 |
+
* @uses \MainWP\Child\MainWP_Helper::ends_with() Check if the String 1 ends with the String 2.
|
384 |
+
* @uses \MainWP\Child\MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
385 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_full() Perform a full backup.
|
386 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit()
|
387 |
+
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
388 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
389 |
+
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
390 |
+
* @uses \MainWP\Child\MainWP_Helper::ends_with()
|
391 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
392 |
+
*/
|
393 |
+
public function backup( $write = true ) {
|
394 |
+
|
395 |
+
$timeout = 20 * 60 * 60;
|
396 |
+
MainWP_Helper::set_limit( $timeout );
|
397 |
+
|
398 |
+
MainWP_Helper::end_session();
|
399 |
+
|
400 |
+
// Cleanup pid files!
|
401 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
402 |
+
$backupdir = trailingslashit( $dirs[0] );
|
403 |
+
|
404 |
+
/**
|
405 |
+
* WordPress files system object.
|
406 |
+
*
|
407 |
+
* @global object
|
408 |
+
*/
|
409 |
+
global $wp_filesystem;
|
410 |
+
|
411 |
+
MainWP_Helper::get_wp_filesystem();
|
412 |
+
|
413 |
+
$files = glob( $backupdir . '*' );
|
414 |
+
foreach ( $files as $file ) {
|
415 |
+
if ( MainWP_Helper::ends_with( $file, '/index.php' ) | MainWP_Helper::ends_with( $file, '/.htaccess' ) ) {
|
416 |
+
continue;
|
417 |
+
}
|
418 |
+
|
419 |
+
if ( ( time() - filemtime( $file ) ) > ( 60 * 60 * 3 ) ) {
|
420 |
+
unlink( $file );
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
$fileName = isset( $_POST['fileUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileUID'] ) ) : '';
|
425 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
426 |
+
|
427 |
+
if ( 'full' === $type ) {
|
428 |
+
|
429 |
+
$res = $this->backup_full( $fileName );
|
430 |
+
|
431 |
+
if ( ! $res ) {
|
432 |
+
$information['full'] = false;
|
433 |
+
} else {
|
434 |
+
$information['full'] = $res['file'];
|
435 |
+
$information['size'] = $res['filesize'];
|
436 |
+
}
|
437 |
+
$information['db'] = false;
|
438 |
+
} elseif ( 'db' == $type ) {
|
439 |
+
$ext = isset( $_POST['ext'] ) ? sanitize_text_field( wp_unslash( $_POST['ext'] ) ) : 'zip';
|
440 |
+
$res = $this->backup_db( $fileName, $ext );
|
441 |
+
if ( ! $res ) {
|
442 |
+
$information['db'] = false;
|
443 |
+
} else {
|
444 |
+
$information['db'] = $res['file'];
|
445 |
+
$information['size'] = $res['filesize'];
|
446 |
+
}
|
447 |
+
$information['full'] = false;
|
448 |
+
} else {
|
449 |
+
$information['full'] = false;
|
450 |
+
$information['db'] = false;
|
451 |
+
}
|
452 |
+
|
453 |
+
if ( $write ) {
|
454 |
+
MainWP_Helper::write( $information );
|
455 |
+
}
|
456 |
+
|
457 |
+
return $information;
|
458 |
+
}
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Perform a full backup.
|
462 |
+
*
|
463 |
+
* @param string $fileName Backup archive file name.
|
464 |
+
*
|
465 |
+
* @return array|bool Returns an array containing the Backup location & file size. Return FALSE on failure.
|
466 |
+
*
|
467 |
+
* @uses \MainWP\Child\MainWP_Backup::create_full_backup() Create full backup.
|
468 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
469 |
+
*/
|
470 |
+
public function backup_full( $fileName ) {
|
471 |
+
$excludes = ( isset( $_POST['exclude'] ) ? explode( ',', wp_unslash( $_POST['exclude'] ) ) : array() );
|
472 |
+
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/mainwp';
|
473 |
+
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
474 |
+
$uploadDir = $uploadDir[0];
|
475 |
+
$excludes[] = str_replace( ABSPATH, '', $uploadDir );
|
476 |
+
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/object-cache.php';
|
477 |
+
|
478 |
+
if ( function_exists( 'posix_uname' ) ) {
|
479 |
+
$uname = posix_uname();
|
480 |
+
if ( is_array( $uname ) && isset( $uname['nodename'] ) ) {
|
481 |
+
if ( stristr( $uname['nodename'], 'hostgator' ) ) {
|
482 |
+
if ( ! isset( $_POST['file_descriptors'] ) || '0' == $_POST['file_descriptors'] || $_POST['file_descriptors'] > 1000 ) {
|
483 |
+
$_POST['file_descriptors'] = 1000;
|
484 |
+
}
|
485 |
+
$_POST['file_descriptors_auto'] = 0;
|
486 |
+
$_POST['loadFilesBeforeZip'] = false;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
$file_descriptors = ( isset( $_POST['file_descriptors'] ) ? intval( wp_unslash( $_POST['file_descriptors'] ) ) : 0 );
|
492 |
+
$file_descriptors_auto = ( isset( $_POST['file_descriptors_auto'] ) ? intval( wp_unslash( $_POST['file_descriptors_auto'] ) ) : 0 );
|
493 |
+
if ( 1 === (int) $file_descriptors_auto ) {
|
494 |
+
if ( function_exists( 'posix_getrlimit' ) ) {
|
495 |
+
$result = posix_getrlimit();
|
496 |
+
if ( isset( $result['soft openfiles'] ) ) {
|
497 |
+
$file_descriptors = $result['soft openfiles'];
|
498 |
+
}
|
499 |
+
}
|
500 |
+
}
|
501 |
+
|
502 |
+
$loadFilesBeforeZip = ( isset( $_POST['loadFilesBeforeZip'] ) ? sanitize_text_field( wp_unslash( $_POST['loadFilesBeforeZip'] ) ) : true );
|
503 |
+
|
504 |
+
$newExcludes = array();
|
505 |
+
foreach ( $excludes as $exclude ) {
|
506 |
+
$newExcludes[] = rtrim( $exclude, '/' );
|
507 |
+
}
|
508 |
+
|
509 |
+
$excludebackup = ( isset( $_POST['excludebackup'] ) && '1' == $_POST['excludebackup'] );
|
510 |
+
$excludecache = ( isset( $_POST['excludecache'] ) && '1' == $_POST['excludecache'] );
|
511 |
+
$excludezip = ( isset( $_POST['excludezip'] ) && '1' == $_POST['excludezip'] );
|
512 |
+
$excludenonwp = ( isset( $_POST['excludenonwp'] ) && '1' == $_POST['excludenonwp'] );
|
513 |
+
|
514 |
+
if ( $excludebackup ) {
|
515 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backupbuddy_backups';
|
516 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backupbuddy_temp';
|
517 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/pb_backupbuddy';
|
518 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/managewp';
|
519 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/infinitewp';
|
520 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
521 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
522 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backwpup*';
|
523 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/plugins/wp-complete-backup/storage';
|
524 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
525 |
+
$newExcludes[] = '/administrator/backups';
|
526 |
+
}
|
527 |
+
|
528 |
+
if ( $excludecache ) {
|
529 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/w3tc-cache';
|
530 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/w3tc';
|
531 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/config';
|
532 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/minify';
|
533 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/page_enhanced';
|
534 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/tmp';
|
535 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/supercache';
|
536 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/quick-cache';
|
537 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/hyper-cache/cache';
|
538 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/all';
|
539 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/wp-rocket';
|
540 |
+
}
|
541 |
+
|
542 |
+
$file = false;
|
543 |
+
if ( isset( $_POST['f'] ) ) {
|
544 |
+
$file = ! empty( $_POST['f'] ) ? wp_unslash( $_POST['f'] ) : false;
|
545 |
+
} elseif ( isset( $_POST['file'] ) ) {
|
546 |
+
$file = ! empty( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : false;
|
547 |
+
}
|
548 |
+
|
549 |
+
$ext = isset( $_POST['ext'] ) ? sanitize_text_field( wp_unslash( $_POST['ext'] ) ) : 'zip';
|
550 |
+
$pid = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : false;
|
551 |
+
|
552 |
+
$append = ( isset( $_POST['append'] ) && ( '1' == $_POST['append'] ) );
|
553 |
+
return $this->create_full_backup( $newExcludes, $fileName, true, true, $file_descriptors, $file, $excludezip, $excludenonwp, $loadFilesBeforeZip, $ext, $pid, $append );
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* Backup site database.
|
558 |
+
*
|
559 |
+
* @param string $fileName Backup arhive file name.
|
560 |
+
* @param string $ext Backup achive extension.
|
561 |
+
*
|
562 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option() Update database option by option name.
|
563 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
564 |
+
* @uses \MainWP\Child\MainWP_Backup::create_backup_db() Create database backup.
|
565 |
+
*
|
566 |
+
* @return array|bool $success Returns an array containing the Backup location & file size. Return FALSE on failure.
|
567 |
+
*/
|
568 |
+
public function backup_db( $fileName = '', $ext = 'zip' ) {
|
569 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
570 |
+
$dir = $dirs[0];
|
571 |
+
$timestamp = time();
|
572 |
+
|
573 |
+
if ( '' !== $fileName ) {
|
574 |
+
$fileName .= '-';
|
575 |
+
}
|
576 |
+
|
577 |
+
$filepath_prefix = $dir . 'dbBackup-' . $fileName . $timestamp;
|
578 |
+
|
579 |
+
$dh = opendir( $dir );
|
580 |
+
|
581 |
+
if ( $dh ) {
|
582 |
+
while ( ( $file = readdir( $dh ) ) !== false ) {
|
583 |
+
if ( '.' !== $file && '..' !== $file && ( preg_match( '/dbBackup-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2|\.tmp)?$/', $file ) ) ) {
|
584 |
+
unlink( $dir . $file );
|
585 |
+
}
|
586 |
+
}
|
587 |
+
closedir( $dh );
|
588 |
+
}
|
589 |
+
|
590 |
+
$result = $this->create_backup_db( $filepath_prefix, $ext );
|
591 |
+
|
592 |
+
MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) );
|
593 |
+
|
594 |
+
return ( ! $result ) ? false : array(
|
595 |
+
'timestamp' => $timestamp,
|
596 |
+
'file' => basename( $result['filepath'] ),
|
597 |
+
'filesize' => filesize( $result['filepath'] ),
|
598 |
+
);
|
599 |
+
}
|
600 |
+
|
601 |
+
/**
|
602 |
+
* Create the ZIP file.
|
603 |
+
*
|
604 |
+
* @param array $files Files to zip.
|
605 |
+
* @param string $archive Type of archive to create.
|
606 |
+
*
|
607 |
+
* @return bool Return FALSE on failure, TRUE on success.
|
608 |
+
*
|
609 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit() Set PHP memory limit.
|
610 |
+
*/
|
611 |
+
public function zip_file( $files, $archive ) {
|
612 |
+
$this->timeout = 20 * 60 * 60;
|
613 |
+
$mem = '512M';
|
614 |
+
MainWP_Helper::set_limit( $this->timeout, $mem );
|
615 |
+
|
616 |
+
if ( ! is_array( $files ) ) {
|
617 |
+
$files = array( $files );
|
618 |
+
}
|
619 |
+
|
620 |
+
if ( null !== $this->archiver ) {
|
621 |
+
$success = $this->archiver->zip_file( $files, $archive );
|
622 |
+
} elseif ( $this->check_zip_support() ) {
|
623 |
+
$success = $this->m_zip_file( $files, $archive );
|
624 |
+
} elseif ( $this->check_zip_console() ) {
|
625 |
+
$success = $this->m_zip_file_console( $files, $archive );
|
626 |
+
} else {
|
627 |
+
$success = $this->m_zip_file_pcl( $files, $archive );
|
628 |
+
}
|
629 |
+
|
630 |
+
return $success;
|
631 |
+
}
|
632 |
+
|
633 |
+
/**
|
634 |
+
* Create m_zip_file.
|
635 |
+
*
|
636 |
+
* @param array $files Files to zip.
|
637 |
+
* @param string $archive Type of archive to create.
|
638 |
+
*
|
639 |
+
* @return bool Return false on failure.
|
640 |
+
*/
|
641 |
+
public function m_zip_file( $files, $archive ) {
|
642 |
+
$this->zip = new \ZipArchive();
|
643 |
+
$this->zipArchiveFileCount = 0;
|
644 |
+
$this->zipArchiveSizeCount = 0;
|
645 |
+
|
646 |
+
$zipRes = $this->zip->open( $archive, \ZipArchive::CREATE );
|
647 |
+
if ( $zipRes ) {
|
648 |
+
foreach ( $files as $file ) {
|
649 |
+
$this->add_fileToZip( $file, basename( $file ) );
|
650 |
+
}
|
651 |
+
|
652 |
+
return $this->zip->close();
|
653 |
+
}
|
654 |
+
|
655 |
+
return false;
|
656 |
+
}
|
657 |
+
|
658 |
+
/**
|
659 |
+
* Method m_zip_file_console().
|
660 |
+
*
|
661 |
+
* @param array $files Files to zip.
|
662 |
+
* @param string $archive Type of archive to create.
|
663 |
+
*
|
664 |
+
* @return bool Return false.
|
665 |
+
*/
|
666 |
+
public function m_zip_file_console( $files, $archive ) {
|
667 |
+
return false;
|
668 |
+
}
|
669 |
+
|
670 |
+
/**
|
671 |
+
* Use pclzip to add files to the zip archive.
|
672 |
+
*
|
673 |
+
* @param array $files Files to zip.
|
674 |
+
* @param string $archive Type of archive to create.
|
675 |
+
*
|
676 |
+
* @return array $rslt Return array of results.
|
677 |
+
*/
|
678 |
+
public function m_zip_file_pcl( $files, $archive ) {
|
679 |
+
// Zip this backup folder.
|
680 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
681 |
+
$this->zip = new \PclZip( $archive );
|
682 |
+
|
683 |
+
$error = false;
|
684 |
+
foreach ( $files as $file ) {
|
685 |
+
$rslt = $this->zip->add( $file, PCLZIP_OPT_REMOVE_PATH, dirname( $file ) );
|
686 |
+
if ( 0 === $rslt ) {
|
687 |
+
$error = true;
|
688 |
+
}
|
689 |
+
}
|
690 |
+
|
691 |
+
return ! $error;
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Check for default PHP zip support.
|
696 |
+
*
|
697 |
+
* @return bool Returns true if class_name is a defined class, false otherwise.
|
698 |
+
*/
|
699 |
+
public function check_zip_support() {
|
700 |
+
return class_exists( '\ZipArchive' );
|
701 |
+
}
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Check if we could run zip on console
|
705 |
+
*
|
706 |
+
* @return bool Return false.
|
707 |
+
*/
|
708 |
+
public function check_zip_console() {
|
709 |
+
return false;
|
710 |
+
}
|
711 |
+
|
712 |
+
/**
|
713 |
+
* Create full backup using default PHP zip library.
|
714 |
+
*
|
715 |
+
* @param string $filepath File path to create.
|
716 |
+
* @param array $excludes Files to exclude from the backup.
|
717 |
+
* @param bool $addConfig Add config file to backup.
|
718 |
+
* @param bool $includeCoreFiles Include WordPress core files.
|
719 |
+
* @param bool $excludezip Exclude zip files from the backup.
|
720 |
+
* @param bool $excludenonwp Exclude non-WordPress directories in site root.
|
721 |
+
*
|
722 |
+
* @uses \MainWP\Child\MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
723 |
+
* @uses \MainWP\Child\MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
724 |
+
* @uses \MainWP\Child\MainWP_Backup::include_core_files() Include core files in backup.
|
725 |
+
* @uses \MainWP\Child\MainWP_Backup::add_config() Add config file to backup.
|
726 |
+
*
|
727 |
+
* @return bool Return true on success & false on failure.
|
728 |
+
*/
|
729 |
+
public function create_zip_full_backup(
|
730 |
+
$filepath,
|
731 |
+
$excludes,
|
732 |
+
$addConfig,
|
733 |
+
$includeCoreFiles,
|
734 |
+
$excludezip,
|
735 |
+
$excludenonwp ) {
|
736 |
+
|
737 |
+
$this->excludeZip = $excludezip;
|
738 |
+
$this->zip = new \ZipArchive();
|
739 |
+
$this->zipArchiveFileCount = 0;
|
740 |
+
$this->zipArchiveSizeCount = 0;
|
741 |
+
$this->zipArchiveFileName = $filepath;
|
742 |
+
$zipRes = $this->zip->open( $filepath, \ZipArchive::CREATE );
|
743 |
+
if ( $zipRes ) {
|
744 |
+
$nodes = glob( ABSPATH . '*' );
|
745 |
+
if ( ! $includeCoreFiles ) {
|
746 |
+
$this->include_core_files( $nodes );
|
747 |
+
}
|
748 |
+
|
749 |
+
$db_files = $this->create_backup_db( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
|
750 |
+
foreach ( $db_files as $db_file ) {
|
751 |
+
$this->add_file_to_zipp( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) );
|
752 |
+
}
|
753 |
+
|
754 |
+
if ( file_exists( ABSPATH . '.htaccess' ) ) {
|
755 |
+
$this->add_file_to_zipp( ABSPATH . '.htaccess', 'mainwp-htaccess' );
|
756 |
+
}
|
757 |
+
|
758 |
+
foreach ( $nodes as $node ) {
|
759 |
+
if ( $excludenonwp && is_dir( $node ) ) {
|
760 |
+
if ( ! MainWP_Helper::starts_with( $node, WP_CONTENT_DIR ) && ! MainWP_Helper::starts_with( $node, ABSPATH . 'wp-admin' ) && ! MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
761 |
+
continue;
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
766 |
+
if ( is_dir( $node ) ) {
|
767 |
+
$this->zip_add_dir( $node, $excludes );
|
768 |
+
} elseif ( is_file( $node ) ) {
|
769 |
+
$this->add_file_to_zipp( $node, str_replace( ABSPATH, '', $node ) );
|
770 |
+
}
|
771 |
+
}
|
772 |
+
}
|
773 |
+
|
774 |
+
if ( $addConfig ) {
|
775 |
+
$this->add_config();
|
776 |
+
}
|
777 |
+
|
778 |
+
$return = $this->zip->close();
|
779 |
+
foreach ( $db_files as $db_file ) {
|
780 |
+
unlink( $db_file );
|
781 |
+
}
|
782 |
+
|
783 |
+
return true;
|
784 |
+
}
|
785 |
+
|
786 |
+
return false;
|
787 |
+
}
|
788 |
+
|
789 |
+
/**
|
790 |
+
* Exclude certain core files from the backup.
|
791 |
+
*
|
792 |
+
* @param array $nodes Default nodes.
|
793 |
+
*
|
794 |
+
* @uses \MainWP\Child\MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
795 |
+
*/
|
796 |
+
private function include_core_files( &$nodes ) {
|
797 |
+
$coreFiles = array(
|
798 |
+
'favicon.ico',
|
799 |
+
'index.php',
|
800 |
+
'license.txt',
|
801 |
+
'readme.html',
|
802 |
+
'wp-activate.php',
|
803 |
+
'wp-app.php',
|
804 |
+
'wp-blog-header.php',
|
805 |
+
'wp-comments-post.php',
|
806 |
+
'wp-config.php',
|
807 |
+
'wp-config-sample.php',
|
808 |
+
'wp-cron.php',
|
809 |
+
'wp-links-opml.php',
|
810 |
+
'wp-load.php',
|
811 |
+
'wp-login.php',
|
812 |
+
'wp-mail.php',
|
813 |
+
'wp-pass.php',
|
814 |
+
'wp-register.php',
|
815 |
+
'wp-settings.php',
|
816 |
+
'wp-signup.php',
|
817 |
+
'wp-trackback.php',
|
818 |
+
'xmlrpc.php',
|
819 |
+
);
|
820 |
+
foreach ( $nodes as $key => $node ) {
|
821 |
+
if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
822 |
+
unset( $nodes[ $key ] );
|
823 |
+
} elseif ( MainWP_Helper::starts_with( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
|
824 |
+
unset( $nodes[ $key ] );
|
825 |
+
} else {
|
826 |
+
foreach ( $coreFiles as $coreFile ) {
|
827 |
+
if ( ABSPATH . $coreFile === $node ) {
|
828 |
+
unset( $nodes[ $key ] );
|
829 |
+
}
|
830 |
+
}
|
831 |
+
}
|
832 |
+
}
|
833 |
+
unset( $coreFiles );
|
834 |
+
}
|
835 |
+
|
836 |
+
/**
|
837 |
+
* Add config file to backup.
|
838 |
+
*
|
839 |
+
* @uses wp_json_encode() Encode a variable into JSON, with some sanity checks.
|
840 |
+
* @see https://developer.wordpress.org/reference/functions/wp_json_encode/
|
841 |
+
*
|
842 |
+
* @uses get_option() Get option by name.
|
843 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
844 |
+
*/
|
845 |
+
public function add_config() {
|
846 |
+
|
847 |
+
/**
|
848 |
+
* WordPress Database instance.
|
849 |
+
*
|
850 |
+
* @global object $wpdb
|
851 |
+
*/
|
852 |
+
global $wpdb;
|
853 |
+
|
854 |
+
$plugins = array();
|
855 |
+
$dir = WP_CONTENT_DIR . '/plugins/';
|
856 |
+
$fh = opendir( $dir );
|
857 |
+
while ( $entry = readdir( $fh ) ) {
|
858 |
+
if ( ! is_dir( $dir . $entry ) ) {
|
859 |
+
continue;
|
860 |
+
}
|
861 |
+
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
862 |
+
continue;
|
863 |
+
}
|
864 |
+
$plugins[] = $entry;
|
865 |
+
}
|
866 |
+
closedir( $fh );
|
867 |
+
|
868 |
+
$themes = array();
|
869 |
+
$dir = WP_CONTENT_DIR . '/themes/';
|
870 |
+
$fh = opendir( $dir );
|
871 |
+
while ( $entry = readdir( $fh ) ) {
|
872 |
+
if ( ! is_dir( $dir . $entry ) ) {
|
873 |
+
continue;
|
874 |
+
}
|
875 |
+
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
876 |
+
continue;
|
877 |
+
}
|
878 |
+
$themes[] = $entry;
|
879 |
+
}
|
880 |
+
closedir( $fh );
|
881 |
+
|
882 |
+
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
|
883 |
+
$string = wp_json_encode(
|
884 |
+
array(
|
885 |
+
'siteurl' => get_option( 'siteurl' ),
|
886 |
+
'home' => get_option( 'home' ),
|
887 |
+
'abspath' => ABSPATH,
|
888 |
+
'prefix' => $wpdb->prefix,
|
889 |
+
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
890 |
+
'plugins' => $plugins,
|
891 |
+
'themes' => $themes,
|
892 |
+
)
|
893 |
+
);
|
894 |
+
} else {
|
895 |
+
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Safe requst, required for backwards compatibility.
|
896 |
+
serialize( // phpcs:ignore -- Safe requst, required for backwards compatibility.
|
897 |
+
array(
|
898 |
+
'siteurl' => get_option( 'siteurl' ),
|
899 |
+
'home' => get_option( 'home' ),
|
900 |
+
'abspath' => ABSPATH,
|
901 |
+
'prefix' => $wpdb->prefix,
|
902 |
+
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
903 |
+
'plugins' => $plugins,
|
904 |
+
'themes' => $themes,
|
905 |
+
)
|
906 |
+
)
|
907 |
+
);
|
908 |
+
}
|
909 |
+
|
910 |
+
$this->add_file_from_string_to_zip( 'clone/config.txt', $string );
|
911 |
+
}
|
912 |
+
|
913 |
+
/**
|
914 |
+
* Copy directory.
|
915 |
+
*
|
916 |
+
* @param array $nodes Default nodes.
|
917 |
+
* @param array $excludes Files & directories to exclude.
|
918 |
+
* @param string $backupfolder Backup folder.
|
919 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
920 |
+
*
|
921 |
+
* @uses \MainWP\Child\MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
922 |
+
* @uses \MainWP\Child\MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
923 |
+
* @uses \MainWP\Child\MainWP_Helper::ends_with() Check if the String 1 ends with the String 2.
|
924 |
+
*/
|
925 |
+
public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp ) {
|
926 |
+
if ( ! is_array( $nodes ) ) {
|
927 |
+
return;
|
928 |
+
}
|
929 |
+
|
930 |
+
foreach ( $nodes as $node ) {
|
931 |
+
if ( $excludenonwp && is_dir( $node ) ) {
|
932 |
+
if ( ! MainWP_Helper::starts_with( $node, WP_CONTENT_DIR ) && ! MainWP_Helper::starts_with( $node, ABSPATH . 'wp-admin' ) && ! MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
933 |
+
continue;
|
934 |
+
}
|
935 |
+
}
|
936 |
+
|
937 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
938 |
+
if ( is_dir( $node ) ) {
|
939 |
+
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
|
940 |
+
mkdir( str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
941 |
+
}
|
942 |
+
|
943 |
+
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
|
944 |
+
$this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false );
|
945 |
+
unset( $newnodes );
|
946 |
+
} elseif ( is_file( $node ) ) {
|
947 |
+
if ( $this->excludeZip && MainWP_Helper::ends_with( $node, '.zip' ) ) {
|
948 |
+
continue;
|
949 |
+
}
|
950 |
+
|
951 |
+
copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
952 |
+
}
|
953 |
+
}
|
954 |
+
}
|
955 |
+
}
|
956 |
+
|
957 |
+
/**
|
958 |
+
* Create PCL zip full backup 2.
|
959 |
+
*
|
960 |
+
* @param string $filepath Path to file.
|
961 |
+
* @param array $excludes Files & directories to exclude.
|
962 |
+
* @param bool $addConfig Add config file to backup.
|
963 |
+
* @param bool $includeCoreFiles Whether to include core files.
|
964 |
+
* @param bool $excludezip Whether to exclude zip archives.
|
965 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
966 |
+
*
|
967 |
+
* @return bool Return true on success.
|
968 |
+
*
|
969 |
+
* @uses \MainWP\Child\MainWP_Helper::delete_dir() Delete wanted directory.
|
970 |
+
* @uses \MainWP\Child\MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
971 |
+
* @uses \MainWP\Child\MainWP_Backup::create_backup_db() Create database backup.
|
972 |
+
* @uses \MainWP\Child\MainWP_Backup::add_file_from_string_to_pcl_zip() Add file from a string to pclzip file.
|
973 |
+
*
|
974 |
+
* @uses wp_json_encode() Encode a variable into JSON, with some sanity checks.
|
975 |
+
* @see https://developer.wordpress.org/reference/functions/wp_json_encode/
|
976 |
+
*
|
977 |
+
* @uses get_option() Get option by name.
|
978 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
979 |
+
*/
|
980 |
+
public function create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
|
981 |
+
// Create backup folder.
|
982 |
+
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
|
983 |
+
|
984 |
+
mkdir( $backupFolder ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
985 |
+
|
986 |
+
// Create DB backup.
|
987 |
+
$db_files = $this->create_backup_db( $backupFolder . 'dbBackup' );
|
988 |
+
|
989 |
+
// Copy installation to backup folder.
|
990 |
+
$nodes = glob( ABSPATH . '*' );
|
991 |
+
if ( ! $includeCoreFiles ) {
|
992 |
+
$coreFiles = array(
|
993 |
+
'favicon.ico',
|
994 |
+
'index.php',
|
995 |
+
'license.txt',
|
996 |
+
'readme.html',
|
997 |
+
'wp-activate.php',
|
998 |
+
'wp-app.php',
|
999 |
+
'wp-blog-header.php',
|
1000 |
+
'wp-comments-post.php',
|
1001 |
+
'wp-config.php',
|
1002 |
+
'wp-config-sample.php',
|
1003 |
+
'wp-cron.php',
|
1004 |
+
'wp-links-opml.php',
|
1005 |
+
'wp-load.php',
|
1006 |
+
'wp-login.php',
|
1007 |
+
'wp-mail.php',
|
1008 |
+
'wp-pass.php',
|
1009 |
+
'wp-register.php',
|
1010 |
+
'wp-settings.php',
|
1011 |
+
'wp-signup.php',
|
1012 |
+
'wp-trackback.php',
|
1013 |
+
'xmlrpc.php',
|
1014 |
+
);
|
1015 |
+
foreach ( $nodes as $key => $node ) {
|
1016 |
+
if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
1017 |
+
unset( $nodes[ $key ] );
|
1018 |
+
} elseif ( MainWP_Helper::starts_with( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
|
1019 |
+
unset( $nodes[ $key ] );
|
1020 |
+
} else {
|
1021 |
+
foreach ( $coreFiles as $coreFile ) {
|
1022 |
+
if ( ABSPATH . $coreFile == $node ) {
|
1023 |
+
unset( $nodes[ $key ] );
|
1024 |
+
}
|
1025 |
+
}
|
1026 |
+
}
|
1027 |
+
}
|
1028 |
+
unset( $coreFiles );
|
1029 |
+
}
|
1030 |
+
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
|
1031 |
+
|
1032 |
+
foreach ( $db_files as $db_file ) {
|
1033 |
+
copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1034 |
+
unlink( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
unset( $nodes );
|
1038 |
+
|
1039 |
+
// Zip this backup folder.
|
1040 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
1041 |
+
$this->zip = new \PclZip( $filepath );
|
1042 |
+
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
|
1043 |
+
if ( $addConfig ) {
|
1044 |
+
|
1045 |
+
/**
|
1046 |
+
* WordPress Database instance.
|
1047 |
+
*
|
1048 |
+
* @global object $wpdb
|
1049 |
+
*/
|
1050 |
+
global $wpdb;
|
1051 |
+
|
1052 |
+
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
|
1053 |
+
$string = wp_json_encode(
|
1054 |
+
array(
|
1055 |
+
'siteurl' => get_option( 'siteurl' ),
|
1056 |
+
'home' => get_option( 'home' ),
|
1057 |
+
'abspath' => ABSPATH,
|
1058 |
+
'prefix' => $wpdb->prefix,
|
1059 |
+
'lang' => WPLANG,
|
1060 |
+
)
|
1061 |
+
);
|
1062 |
+
} else {
|
1063 |
+
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Safe requst, required for backwards compatibility.
|
1064 |
+
serialize( // phpcs:ignore -- Safe requst, required for backwards compatibility.
|
1065 |
+
array(
|
1066 |
+
'siteurl' => get_option( 'siteurl' ),
|
1067 |
+
'home' => get_option( 'home' ),
|
1068 |
+
'abspath' => ABSPATH,
|
1069 |
+
'prefix' => $wpdb->prefix,
|
1070 |
+
'lang' => WPLANG,
|
1071 |
+
)
|
1072 |
+
)
|
1073 |
+
);
|
1074 |
+
}
|
1075 |
+
|
1076 |
+
$this->add_file_from_string_to_pcl_zip( 'clone/config.txt', $string, $filepath );
|
1077 |
+
}
|
1078 |
+
// Remove backup folder.
|
1079 |
+
MainWP_Helper::delete_dir( $backupFolder );
|
1080 |
+
|
1081 |
+
return true;
|
1082 |
+
}
|
1083 |
+
|
1084 |
+
/**
|
1085 |
+
* Recursively add directory to default PHP zip library.
|
1086 |
+
*
|
1087 |
+
* @param string $path Path to directory.
|
1088 |
+
* @param array $excludes Files or directories to exclude.
|
1089 |
+
*
|
1090 |
+
* @uses \MainWP\Child\MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
1091 |
+
*/
|
1092 |
+
public function zip_add_dir( $path, $excludes ) {
|
1093 |
+
$this->zip->add_empty_dir( str_replace( ABSPATH, '', $path ) );
|
1094 |
+
|
1095 |
+
if ( file_exists( rtrim( $path, '/' ) . '/.htaccess' ) ) {
|
1096 |
+
$this->add_file_to_zipp( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' );
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
$iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path ), \RecursiveIteratorIterator::SELF_FIRST );
|
1100 |
+
|
1101 |
+
foreach ( $iterator as $path ) {
|
1102 |
+
$name = $path->__toString();
|
1103 |
+
if ( ( '.' === basename( $name ) ) || ( '..' === basename( $name ) ) ) {
|
1104 |
+
continue;
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $name ) ) ) {
|
1108 |
+
if ( $path->isDir() ) {
|
1109 |
+
$this->zip_add_dir( $name, $excludes );
|
1110 |
+
} else {
|
1111 |
+
$this->add_file_to_zipp( $name, str_replace( ABSPATH, '', $name ) );
|
1112 |
+
}
|
1113 |
+
}
|
1114 |
+
$name = null;
|
1115 |
+
unset( $name );
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
$iterator = null;
|
1119 |
+
unset( $iterator );
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
/**
|
1123 |
+
* Add file from a string to zip file.
|
1124 |
+
*
|
1125 |
+
* @param resource $file File to add to zip.
|
1126 |
+
* @param string $string String to add.
|
1127 |
+
*
|
1128 |
+
* @return bool true|false.
|
1129 |
+
*/
|
1130 |
+
public function add_file_from_string_to_zip( $file, $string ) {
|
1131 |
+
return $this->zip->addFromString( $file, $string );
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
/**
|
1135 |
+
* Add file from a string to pclzip file.
|
1136 |
+
*
|
1137 |
+
* @param resource $file File to add to zip.
|
1138 |
+
* @param string $string String to add.
|
1139 |
+
* @param string $filepath Path to file.
|
1140 |
+
*
|
1141 |
+
* @return bool true|false.
|
1142 |
+
*/
|
1143 |
+
public function add_file_from_string_to_pcl_zip( $file, $string, $filepath ) {
|
1144 |
+
$file = preg_replace( '/(?:\.|\/)*(.*)/', '$1', $file );
|
1145 |
+
$localpath = dirname( $file );
|
1146 |
+
$tmpfilename = dirname( $filepath ) . '/' . basename( $file );
|
1147 |
+
if ( false !== file_put_contents( $tmpfilename, $string ) ) {
|
1148 |
+
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
|
1149 |
+
$add = $this->zip->add(
|
1150 |
+
$tmpfilename,
|
1151 |
+
PCLZIP_OPT_REMOVE_PATH,
|
1152 |
+
dirname( $filepath ),
|
1153 |
+
PCLZIP_OPT_ADD_PATH,
|
1154 |
+
$localpath
|
1155 |
+
);
|
1156 |
+
unlink( $tmpfilename );
|
1157 |
+
if ( ! empty( $add ) ) {
|
1158 |
+
return true;
|
1159 |
+
}
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
return false;
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
/**
|
1166 |
+
* Add file to zip.
|
1167 |
+
*
|
1168 |
+
* @param string $path Path to zip file.
|
1169 |
+
* @param string $zipEntryName File to add to zip.
|
1170 |
+
*
|
1171 |
+
* @return bool True|false.
|
1172 |
+
*
|
1173 |
+
* @uses \MainWP\Child\MainWP_Helper::ends_with()
|
1174 |
+
*/
|
1175 |
+
public function add_file_to_zipp( $path, $zipEntryName ) {
|
1176 |
+
if ( time() - $this->lastRun > 20 ) {
|
1177 |
+
set_time_limit( $this->timeout ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1178 |
+
$this->lastRun = time();
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
if ( $this->excludeZip && MainWP_Helper::ends_with( $path, '.zip' ) ) {
|
1182 |
+
return false;
|
1183 |
+
}
|
1184 |
+
|
1185 |
+
$this->zipArchiveSizeCount += filesize( $path );
|
1186 |
+
$this->gcCnt ++;
|
1187 |
+
|
1188 |
+
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
|
1189 |
+
$this->zipArchiveFileCount ++;
|
1190 |
+
$added = $this->zip->add_file( $path, $zipEntryName );
|
1191 |
+
} else {
|
1192 |
+
$this->zipArchiveFileCount ++;
|
1193 |
+
|
1194 |
+
$this->testContent = file_get_contents( $path );
|
1195 |
+
if ( false === $this->testContent ) {
|
1196 |
+
return false;
|
1197 |
+
}
|
1198 |
+
$added = $this->zip->addFromString( $zipEntryName, $this->testContent );
|
1199 |
+
}
|
1200 |
+
|
1201 |
+
if ( $this->gcCnt > 20 ) {
|
1202 |
+
if ( function_exists( 'gc_enable' ) ) {
|
1203 |
+
gc_enable();
|
1204 |
+
}
|
1205 |
+
if ( function_exists( 'gc_collect_cycles' ) ) {
|
1206 |
+
gc_collect_cycles();
|
1207 |
+
}
|
1208 |
+
$this->gcCnt = 0;
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) {
|
1212 |
+
$this->zip->close();
|
1213 |
+
$this->zip = null;
|
1214 |
+
unset( $this->zip );
|
1215 |
+
if ( function_exists( 'gc_enable' ) ) {
|
1216 |
+
gc_enable();
|
1217 |
+
}
|
1218 |
+
if ( function_exists( 'gc_collect_cycles' ) ) {
|
1219 |
+
gc_collect_cycles();
|
1220 |
+
}
|
1221 |
+
$this->zip = new \ZipArchive();
|
1222 |
+
$this->zip->open( $this->zipArchiveFileName );
|
1223 |
+
$this->zipArchiveFileCount = 0;
|
1224 |
+
$this->zipArchiveSizeCount = 0;
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
return $added;
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
/**
|
1231 |
+
* Create full backup via console.
|
1232 |
+
*
|
1233 |
+
* @param string $filepath Path to file.
|
1234 |
+
* @param array $excludes Files & directories to exclude.
|
1235 |
+
* @param bool $addConfig Add config file to backup.
|
1236 |
+
* @param bool $includeCoreFiles Whether to include core files.
|
1237 |
+
* @param bool $excludezip Whether to exclude zip archives.
|
1238 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
1239 |
+
*
|
1240 |
+
* @return bool Return false.
|
1241 |
+
*/
|
1242 |
+
public function create_zip_console_full_backup(
|
1243 |
+
$filepath,
|
1244 |
+
$excludes,
|
1245 |
+
$addConfig,
|
1246 |
+
$includeCoreFiles,
|
1247 |
+
$excludezip,
|
1248 |
+
$excludenonwp ) {
|
1249 |
+
|
1250 |
+
return false;
|
1251 |
+
}
|
1252 |
+
|
1253 |
+
/**
|
1254 |
+
* Create DB backup.
|
1255 |
+
*
|
1256 |
+
* @param string $filepath_prefix File path prefix.
|
1257 |
+
* @param bool $archiveExt Archive extension.
|
1258 |
+
* @param object $archiver Archiver.
|
1259 |
+
*
|
1260 |
+
* @return array|string[] Action response.
|
1261 |
+
*
|
1262 |
+
* @uses \MainWP\Child\MainWP_Helper::sanitize_filename() Sanitize filename.
|
1263 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit() Set PHP memory limit.
|
1264 |
+
* @uses \MainWP\Child\MainWP_Child_DB::to_query() Run a mysqli query & get a result.
|
1265 |
+
* @uses \MainWP\Child\MainWP_Child_DB::fetch_array()
|
1266 |
+
* @uses \MainWP\Child\MainWP_Child_DB::real_escape_string()
|
1267 |
+
* @uses \MainWP\Child\Tar_Archiver()
|
1268 |
+
*
|
1269 |
+
* @uses wpdb::get_results() Retrieve an entire SQL result set from the database (i.e., many rows).
|
1270 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_results/
|
1271 |
+
*
|
1272 |
+
* @uses wpdb::get_row() Retrieve one row from the database.
|
1273 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_row/
|
1274 |
+
*/
|
1275 |
+
public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
|
1276 |
+
|
1277 |
+
$timeout = 20 * 60 * 60;
|
1278 |
+
$mem = '512M';
|
1279 |
+
MainWP_Helper::set_limit( $timeout, $mem );
|
1280 |
+
|
1281 |
+
/**
|
1282 |
+
* WordPress Database instance.
|
1283 |
+
*
|
1284 |
+
* @global object $wpdb
|
1285 |
+
*/
|
1286 |
+
global $wpdb;
|
1287 |
+
|
1288 |
+
$db_files = array();
|
1289 |
+
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1290 |
+
foreach ( $tables_db as $curr_table ) {
|
1291 |
+
if ( null !== $archiver ) {
|
1292 |
+
$archiver->update_pid_file();
|
1293 |
+
}
|
1294 |
+
|
1295 |
+
$table = $curr_table[0];
|
1296 |
+
|
1297 |
+
$currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql';
|
1298 |
+
$db_files[] = $currentfile;
|
1299 |
+
if ( file_exists( $currentfile ) ) {
|
1300 |
+
continue;
|
1301 |
+
}
|
1302 |
+
$fh = fopen( $currentfile . '.tmp', 'w' );
|
1303 |
+
|
1304 |
+
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
|
1305 |
+
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1306 |
+
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
|
1307 |
+
|
1308 |
+
$rows = MainWP_Child_DB::to_query( 'SELECT * FROM ' . $table, $wpdb->dbh ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1309 |
+
|
1310 |
+
if ( $rows ) {
|
1311 |
+
$i = 0;
|
1312 |
+
$table_insert = 'INSERT INTO `' . $table . '` VALUES (';
|
1313 |
+
|
1314 |
+
// @codingStandardsIgnoreStart
|
1315 |
+
while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) {
|
1316 |
+
// @codingStandardsIgnoreEnd
|
1317 |
+
$query = $table_insert;
|
1318 |
+
foreach ( $row as $value ) {
|
1319 |
+
if ( null === $value ) {
|
1320 |
+
$query .= 'NULL, ';
|
1321 |
+
} else {
|
1322 |
+
$query .= '"' . MainWP_Child_DB::real_escape_string( $value ) . '", ';
|
1323 |
+
}
|
1324 |
+
}
|
1325 |
+
$query = trim( $query, ', ' ) . ');';
|
1326 |
+
|
1327 |
+
fwrite( $fh, "\n" . $query ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1328 |
+
$i ++;
|
1329 |
+
|
1330 |
+
if ( $i >= 50 ) {
|
1331 |
+
fflush( $fh );
|
1332 |
+
$i = 0;
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
$query = null;
|
1336 |
+
$row = null;
|
1337 |
+
}
|
1338 |
+
}
|
1339 |
+
$rows = null;
|
1340 |
+
fflush( $fh );
|
1341 |
+
fclose( $fh ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1342 |
+
rename( $currentfile . '.tmp', $currentfile );
|
1343 |
+
}
|
1344 |
+
|
1345 |
+
fclose( fopen( $filepath_prefix . '.sql', 'w' ) ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1346 |
+
$db_files[] = $filepath_prefix . '.sql';
|
1347 |
+
|
1348 |
+
$archivefilePath = null;
|
1349 |
+
if ( false !== $archiveExt ) {
|
1350 |
+
$archivefilePath = $filepath_prefix . '.sql.' . $archiveExt;
|
1351 |
+
|
1352 |
+
if ( 'zip' === $archiveExt ) {
|
1353 |
+
$this->archiver = null;
|
1354 |
+
} else {
|
1355 |
+
$this->archiver = new Tar_Archiver( $this, $archiveExt );
|
1356 |
+
}
|
1357 |
+
|
1358 |
+
if ( $this->zip_file( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) {
|
1359 |
+
foreach ( $db_files as $db_file ) {
|
1360 |
+
unlink( $db_file );
|
1361 |
+
}
|
1362 |
+
}
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files );
|
1366 |
+
}
|
1367 |
+
}
|
class/class-mainwp-child-back-up-buddy.php
CHANGED
@@ -1,3856 +1,3859 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Backup Buddy
|
4 |
-
*
|
5 |
-
* The code is used for the MainWP Buddy Extension.
|
6 |
-
*
|
7 |
-
* Credits
|
8 |
-
*
|
9 |
-
* Plugin-Name: BackupBuddy
|
10 |
-
* Plugin URI: http://ithemes.com/purchase/backupbuddy/
|
11 |
-
* Author: iThemes
|
12 |
-
* Author URI: http://ithemes.com/
|
13 |
-
* iThemes Package: backupbuddy
|
14 |
-
*
|
15 |
-
* The code is used for the MainWP Buddy Extension
|
16 |
-
* Extension URL: https://mainwp.com/extension/mainwpbuddy/
|
17 |
-
*
|
18 |
-
* @package MainWP\Child
|
19 |
-
*/
|
20 |
-
|
21 |
-
namespace MainWP\Child;
|
22 |
-
|
23 |
-
// phpcs:disable -- third party credit.
|
24 |
-
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Class MainWP_Child_Back_Up_Buddy
|
28 |
-
*/
|
29 |
-
class MainWP_Child_Back_Up_Buddy {
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Public static variable to hold the single instance of MainWP_Child_Back_Up_Buddy.
|
33 |
-
* @var null
|
34 |
-
*/
|
35 |
-
public static $instance = null;
|
36 |
-
|
37 |
-
/** @var string $plugin_translate Plugin translation string. */
|
38 |
-
public $plugin_translate = 'mainwp-child';
|
39 |
-
|
40 |
-
/** @var bool $is_backupbuddy_installed Whether or not BackupBuddy is installed. Default: False. */
|
41 |
-
public $is_backupbuddy_installed = false;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Create a public static instance of MainWP_Child_Back_Up_Buddy.
|
45 |
-
*
|
46 |
-
* @return MainWP_Child_Back_Up_Buddy|null
|
47 |
-
*/
|
48 |
-
public static function instance() {
|
49 |
-
if ( null === self::$instance ) {
|
50 |
-
self::$instance = new self();
|
51 |
-
}
|
52 |
-
return self::$instance;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* MainWP_Child_Back_Up_Buddy constructor.
|
57 |
-
*
|
58 |
-
* Run any time class is called.
|
59 |
-
*/
|
60 |
-
public function __construct() {
|
61 |
-
// To fix bug run dashboard on local machine.
|
62 |
-
if ( class_exists( '\pb_backupbuddy' ) ) {
|
63 |
-
$this->is_backupbuddy_installed = true;
|
64 |
-
}
|
65 |
-
|
66 |
-
if ( ! $this->is_backupbuddy_installed ) {
|
67 |
-
return;
|
68 |
-
}
|
69 |
-
|
70 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
71 |
-
|
72 |
-
add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) );
|
73 |
-
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
74 |
-
|
75 |
-
if ( get_option( 'mainwp_backupbuddy_hide_plugin' ) === 'hide' ) {
|
76 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
77 |
-
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
78 |
-
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
79 |
-
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
80 |
-
}
|
81 |
-
}
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Hide Backupbuddy update notice.
|
85 |
-
*
|
86 |
-
* @param string $slugs plugin slug.
|
87 |
-
* @return string $slugs Return slugs array.
|
88 |
-
*/
|
89 |
-
public function hide_update_notice( $slugs ) {
|
90 |
-
$slugs[] = 'backupbuddy/backupbuddy.php';
|
91 |
-
return $slugs;
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Remove update nag.
|
96 |
-
*
|
97 |
-
* @param array $value Plugin slug array.
|
98 |
-
* @return array $value Plugin slug array.
|
99 |
-
*
|
100 |
-
* @uses \MainWP\Child\MainWP_Helper::is_updates_screen()
|
101 |
-
*/
|
102 |
-
public function remove_update_nag( $value ) {
|
103 |
-
if ( isset( $_POST['mainwpsignature'] ) ) {
|
104 |
-
return $value;
|
105 |
-
}
|
106 |
-
|
107 |
-
if ( ! MainWP_Helper::is_updates_screen() ) {
|
108 |
-
return $value;
|
109 |
-
}
|
110 |
-
|
111 |
-
if ( isset( $value->response['backupbuddy/backupbuddy.php'] ) ) {
|
112 |
-
unset( $value->response['backupbuddy/backupbuddy.php'] );
|
113 |
-
}
|
114 |
-
|
115 |
-
return $value;
|
116 |
-
}
|
117 |
-
|
118 |
-
|
119 |
-
/**
|
120 |
-
* Remove Backup buddy from plugins list.
|
121 |
-
*
|
122 |
-
* @param array $plugins All plugins array.
|
123 |
-
* @return array $plugins All plugins array with backupbuddy removed.
|
124 |
-
*/
|
125 |
-
public function all_plugins( $plugins ) {
|
126 |
-
foreach ( $plugins as $key => $value ) {
|
127 |
-
$plugin_slug = basename( $key, '.php' );
|
128 |
-
if ( 'backupbuddy' === $plugin_slug ) {
|
129 |
-
unset( $plugins[ $key ] );
|
130 |
-
}
|
131 |
-
}
|
132 |
-
|
133 |
-
return $plugins;
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Remove backupbuddy from admin menu.
|
138 |
-
*/
|
139 |
-
public function admin_menu() {
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Submenu array.
|
143 |
-
*
|
144 |
-
* @global object
|
145 |
-
*/
|
146 |
-
global $submenu;
|
147 |
-
|
148 |
-
remove_menu_page( 'pb_backupbuddy_backup' );
|
149 |
-
|
150 |
-
if ( isset( $_SERVER['REQUEST_URI'] ) && false !== stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=pb_backupbuddy_' ) ) {
|
151 |
-
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
152 |
-
exit();
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Backupbuddy Client Reports log.
|
159 |
-
*
|
160 |
-
* @uses MainWP_Child_Back_Up_Buddy::do_reports_log()
|
161 |
-
*/
|
162 |
-
public function do_site_stats() {
|
163 |
-
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
164 |
-
do_action( 'mainwp_child_reports_log', 'backupbuddy' );
|
165 |
-
} else {
|
166 |
-
$this->do_reports_log( 'backupbuddy' );
|
167 |
-
}
|
168 |
-
}
|
169 |
-
|
170 |
-
/**
|
171 |
-
* Create BackupBuddy Client Reports log.
|
172 |
-
*
|
173 |
-
* @param string $ext Extension to create log for.
|
174 |
-
*
|
175 |
-
* @uses MainWP_Child_Back_Up_Buddy::is_backupbuddy_installed()
|
176 |
-
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
177 |
-
* @uses \MainWP\Child\MainWP_Helper::check_properties()
|
178 |
-
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
179 |
-
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
180 |
-
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
181 |
-
* @uses \pb_backupbuddy_fileoptions()
|
182 |
-
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
183 |
-
* @uses \pb_backupbuddy::$format::prettify()
|
184 |
-
* @uses \backupbuddy_live_periodic::get_stats()
|
185 |
-
* @uses \Exception
|
186 |
-
*/
|
187 |
-
public function do_reports_log( $ext = '' ) {
|
188 |
-
if ( 'backupbuddy' !== $ext ) {
|
189 |
-
return;
|
190 |
-
}
|
191 |
-
|
192 |
-
if ( ! $this->is_backupbuddy_installed ) {
|
193 |
-
return;
|
194 |
-
}
|
195 |
-
|
196 |
-
try {
|
197 |
-
|
198 |
-
MainWP_Helper::check_methods( '\pb_backupbuddy', array( 'plugin_path' ) );
|
199 |
-
|
200 |
-
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
201 |
-
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/core.php' ) ) {
|
202 |
-
require_once \pb_backupbuddy::plugin_path() . '/classes/core.php';
|
203 |
-
}
|
204 |
-
}
|
205 |
-
|
206 |
-
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ) ) {
|
207 |
-
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
208 |
-
}
|
209 |
-
|
210 |
-
MainWP_Helper::check_classes_exists( array( '\backupbuddy_core', '\pb_backupbuddy_fileoptions' ) );
|
211 |
-
MainWP_Helper::check_methods( '\backupbuddy_core', 'getLogDirectory' );
|
212 |
-
|
213 |
-
$pretty_type = array(
|
214 |
-
'full' => 'Full',
|
215 |
-
'db' => 'Database',
|
216 |
-
'files' => 'Files',
|
217 |
-
);
|
218 |
-
|
219 |
-
$recentBackups_list = glob( \backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' );
|
220 |
-
|
221 |
-
foreach ( $recentBackups_list as $backup_fileoptions ) {
|
222 |
-
|
223 |
-
$backup = new \pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
224 |
-
$result = $backup->is_ok();
|
225 |
-
if ( method_exists( $backup, 'is_ok' ) && true !== $result ) {
|
226 |
-
continue;
|
227 |
-
}
|
228 |
-
|
229 |
-
$backup = &$backup->options;
|
230 |
-
|
231 |
-
if ( ! isset( $backup['serial'] ) || ( '' == $backup['serial'] ) ) {
|
232 |
-
continue;
|
233 |
-
}
|
234 |
-
|
235 |
-
$check_finished = false;
|
236 |
-
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
237 |
-
$check_finished = true;
|
238 |
-
}
|
239 |
-
|
240 |
-
if ( ! $check_finished ) {
|
241 |
-
continue;
|
242 |
-
}
|
243 |
-
|
244 |
-
$backupType = '';
|
245 |
-
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
246 |
-
if ( true === MainWP_Helper::check_properties( '\pb_backupbuddy', 'format', true ) ) {
|
247 |
-
if ( true === MainWP_Helper::check_methods( \pb_backupbuddy::$format, array( 'prettify' ), true ) ) {
|
248 |
-
$backupType = \pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type );
|
249 |
-
}
|
250 |
-
}
|
251 |
-
} else {
|
252 |
-
if ( true === MainWP_Helper::check_methods( '\backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true ) ) {
|
253 |
-
$backupType = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
254 |
-
}
|
255 |
-
}
|
256 |
-
|
257 |
-
if ( '' == $backupType ) {
|
258 |
-
$backupType = 'Unknown';
|
259 |
-
}
|
260 |
-
|
261 |
-
$finish_time = $backup['finish_time'];
|
262 |
-
$message = 'BackupBuddy ' . $backupType . ' finished';
|
263 |
-
if ( ! empty( $finish_time ) ) {
|
264 |
-
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
265 |
-
}
|
266 |
-
}
|
267 |
-
|
268 |
-
if ( file_exists( \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ) ) {
|
269 |
-
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
270 |
-
|
271 |
-
MainWP_Helper::check_classes_exists( array( '\backupbuddy_live_periodic' ) );
|
272 |
-
MainWP_Helper::check_methods( '\backupbuddy_live_periodic', 'get_stats' );
|
273 |
-
|
274 |
-
$state = \backupbuddy_live_periodic::get_stats();
|
275 |
-
if ( is_array( $state ) && isset( $state['stats'] ) ) {
|
276 |
-
|
277 |
-
if ( is_array( $state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] ) ) {
|
278 |
-
if ( isset( $state['stats']['last_remote_snapshot_response'] ) ) {
|
279 |
-
$resp = $state['stats']['last_remote_snapshot_response'];
|
280 |
-
if ( isset( $resp['success'] ) && $resp['success'] ) {
|
281 |
-
$finish_time = $state['stats']['last_remote_snapshot'];
|
282 |
-
$backupType = 'Live Backup to cloud';
|
283 |
-
$message = 'BackupBuddy ' . $backupType . ' finished';
|
284 |
-
if ( ! empty( $finish_time ) ) {
|
285 |
-
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
286 |
-
}
|
287 |
-
}
|
288 |
-
}
|
289 |
-
}
|
290 |
-
}
|
291 |
-
}
|
292 |
-
} catch ( \Exception $e ) {
|
293 |
-
// ok!
|
294 |
-
}
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* MainWP Child BackupBuddy actions.
|
299 |
-
*
|
300 |
-
* @uses
|
301 |
-
* @uses \MainWP\Child\
|
302 |
-
* @uses \MainWP\Child\
|
303 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
304 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
305 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
306 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
307 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
308 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
309 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
310 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
311 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
312 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
313 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
314 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
315 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
316 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
317 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
318 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
319 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
320 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
321 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
322 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
323 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
324 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
325 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
326 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
327 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
328 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
329 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
330 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
331 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
332 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
333 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
334 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
335 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
336 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
337 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
338 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
339 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
340 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
341 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
342 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
343 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
344 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
345 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
346 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
347 |
-
* @uses MainWP_Child_Back_Up_Buddy::
|
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 |
-
* @uses \
|
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 |
-
global $wpdb
|
678 |
-
|
679 |
-
|
680 |
-
$
|
681 |
-
$newOptions =
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
$information['
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
*
|
696 |
-
*
|
697 |
-
*
|
698 |
-
*
|
699 |
-
* @uses \pb_backupbuddy
|
700 |
-
* @uses \pb_backupbuddy::
|
701 |
-
* @uses \
|
702 |
-
* @uses \backupbuddy_core::
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
$
|
711 |
-
\pb_backupbuddy::$options
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
$
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
$information['
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
*
|
734 |
-
*
|
735 |
-
*
|
736 |
-
*
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
'
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
*
|
748 |
-
*
|
749 |
-
*
|
750 |
-
*
|
751 |
-
* @uses \pb_backupbuddy::$
|
752 |
-
* @uses \pb_backupbuddy::$format::
|
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 |
-
* @uses
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
$information
|
800 |
-
$information['
|
801 |
-
$information['
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
*
|
816 |
-
*
|
817 |
-
*
|
818 |
-
*
|
819 |
-
* @uses \pb_backupbuddy
|
820 |
-
* @uses \
|
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 |
-
* @uses \
|
849 |
-
* @uses \backupbuddy_core::
|
850 |
-
* @uses \
|
851 |
-
* @uses
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
$
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
\pb_backupbuddy::$options['next_schedule_index']
|
865 |
-
\pb_backupbuddy::$options['
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
$
|
873 |
-
|
874 |
-
\backupbuddy_core::
|
875 |
-
\
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
$information['
|
880 |
-
$information['
|
881 |
-
$information['
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
*
|
889 |
-
*
|
890 |
-
*
|
891 |
-
*
|
892 |
-
* @uses \pb_backupbuddy
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
$
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
\pb_backupbuddy
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
*
|
913 |
-
*
|
914 |
-
*
|
915 |
-
*
|
916 |
-
* @uses \pb_backupbuddy
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
*
|
933 |
-
*
|
934 |
-
* @param
|
935 |
-
*
|
936 |
-
*
|
937 |
-
*
|
938 |
-
*
|
939 |
-
* @uses \backupbuddy_core::
|
940 |
-
* @uses \backupbuddy_core::
|
941 |
-
* @uses \backupbuddy_core::getLogDirectory
|
942 |
-
* @uses \
|
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 |
-
* @param array $
|
991 |
-
*
|
992 |
-
*
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
*
|
1008 |
-
*
|
1009 |
-
* @
|
1010 |
-
*
|
1011 |
-
*
|
1012 |
-
* @uses MainWP_Helper::
|
1013 |
-
* @uses \
|
1014 |
-
* @uses \
|
1015 |
-
* @uses \backupbuddy_core::
|
1016 |
-
* @uses \backupbuddy_core::
|
1017 |
-
* @uses
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
MainWP_Helper::
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
$data
|
1038 |
-
$data['
|
1039 |
-
$data['
|
1040 |
-
$data['
|
1041 |
-
|
1042 |
-
$
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
$
|
1049 |
-
$
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
}
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
}
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
*
|
1067 |
-
*
|
1068 |
-
* @
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
$gmt_offset =
|
1075 |
-
}
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
*
|
1083 |
-
*
|
1084 |
-
* @
|
1085 |
-
*
|
1086 |
-
* @uses
|
1087 |
-
* @uses
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
$information
|
1094 |
-
$
|
1095 |
-
$
|
1096 |
-
$backup_directory =
|
1097 |
-
$
|
1098 |
-
$
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
*
|
1106 |
-
*
|
1107 |
-
* @
|
1108 |
-
*
|
1109 |
-
* @uses \pb_backupbuddy
|
1110 |
-
* @uses \pb_backupbuddy
|
1111 |
-
* @uses \
|
1112 |
-
* @uses \
|
1113 |
-
* @uses \pb_backupbuddy_fileoptions
|
1114 |
-
* @uses \
|
1115 |
-
* @uses \
|
1116 |
-
* @uses \
|
1117 |
-
* @uses \backupbuddy_core::
|
1118 |
-
* @uses \backupbuddy_core::
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
$
|
1128 |
-
$note =
|
1129 |
-
$note =
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
$
|
1135 |
-
|
1136 |
-
$
|
1137 |
-
|
1138 |
-
$
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
*
|
1161 |
-
*
|
1162 |
-
* @
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
}
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
*
|
1181 |
-
*
|
1182 |
-
* @
|
1183 |
-
*
|
1184 |
-
* @uses \pb_backupbuddy::
|
1185 |
-
* @uses \
|
1186 |
-
* @uses \
|
1187 |
-
* @uses \pb_backupbuddy_fileoptions
|
1188 |
-
* @uses \
|
1189 |
-
* @uses \
|
1190 |
-
* @uses \
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
$
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
$
|
1227 |
-
|
1228 |
-
$
|
1229 |
-
}
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
}
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
'
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
*
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
}
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
unset( $
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
$return
|
1316 |
-
$return .= '
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
echo '
|
1321 |
-
|
1322 |
-
|
1323 |
-
$return
|
1324 |
-
$return .= '
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
echo '
|
1333 |
-
|
1334 |
-
echo '
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
return array( '
|
1341 |
-
}
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
*
|
1348 |
-
*
|
1349 |
-
* @
|
1350 |
-
*
|
1351 |
-
*
|
1352 |
-
* @
|
1353 |
-
*
|
1354 |
-
* @uses \MainWP\Child\MainWP_Helper::
|
1355 |
-
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1356 |
-
* @uses
|
1357 |
-
* @uses \
|
1358 |
-
* @uses
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
MainWP_Helper::
|
1365 |
-
MainWP_Helper::check_methods( \pb_backupbuddy
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
$results = $wpdb->get_results( '
|
1377 |
-
}
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
$return .= '<
|
1401 |
-
$return .= '<
|
1402 |
-
$return .= '
|
1403 |
-
$return .= '
|
1404 |
-
$return .= '</
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
*
|
1414 |
-
*
|
1415 |
-
* @
|
1416 |
-
*
|
1417 |
-
* @uses \
|
1418 |
-
* @uses \
|
1419 |
-
* @uses \
|
1420 |
-
* @uses \
|
1421 |
-
* @uses \
|
1422 |
-
* @uses \pb_backupbuddy
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
$
|
1429 |
-
$
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
$
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
}
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
\pb_backupbuddy::status( 'details', '
|
1472 |
-
}
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
*
|
1486 |
-
*
|
1487 |
-
* @
|
1488 |
-
*
|
1489 |
-
* @uses \pb_backupbuddy::
|
1490 |
-
* @uses \
|
1491 |
-
* @uses \
|
1492 |
-
* @uses \
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
$
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
$
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
$pb_backupbuddy_js_status
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
\
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
*
|
1536 |
-
*
|
1537 |
-
*
|
1538 |
-
* @
|
1539 |
-
*
|
1540 |
-
* @
|
1541 |
-
*
|
1542 |
-
* @uses \backupbuddy_core::
|
1543 |
-
* @uses \backupbuddy_core::
|
1544 |
-
* @uses \backupbuddy_core::
|
1545 |
-
* @uses \backupbuddy_core::
|
1546 |
-
* @uses \backupbuddy_core::
|
1547 |
-
* @uses \backupbuddy_core::pretty_backup_type()
|
1548 |
-
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1549 |
-
* @uses \
|
1550 |
-
* @uses \
|
1551 |
-
* @uses \
|
1552 |
-
* @uses \
|
1553 |
-
* @uses \
|
1554 |
-
* @uses \
|
1555 |
-
* @uses \pb_backupbuddy::$format::
|
1556 |
-
* @uses \pb_backupbuddy::$format::
|
1557 |
-
* @uses \pb_backupbuddy::$format::
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
$
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
$
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
'
|
1615 |
-
'
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
$
|
1623 |
-
$
|
1624 |
-
|
1625 |
-
$
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
$
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
$
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
$
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
*
|
1724 |
-
*
|
1725 |
-
* @
|
1726 |
-
*
|
1727 |
-
* @uses \backupbuddy_core::
|
1728 |
-
* @uses \
|
1729 |
-
* @uses \
|
1730 |
-
* @uses \
|
1731 |
-
* @uses \
|
1732 |
-
* @uses \pb_backupbuddy
|
1733 |
-
* @uses \
|
1734 |
-
* @uses \
|
1735 |
-
* @uses \pb_backupbuddy::$format::
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
if ( ( $backup['
|
1769 |
-
|
1770 |
-
}
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
$status .= '<
|
1783 |
-
|
1784 |
-
|
1785 |
-
$
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
$
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
__( '
|
1839 |
-
__( '
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
*
|
1847 |
-
*
|
1848 |
-
* @
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
$
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
*
|
1876 |
-
*
|
1877 |
-
* @
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
*
|
1901 |
-
*
|
1902 |
-
* @
|
1903 |
-
*
|
1904 |
-
* @uses \
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
|
1931 |
-
echo $line['
|
1932 |
-
echo $line['
|
1933 |
-
|
1934 |
-
echo $
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
|
1958 |
-
|
1959 |
-
*
|
1960 |
-
*
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
|
1967 |
-
|
1968 |
-
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
1973 |
-
|
1974 |
-
|
1975 |
-
*
|
1976 |
-
*
|
1977 |
-
* @
|
1978 |
-
*
|
1979 |
-
* @uses \
|
1980 |
-
* @uses \
|
1981 |
-
* @uses \
|
1982 |
-
* @uses \
|
1983 |
-
* @uses \
|
1984 |
-
* @uses \pb_backupbuddy::
|
1985 |
-
* @uses \pb_backupbuddy::
|
1986 |
-
* @uses \pb_backupbuddy::
|
1987 |
-
* @uses \pb_backupbuddy::
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
1996 |
-
\pb_backupbuddy::
|
1997 |
-
|
1998 |
-
|
1999 |
-
|
2000 |
-
|
2001 |
-
|
2002 |
-
|
2003 |
-
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
$
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
-
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
|
2030 |
-
echo '
|
2031 |
-
|
2032 |
-
|
2033 |
-
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
2037 |
-
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
|
2042 |
-
|
2043 |
-
|
2044 |
-
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
|
2049 |
-
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
2055 |
-
|
2056 |
-
|
2057 |
-
|
2058 |
-
|
2059 |
-
|
2060 |
-
|
2061 |
-
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
2065 |
-
|
2066 |
-
|
2067 |
-
|
2068 |
-
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
|
2107 |
-
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
2113 |
-
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
|
2118 |
-
|
2119 |
-
|
2120 |
-
|
2121 |
-
|
2122 |
-
|
2123 |
-
|
2124 |
-
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
|
2130 |
-
|
2131 |
-
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
|
2146 |
-
|
2147 |
-
|
2148 |
-
|
2149 |
-
|
2150 |
-
|
2151 |
-
|
2152 |
-
|
2153 |
-
|
2154 |
-
|
2155 |
-
|
2156 |
-
|
2157 |
-
|
2158 |
-
|
2159 |
-
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
|
2164 |
-
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
|
2169 |
-
|
2170 |
-
|
2171 |
-
|
2172 |
-
|
2173 |
-
|
2174 |
-
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
2178 |
-
|
2179 |
-
|
2180 |
-
|
2181 |
-
|
2182 |
-
|
2183 |
-
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
2190 |
-
|
2191 |
-
|
2192 |
-
|
2193 |
-
|
2194 |
-
|
2195 |
-
|
2196 |
-
|
2197 |
-
|
2198 |
-
$
|
2199 |
-
|
2200 |
-
|
2201 |
-
|
2202 |
-
|
2203 |
-
|
2204 |
-
echo '<
|
2205 |
-
|
2206 |
-
echo
|
2207 |
-
echo '
|
2208 |
-
echo '
|
2209 |
-
|
2210 |
-
|
2211 |
-
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
|
2216 |
-
|
2217 |
-
|
2218 |
-
|
2219 |
-
|
2220 |
-
|
2221 |
-
|
2222 |
-
|
2223 |
-
|
2224 |
-
|
2225 |
-
|
2226 |
-
|
2227 |
-
|
2228 |
-
|
2229 |
-
|
2230 |
-
|
2231 |
-
|
2232 |
-
|
2233 |
-
|
2234 |
-
*
|
2235 |
-
*
|
2236 |
-
* @uses \
|
2237 |
-
* @uses \
|
2238 |
-
* @uses \
|
2239 |
-
|
2240 |
-
|
2241 |
-
|
2242 |
-
|
2243 |
-
|
2244 |
-
|
2245 |
-
|
2246 |
-
|
2247 |
-
|
2248 |
-
|
2249 |
-
|
2250 |
-
|
2251 |
-
|
2252 |
-
|
2253 |
-
|
2254 |
-
|
2255 |
-
|
2256 |
-
|
2257 |
-
|
2258 |
-
|
2259 |
-
|
2260 |
-
|
2261 |
-
|
2262 |
-
|
2263 |
-
|
2264 |
-
|
2265 |
-
|
2266 |
-
|
2267 |
-
|
2268 |
-
|
2269 |
-
|
2270 |
-
|
2271 |
-
|
2272 |
-
|
2273 |
-
|
2274 |
-
|
2275 |
-
|
2276 |
-
|
2277 |
-
|
2278 |
-
|
2279 |
-
|
2280 |
-
|
2281 |
-
|
2282 |
-
|
2283 |
-
|
2284 |
-
|
2285 |
-
|
2286 |
-
|
2287 |
-
|
2288 |
-
|
2289 |
-
|
2290 |
-
|
2291 |
-
|
2292 |
-
|
2293 |
-
|
2294 |
-
|
2295 |
-
|
2296 |
-
|
2297 |
-
|
2298 |
-
|
2299 |
-
|
2300 |
-
|
2301 |
-
*
|
2302 |
-
*
|
2303 |
-
* @
|
2304 |
-
*
|
2305 |
-
* @uses \pb_backupbuddy
|
2306 |
-
* @uses \pb_backupbuddy_backup
|
2307 |
-
|
2308 |
-
|
2309 |
-
|
2310 |
-
|
2311 |
-
|
2312 |
-
|
2313 |
-
|
2314 |
-
|
2315 |
-
|
2316 |
-
|
2317 |
-
|
2318 |
-
|
2319 |
-
$
|
2320 |
-
|
2321 |
-
|
2322 |
-
|
2323 |
-
|
2324 |
-
|
2325 |
-
|
2326 |
-
|
2327 |
-
|
2328 |
-
|
2329 |
-
|
2330 |
-
|
2331 |
-
*
|
2332 |
-
*
|
2333 |
-
* @
|
2334 |
-
*
|
2335 |
-
|
2336 |
-
|
2337 |
-
|
2338 |
-
|
2339 |
-
|
2340 |
-
|
2341 |
-
|
2342 |
-
|
2343 |
-
|
2344 |
-
|
2345 |
-
|
2346 |
-
'',
|
2347 |
-
|
2348 |
-
isset( $data['
|
2349 |
-
|
2350 |
-
|
2351 |
-
|
2352 |
-
|
2353 |
-
|
2354 |
-
|
2355 |
-
|
2356 |
-
|
2357 |
-
|
2358 |
-
|
2359 |
-
|
2360 |
-
|
2361 |
-
|
2362 |
-
|
2363 |
-
|
2364 |
-
|
2365 |
-
*
|
2366 |
-
*
|
2367 |
-
*
|
2368 |
-
|
2369 |
-
|
2370 |
-
|
2371 |
-
|
2372 |
-
|
2373 |
-
|
2374 |
-
|
2375 |
-
|
2376 |
-
|
2377 |
-
|
2378 |
-
|
2379 |
-
|
2380 |
-
'
|
2381 |
-
|
2382 |
-
|
2383 |
-
|
2384 |
-
|
2385 |
-
|
2386 |
-
|
2387 |
-
|
2388 |
-
|
2389 |
-
|
2390 |
-
|
2391 |
-
|
2392 |
-
|
2393 |
-
|
2394 |
-
|
2395 |
-
|
2396 |
-
|
2397 |
-
|
2398 |
-
|
2399 |
-
|
2400 |
-
*
|
2401 |
-
*
|
2402 |
-
* @
|
2403 |
-
|
2404 |
-
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
-
|
2409 |
-
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
|
2415 |
-
|
2416 |
-
'
|
2417 |
-
|
2418 |
-
|
2419 |
-
|
2420 |
-
|
2421 |
-
|
2422 |
-
|
2423 |
-
|
2424 |
-
|
2425 |
-
|
2426 |
-
|
2427 |
-
|
2428 |
-
|
2429 |
-
|
2430 |
-
|
2431 |
-
|
2432 |
-
|
2433 |
-
|
2434 |
-
\pb_backupbuddy::$options['remote_destinations'][ $destination_id ] = $data;
|
2435 |
-
}
|
2436 |
-
|
2437 |
-
|
2438 |
-
|
2439 |
-
|
2440 |
-
|
2441 |
-
|
2442 |
-
|
2443 |
-
|
2444 |
-
|
2445 |
-
|
2446 |
-
|
2447 |
-
*
|
2448 |
-
*
|
2449 |
-
|
2450 |
-
|
2451 |
-
|
2452 |
-
|
2453 |
-
|
2454 |
-
|
2455 |
-
|
2456 |
-
|
2457 |
-
|
2458 |
-
|
2459 |
-
|
2460 |
-
|
2461 |
-
|
2462 |
-
|
2463 |
-
*
|
2464 |
-
*
|
2465 |
-
* @
|
2466 |
-
|
2467 |
-
|
2468 |
-
|
2469 |
-
|
2470 |
-
|
2471 |
-
|
2472 |
-
|
2473 |
-
|
2474 |
-
|
2475 |
-
|
2476 |
-
|
2477 |
-
|
2478 |
-
|
2479 |
-
|
2480 |
-
|
2481 |
-
|
2482 |
-
|
2483 |
-
|
2484 |
-
|
2485 |
-
|
2486 |
-
|
2487 |
-
*
|
2488 |
-
*
|
2489 |
-
* @
|
2490 |
-
*
|
2491 |
-
* @uses \
|
2492 |
-
* @uses \
|
2493 |
-
* @uses \
|
2494 |
-
* @uses \
|
2495 |
-
* @uses \pb_backupbuddy
|
2496 |
-
|
2497 |
-
|
2498 |
-
|
2499 |
-
|
2500 |
-
|
2501 |
-
|
2502 |
-
|
2503 |
-
|
2504 |
-
|
2505 |
-
|
2506 |
-
|
2507 |
-
|
2508 |
-
|
2509 |
-
|
2510 |
-
|
2511 |
-
|
2512 |
-
|
2513 |
-
|
2514 |
-
|
2515 |
-
|
2516 |
-
|
2517 |
-
|
2518 |
-
|
2519 |
-
|
2520 |
-
|
2521 |
-
|
2522 |
-
|
2523 |
-
$send_importbuddy =
|
2524 |
-
\pb_backupbuddy::status( 'details', 'Cron send to be scheduled
|
2525 |
-
}
|
2526 |
-
|
2527 |
-
|
2528 |
-
|
2529 |
-
|
2530 |
-
|
2531 |
-
$delete_after =
|
2532 |
-
\pb_backupbuddy::status( 'details', 'Remote send
|
2533 |
-
}
|
2534 |
-
|
2535 |
-
|
2536 |
-
|
2537 |
-
|
2538 |
-
|
2539 |
-
|
2540 |
-
|
2541 |
-
|
2542 |
-
|
2543 |
-
|
2544 |
-
|
2545 |
-
|
2546 |
-
|
2547 |
-
|
2548 |
-
|
2549 |
-
|
2550 |
-
|
2551 |
-
|
2552 |
-
|
2553 |
-
|
2554 |
-
|
2555 |
-
|
2556 |
-
|
2557 |
-
|
2558 |
-
|
2559 |
-
|
2560 |
-
|
2561 |
-
|
2562 |
-
|
2563 |
-
|
2564 |
-
|
2565 |
-
|
2566 |
-
|
2567 |
-
|
2568 |
-
|
2569 |
-
|
2570 |
-
|
2571 |
-
|
2572 |
-
|
2573 |
-
|
2574 |
-
|
2575 |
-
|
2576 |
-
|
2577 |
-
|
2578 |
-
\pb_backupbuddy::status( '
|
2579 |
-
|
2580 |
-
|
2581 |
-
|
2582 |
-
|
2583 |
-
|
2584 |
-
|
2585 |
-
|
2586 |
-
|
2587 |
-
|
2588 |
-
|
2589 |
-
|
2590 |
-
|
2591 |
-
*
|
2592 |
-
*
|
2593 |
-
* @
|
2594 |
-
|
2595 |
-
|
2596 |
-
|
2597 |
-
|
2598 |
-
|
2599 |
-
|
2600 |
-
|
2601 |
-
|
2602 |
-
|
2603 |
-
|
2604 |
-
|
2605 |
-
|
2606 |
-
|
2607 |
-
|
2608 |
-
|
2609 |
-
|
2610 |
-
|
2611 |
-
*
|
2612 |
-
*
|
2613 |
-
* @
|
2614 |
-
*
|
2615 |
-
* @uses \
|
2616 |
-
* @uses \
|
2617 |
-
* @uses \
|
2618 |
-
* @uses \
|
2619 |
-
* @uses \
|
2620 |
-
* @uses \
|
2621 |
-
* @uses \
|
2622 |
-
|
2623 |
-
|
2624 |
-
|
2625 |
-
|
2626 |
-
|
2627 |
-
|
2628 |
-
$
|
2629 |
-
|
2630 |
-
|
2631 |
-
|
2632 |
-
|
2633 |
-
|
2634 |
-
|
2635 |
-
|
2636 |
-
|
2637 |
-
|
2638 |
-
|
2639 |
-
|
2640 |
-
|
2641 |
-
|
2642 |
-
|
2643 |
-
|
2644 |
-
|
2645 |
-
|
2646 |
-
|
2647 |
-
if ( file_exists( $log_file ) ) {
|
2648 |
-
|
2649 |
-
}
|
2650 |
-
|
2651 |
-
|
2652 |
-
|
2653 |
-
|
2654 |
-
|
2655 |
-
|
2656 |
-
|
2657 |
-
|
2658 |
-
|
2659 |
-
|
2660 |
-
|
2661 |
-
|
2662 |
-
|
2663 |
-
|
2664 |
-
|
2665 |
-
$
|
2666 |
-
|
2667 |
-
|
2668 |
-
|
2669 |
-
|
2670 |
-
|
2671 |
-
|
2672 |
-
|
2673 |
-
|
2674 |
-
|
2675 |
-
|
2676 |
-
|
2677 |
-
|
2678 |
-
|
2679 |
-
|
2680 |
-
|
2681 |
-
|
2682 |
-
|
2683 |
-
|
2684 |
-
|
2685 |
-
|
2686 |
-
|
2687 |
-
|
2688 |
-
|
2689 |
-
|
2690 |
-
|
2691 |
-
|
2692 |
-
|
2693 |
-
|
2694 |
-
|
2695 |
-
|
2696 |
-
|
2697 |
-
|
2698 |
-
*
|
2699 |
-
*
|
2700 |
-
* @
|
2701 |
-
*
|
2702 |
-
* @uses \
|
2703 |
-
|
2704 |
-
|
2705 |
-
|
2706 |
-
|
2707 |
-
|
2708 |
-
|
2709 |
-
|
2710 |
-
|
2711 |
-
|
2712 |
-
|
2713 |
-
|
2714 |
-
|
2715 |
-
|
2716 |
-
$url =
|
2717 |
-
|
2718 |
-
|
2719 |
-
|
2720 |
-
|
2721 |
-
|
2722 |
-
|
2723 |
-
|
2724 |
-
|
2725 |
-
|
2726 |
-
|
2727 |
-
|
2728 |
-
|
2729 |
-
|
2730 |
-
|
2731 |
-
|
2732 |
-
|
2733 |
-
|
2734 |
-
|
2735 |
-
|
2736 |
-
|
2737 |
-
|
2738 |
-
|
2739 |
-
|
2740 |
-
|
2741 |
-
|
2742 |
-
|
2743 |
-
|
2744 |
-
|
2745 |
-
|
2746 |
-
|
2747 |
-
|
2748 |
-
|
2749 |
-
|
2750 |
-
|
2751 |
-
|
2752 |
-
|
2753 |
-
|
2754 |
-
|
2755 |
-
|
2756 |
-
|
2757 |
-
|
2758 |
-
|
2759 |
-
|
2760 |
-
|
2761 |
-
|
2762 |
-
|
2763 |
-
|
2764 |
-
|
2765 |
-
|
2766 |
-
'
|
2767 |
-
'
|
2768 |
-
'
|
2769 |
-
'
|
2770 |
-
'
|
2771 |
-
|
2772 |
-
|
2773 |
-
|
2774 |
-
|
2775 |
-
|
2776 |
-
|
2777 |
-
|
2778 |
-
$scan
|
2779 |
-
|
2780 |
-
}
|
2781 |
-
|
2782 |
-
|
2783 |
-
|
2784 |
-
|
2785 |
-
|
2786 |
-
|
2787 |
-
|
2788 |
-
|
2789 |
-
|
2790 |
-
|
2791 |
-
$scan
|
2792 |
-
|
2793 |
-
|
2794 |
-
|
2795 |
-
|
2796 |
-
|
2797 |
-
|
2798 |
-
|
2799 |
-
|
2800 |
-
|
2801 |
-
|
2802 |
-
*
|
2803 |
-
*
|
2804 |
-
|
2805 |
-
|
2806 |
-
|
2807 |
-
|
2808 |
-
|
2809 |
-
|
2810 |
-
|
2811 |
-
|
2812 |
-
|
2813 |
-
|
2814 |
-
|
2815 |
-
|
2816 |
-
|
2817 |
-
|
2818 |
-
|
2819 |
-
|
2820 |
-
|
2821 |
-
|
2822 |
-
|
2823 |
-
|
2824 |
-
|
2825 |
-
|
2826 |
-
|
2827 |
-
|
2828 |
-
|
2829 |
-
|
2830 |
-
|
2831 |
-
|
2832 |
-
|
2833 |
-
|
2834 |
-
|
2835 |
-
|
2836 |
-
|
2837 |
-
|
2838 |
-
|
2839 |
-
|
2840 |
-
|
2841 |
-
|
2842 |
-
|
2843 |
-
|
2844 |
-
echo
|
2845 |
-
\backupbuddy_core::addNotification( '
|
2846 |
-
}
|
2847 |
-
|
2848 |
-
|
2849 |
-
|
2850 |
-
|
2851 |
-
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
2855 |
-
|
2856 |
-
|
2857 |
-
|
2858 |
-
|
2859 |
-
|
2860 |
-
|
2861 |
-
|
2862 |
-
|
2863 |
-
|
2864 |
-
|
2865 |
-
|
2866 |
-
|
2867 |
-
|
2868 |
-
|
2869 |
-
|
2870 |
-
|
2871 |
-
|
2872 |
-
|
2873 |
-
|
2874 |
-
|
2875 |
-
|
2876 |
-
|
2877 |
-
|
2878 |
-
|
2879 |
-
|
2880 |
-
|
2881 |
-
|
2882 |
-
|
2883 |
-
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
|
2888 |
-
|
2889 |
-
|
2890 |
-
|
2891 |
-
|
2892 |
-
|
2893 |
-
|
2894 |
-
|
2895 |
-
|
2896 |
-
|
2897 |
-
|
2898 |
-
|
2899 |
-
|
2900 |
-
|
2901 |
-
|
2902 |
-
|
2903 |
-
|
2904 |
-
|
2905 |
-
|
2906 |
-
|
2907 |
-
|
2908 |
-
|
2909 |
-
|
2910 |
-
|
2911 |
-
|
2912 |
-
|
2913 |
-
|
2914 |
-
|
2915 |
-
|
2916 |
-
|
2917 |
-
|
2918 |
-
|
2919 |
-
|
2920 |
-
|
2921 |
-
|
2922 |
-
|
2923 |
-
|
2924 |
-
|
2925 |
-
|
2926 |
-
|
2927 |
-
|
2928 |
-
|
2929 |
-
|
2930 |
-
|
2931 |
-
|
2932 |
-
|
2933 |
-
|
2934 |
-
|
2935 |
-
|
2936 |
-
|
2937 |
-
|
2938 |
-
|
2939 |
-
|
2940 |
-
|
2941 |
-
|
2942 |
-
|
2943 |
-
|
2944 |
-
|
2945 |
-
|
2946 |
-
|
2947 |
-
|
2948 |
-
|
2949 |
-
|
2950 |
-
|
2951 |
-
|
2952 |
-
|
2953 |
-
|
2954 |
-
|
2955 |
-
|
2956 |
-
|
2957 |
-
|
2958 |
-
|
2959 |
-
|
2960 |
-
|
2961 |
-
|
2962 |
-
|
2963 |
-
|
2964 |
-
|
2965 |
-
|
2966 |
-
|
2967 |
-
|
2968 |
-
|
2969 |
-
|
2970 |
-
|
2971 |
-
|
2972 |
-
|
2973 |
-
|
2974 |
-
|
2975 |
-
|
2976 |
-
|
2977 |
-
|
2978 |
-
|
2979 |
-
|
2980 |
-
|
2981 |
-
|
2982 |
-
|
2983 |
-
|
2984 |
-
|
2985 |
-
|
2986 |
-
|
2987 |
-
|
2988 |
-
|
2989 |
-
|
2990 |
-
|
2991 |
-
|
2992 |
-
|
2993 |
-
|
2994 |
-
|
2995 |
-
|
2996 |
-
|
2997 |
-
|
2998 |
-
|
2999 |
-
|
3000 |
-
|
3001 |
-
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
|
3006 |
-
|
3007 |
-
|
3008 |
-
|
3009 |
-
|
3010 |
-
|
3011 |
-
|
3012 |
-
|
3013 |
-
|
3014 |
-
|
3015 |
-
|
3016 |
-
|
3017 |
-
|
3018 |
-
|
3019 |
-
|
3020 |
-
|
3021 |
-
|
3022 |
-
|
3023 |
-
|
3024 |
-
|
3025 |
-
|
3026 |
-
|
3027 |
-
|
3028 |
-
|
3029 |
-
|
3030 |
-
|
3031 |
-
|
3032 |
-
|
3033 |
-
|
3034 |
-
|
3035 |
-
|
3036 |
-
|
3037 |
-
|
3038 |
-
|
3039 |
-
*
|
3040 |
-
*
|
3041 |
-
* @
|
3042 |
-
*
|
3043 |
-
* @uses
|
3044 |
-
* @uses
|
3045 |
-
* @uses \
|
3046 |
-
* @uses \pb_backupbuddy
|
3047 |
-
* @uses \
|
3048 |
-
* @uses \
|
3049 |
-
* @uses \
|
3050 |
-
|
3051 |
-
|
3052 |
-
|
3053 |
-
|
3054 |
-
|
3055 |
-
|
3056 |
-
|
3057 |
-
|
3058 |
-
|
3059 |
-
'
|
3060 |
-
|
3061 |
-
|
3062 |
-
|
3063 |
-
|
3064 |
-
|
3065 |
-
|
3066 |
-
'
|
3067 |
-
|
3068 |
-
|
3069 |
-
|
3070 |
-
|
3071 |
-
|
3072 |
-
|
3073 |
-
|
3074 |
-
|
3075 |
-
|
3076 |
-
|
3077 |
-
|
3078 |
-
|
3079 |
-
|
3080 |
-
|
3081 |
-
|
3082 |
-
|
3083 |
-
|
3084 |
-
$
|
3085 |
-
|
3086 |
-
|
3087 |
-
|
3088 |
-
|
3089 |
-
|
3090 |
-
|
3091 |
-
|
3092 |
-
|
3093 |
-
|
3094 |
-
|
3095 |
-
|
3096 |
-
|
3097 |
-
|
3098 |
-
|
3099 |
-
|
3100 |
-
|
3101 |
-
|
3102 |
-
|
3103 |
-
|
3104 |
-
|
3105 |
-
|
3106 |
-
|
3107 |
-
|
3108 |
-
|
3109 |
-
|
3110 |
-
|
3111 |
-
|
3112 |
-
|
3113 |
-
|
3114 |
-
|
3115 |
-
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]
|
3116 |
-
|
3117 |
-
|
3118 |
-
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['
|
3119 |
-
|
3120 |
-
//
|
3121 |
-
|
3122 |
-
|
3123 |
-
|
3124 |
-
|
3125 |
-
|
3126 |
-
|
3127 |
-
|
3128 |
-
|
3129 |
-
|
3130 |
-
|
3131 |
-
|
3132 |
-
|
3133 |
-
|
3134 |
-
|
3135 |
-
|
3136 |
-
|
3137 |
-
|
3138 |
-
|
3139 |
-
|
3140 |
-
//
|
3141 |
-
|
3142 |
-
|
3143 |
-
|
3144 |
-
|
3145 |
-
|
3146 |
-
|
3147 |
-
|
3148 |
-
|
3149 |
-
\pb_backupbuddy::status( '
|
3150 |
-
|
3151 |
-
|
3152 |
-
|
3153 |
-
|
3154 |
-
|
3155 |
-
|
3156 |
-
|
3157 |
-
|
3158 |
-
|
3159 |
-
|
3160 |
-
|
3161 |
-
|
3162 |
-
|
3163 |
-
|
3164 |
-
|
3165 |
-
|
3166 |
-
|
3167 |
-
|
3168 |
-
|
3169 |
-
|
3170 |
-
|
3171 |
-
|
3172 |
-
*
|
3173 |
-
*
|
3174 |
-
* @
|
3175 |
-
*
|
3176 |
-
* @uses \
|
3177 |
-
* @uses \
|
3178 |
-
* @uses \
|
3179 |
-
|
3180 |
-
|
3181 |
-
|
3182 |
-
|
3183 |
-
|
3184 |
-
|
3185 |
-
|
3186 |
-
|
3187 |
-
|
3188 |
-
|
3189 |
-
|
3190 |
-
|
3191 |
-
$
|
3192 |
-
|
3193 |
-
|
3194 |
-
|
3195 |
-
|
3196 |
-
|
3197 |
-
|
3198 |
-
$destination_settings['itxapi_username']
|
3199 |
-
$destination_settings['itxapi_token']
|
3200 |
-
|
3201 |
-
|
3202 |
-
|
3203 |
-
|
3204 |
-
|
3205 |
-
|
3206 |
-
|
3207 |
-
|
3208 |
-
|
3209 |
-
\
|
3210 |
-
|
3211 |
-
|
3212 |
-
|
3213 |
-
|
3214 |
-
|
3215 |
-
|
3216 |
-
|
3217 |
-
|
3218 |
-
|
3219 |
-
|
3220 |
-
|
3221 |
-
*
|
3222 |
-
*
|
3223 |
-
* @
|
3224 |
-
*
|
3225 |
-
|
3226 |
-
|
3227 |
-
|
3228 |
-
|
3229 |
-
|
3230 |
-
$
|
3231 |
-
|
3232 |
-
|
3233 |
-
|
3234 |
-
|
3235 |
-
|
3236 |
-
// Clear
|
3237 |
-
|
3238 |
-
|
3239 |
-
|
3240 |
-
|
3241 |
-
|
3242 |
-
|
3243 |
-
|
3244 |
-
|
3245 |
-
|
3246 |
-
|
3247 |
-
|
3248 |
-
|
3249 |
-
|
3250 |
-
|
3251 |
-
|
3252 |
-
|
3253 |
-
|
3254 |
-
|
3255 |
-
|
3256 |
-
|
3257 |
-
|
3258 |
-
*
|
3259 |
-
*
|
3260 |
-
* @
|
3261 |
-
*
|
3262 |
-
* @uses \
|
3263 |
-
* @uses \
|
3264 |
-
* @uses \
|
3265 |
-
* @uses \
|
3266 |
-
* @uses \
|
3267 |
-
* @uses \
|
3268 |
-
|
3269 |
-
|
3270 |
-
|
3271 |
-
|
3272 |
-
|
3273 |
-
|
3274 |
-
|
3275 |
-
$
|
3276 |
-
|
3277 |
-
|
3278 |
-
$
|
3279 |
-
|
3280 |
-
|
3281 |
-
|
3282 |
-
|
3283 |
-
|
3284 |
-
|
3285 |
-
|
3286 |
-
|
3287 |
-
|
3288 |
-
|
3289 |
-
|
3290 |
-
|
3291 |
-
|
3292 |
-
|
3293 |
-
|
3294 |
-
|
3295 |
-
|
3296 |
-
|
3297 |
-
$
|
3298 |
-
$
|
3299 |
-
|
3300 |
-
|
3301 |
-
$
|
3302 |
-
|
3303 |
-
|
3304 |
-
|
3305 |
-
|
3306 |
-
|
3307 |
-
|
3308 |
-
|
3309 |
-
|
3310 |
-
$
|
3311 |
-
|
3312 |
-
|
3313 |
-
$
|
3314 |
-
|
3315 |
-
|
3316 |
-
$
|
3317 |
-
|
3318 |
-
|
3319 |
-
|
3320 |
-
|
3321 |
-
$
|
3322 |
-
|
3323 |
-
$
|
3324 |
-
|
3325 |
-
|
3326 |
-
|
3327 |
-
|
3328 |
-
|
3329 |
-
|
3330 |
-
|
3331 |
-
|
3332 |
-
|
3333 |
-
|
3334 |
-
|
3335 |
-
|
3336 |
-
|
3337 |
-
|
3338 |
-
|
3339 |
-
|
3340 |
-
|
3341 |
-
|
3342 |
-
*
|
3343 |
-
*
|
3344 |
-
* @
|
3345 |
-
*
|
3346 |
-
* @uses \
|
3347 |
-
|
3348 |
-
|
3349 |
-
|
3350 |
-
|
3351 |
-
|
3352 |
-
|
3353 |
-
|
3354 |
-
|
3355 |
-
|
3356 |
-
|
3357 |
-
|
3358 |
-
|
3359 |
-
|
3360 |
-
|
3361 |
-
|
3362 |
-
|
3363 |
-
*
|
3364 |
-
*
|
3365 |
-
* @
|
3366 |
-
*
|
3367 |
-
* @uses \
|
3368 |
-
* @uses \pb_backupbuddy::$
|
3369 |
-
* @uses \
|
3370 |
-
* @uses \
|
3371 |
-
* @uses \pb_backupbuddy::$format::
|
3372 |
-
* @uses \
|
3373 |
-
* @uses \
|
3374 |
-
* @uses \
|
3375 |
-
* @uses \backupbuddy_core::
|
3376 |
-
|
3377 |
-
|
3378 |
-
|
3379 |
-
|
3380 |
-
|
3381 |
-
|
3382 |
-
|
3383 |
-
|
3384 |
-
|
3385 |
-
|
3386 |
-
|
3387 |
-
|
3388 |
-
|
3389 |
-
$
|
3390 |
-
|
3391 |
-
|
3392 |
-
|
3393 |
-
|
3394 |
-
|
3395 |
-
|
3396 |
-
$
|
3397 |
-
|
3398 |
-
|
3399 |
-
|
3400 |
-
|
3401 |
-
|
3402 |
-
|
3403 |
-
|
3404 |
-
|
3405 |
-
|
3406 |
-
|
3407 |
-
|
3408 |
-
|
3409 |
-
|
3410 |
-
|
3411 |
-
|
3412 |
-
|
3413 |
-
|
3414 |
-
|
3415 |
-
|
3416 |
-
|
3417 |
-
|
3418 |
-
|
3419 |
-
|
3420 |
-
|
3421 |
-
|
3422 |
-
|
3423 |
-
|
3424 |
-
|
3425 |
-
|
3426 |
-
\
|
3427 |
-
|
3428 |
-
|
3429 |
-
|
3430 |
-
|
3431 |
-
|
3432 |
-
|
3433 |
-
|
3434 |
-
|
3435 |
-
|
3436 |
-
|
3437 |
-
|
3438 |
-
|
3439 |
-
|
3440 |
-
|
3441 |
-
|
3442 |
-
|
3443 |
-
|
3444 |
-
|
3445 |
-
|
3446 |
-
|
3447 |
-
|
3448 |
-
|
3449 |
-
|
3450 |
-
|
3451 |
-
|
3452 |
-
*
|
3453 |
-
*
|
3454 |
-
* @
|
3455 |
-
*
|
3456 |
-
* @uses \
|
3457 |
-
* @uses \
|
3458 |
-
*
|
3459 |
-
|
3460 |
-
|
3461 |
-
|
3462 |
-
|
3463 |
-
|
3464 |
-
|
3465 |
-
//
|
3466 |
-
|
3467 |
-
|
3468 |
-
|
3469 |
-
|
3470 |
-
|
3471 |
-
|
3472 |
-
|
3473 |
-
|
3474 |
-
|
3475 |
-
\
|
3476 |
-
|
3477 |
-
|
3478 |
-
|
3479 |
-
|
3480 |
-
|
3481 |
-
|
3482 |
-
|
3483 |
-
|
3484 |
-
|
3485 |
-
|
3486 |
-
|
3487 |
-
*
|
3488 |
-
*
|
3489 |
-
* @
|
3490 |
-
*
|
3491 |
-
* @uses \
|
3492 |
-
* @uses \
|
3493 |
-
|
3494 |
-
|
3495 |
-
|
3496 |
-
|
3497 |
-
|
3498 |
-
|
3499 |
-
|
3500 |
-
|
3501 |
-
|
3502 |
-
|
3503 |
-
|
3504 |
-
|
3505 |
-
|
3506 |
-
|
3507 |
-
|
3508 |
-
$
|
3509 |
-
|
3510 |
-
|
3511 |
-
|
3512 |
-
|
3513 |
-
$file
|
3514 |
-
|
3515 |
-
|
3516 |
-
|
3517 |
-
|
3518 |
-
|
3519 |
-
|
3520 |
-
|
3521 |
-
|
3522 |
-
|
3523 |
-
|
3524 |
-
|
3525 |
-
|
3526 |
-
|
3527 |
-
|
3528 |
-
|
3529 |
-
|
3530 |
-
|
3531 |
-
|
3532 |
-
|
3533 |
-
|
3534 |
-
|
3535 |
-
|
3536 |
-
|
3537 |
-
*
|
3538 |
-
*
|
3539 |
-
* @
|
3540 |
-
*
|
3541 |
-
* @uses \
|
3542 |
-
* @uses \
|
3543 |
-
* @uses \
|
3544 |
-
* @uses \
|
3545 |
-
|
3546 |
-
|
3547 |
-
|
3548 |
-
|
3549 |
-
|
3550 |
-
|
3551 |
-
|
3552 |
-
|
3553 |
-
|
3554 |
-
|
3555 |
-
|
3556 |
-
|
3557 |
-
|
3558 |
-
|
3559 |
-
|
3560 |
-
|
3561 |
-
|
3562 |
-
|
3563 |
-
|
3564 |
-
|
3565 |
-
|
3566 |
-
|
3567 |
-
|
3568 |
-
|
3569 |
-
|
3570 |
-
|
3571 |
-
|
3572 |
-
|
3573 |
-
|
3574 |
-
|
3575 |
-
|
3576 |
-
if (
|
3577 |
-
|
3578 |
-
|
3579 |
-
|
3580 |
-
|
3581 |
-
|
3582 |
-
|
3583 |
-
|
3584 |
-
|
3585 |
-
|
3586 |
-
|
3587 |
-
|
3588 |
-
\pb_backupbuddy::status( '
|
3589 |
-
|
3590 |
-
|
3591 |
-
|
3592 |
-
|
3593 |
-
|
3594 |
-
|
3595 |
-
|
3596 |
-
|
3597 |
-
|
3598 |
-
|
3599 |
-
|
3600 |
-
|
3601 |
-
|
3602 |
-
|
3603 |
-
|
3604 |
-
|
3605 |
-
|
3606 |
-
|
3607 |
-
|
3608 |
-
|
3609 |
-
|
3610 |
-
|
3611 |
-
|
3612 |
-
|
3613 |
-
|
3614 |
-
|
3615 |
-
|
3616 |
-
|
3617 |
-
|
3618 |
-
*
|
3619 |
-
*
|
3620 |
-
* @
|
3621 |
-
|
3622 |
-
|
3623 |
-
|
3624 |
-
|
3625 |
-
|
3626 |
-
|
3627 |
-
|
3628 |
-
|
3629 |
-
|
3630 |
-
|
3631 |
-
require_once $GLOBALS['ithemes_updater_path'] . '/
|
3632 |
-
|
3633 |
-
|
3634 |
-
|
3635 |
-
|
3636 |
-
|
3637 |
-
|
3638 |
-
|
3639 |
-
|
3640 |
-
|
3641 |
-
|
3642 |
-
|
3643 |
-
|
3644 |
-
|
3645 |
-
|
3646 |
-
|
3647 |
-
|
3648 |
-
|
3649 |
-
|
3650 |
-
|
3651 |
-
|
3652 |
-
*
|
3653 |
-
*
|
3654 |
-
* @
|
3655 |
-
*
|
3656 |
-
|
3657 |
-
|
3658 |
-
|
3659 |
-
|
3660 |
-
|
3661 |
-
|
3662 |
-
|
3663 |
-
$
|
3664 |
-
|
3665 |
-
|
3666 |
-
|
3667 |
-
|
3668 |
-
|
3669 |
-
|
3670 |
-
require_once $GLOBALS['ithemes_updater_path'] . '/
|
3671 |
-
|
3672 |
-
|
3673 |
-
|
3674 |
-
|
3675 |
-
|
3676 |
-
|
3677 |
-
|
3678 |
-
|
3679 |
-
|
3680 |
-
|
3681 |
-
|
3682 |
-
|
3683 |
-
|
3684 |
-
|
3685 |
-
|
3686 |
-
|
3687 |
-
|
3688 |
-
|
3689 |
-
$
|
3690 |
-
|
3691 |
-
|
3692 |
-
|
3693 |
-
|
3694 |
-
|
3695 |
-
|
3696 |
-
|
3697 |
-
|
3698 |
-
|
3699 |
-
|
3700 |
-
|
3701 |
-
|
3702 |
-
|
3703 |
-
|
3704 |
-
|
3705 |
-
|
3706 |
-
|
3707 |
-
|
3708 |
-
|
3709 |
-
|
3710 |
-
|
3711 |
-
|
3712 |
-
|
3713 |
-
|
3714 |
-
|
3715 |
-
|
3716 |
-
|
3717 |
-
$
|
3718 |
-
|
3719 |
-
|
3720 |
-
|
3721 |
-
|
3722 |
-
|
3723 |
-
|
3724 |
-
$
|
3725 |
-
|
3726 |
-
|
3727 |
-
|
3728 |
-
|
3729 |
-
|
3730 |
-
|
3731 |
-
|
3732 |
-
|
3733 |
-
|
3734 |
-
*
|
3735 |
-
*
|
3736 |
-
*
|
3737 |
-
*
|
3738 |
-
* @
|
3739 |
-
*
|
3740 |
-
|
3741 |
-
|
3742 |
-
|
3743 |
-
|
3744 |
-
|
3745 |
-
|
3746 |
-
|
3747 |
-
$
|
3748 |
-
|
3749 |
-
|
3750 |
-
|
3751 |
-
|
3752 |
-
|
3753 |
-
|
3754 |
-
|
3755 |
-
require_once $GLOBALS['ithemes_updater_path'] . '/
|
3756 |
-
|
3757 |
-
|
3758 |
-
|
3759 |
-
|
3760 |
-
|
3761 |
-
|
3762 |
-
|
3763 |
-
|
3764 |
-
|
3765 |
-
|
3766 |
-
|
3767 |
-
|
3768 |
-
|
3769 |
-
|
3770 |
-
|
3771 |
-
|
3772 |
-
|
3773 |
-
|
3774 |
-
$
|
3775 |
-
|
3776 |
-
|
3777 |
-
|
3778 |
-
|
3779 |
-
|
3780 |
-
|
3781 |
-
|
3782 |
-
|
3783 |
-
|
3784 |
-
|
3785 |
-
|
3786 |
-
|
3787 |
-
|
3788 |
-
|
3789 |
-
|
3790 |
-
|
3791 |
-
|
3792 |
-
|
3793 |
-
|
3794 |
-
|
3795 |
-
|
3796 |
-
|
3797 |
-
|
3798 |
-
|
3799 |
-
|
3800 |
-
|
3801 |
-
$
|
3802 |
-
|
3803 |
-
|
3804 |
-
|
3805 |
-
|
3806 |
-
|
3807 |
-
|
3808 |
-
|
3809 |
-
|
3810 |
-
|
3811 |
-
|
3812 |
-
*
|
3813 |
-
*
|
3814 |
-
*
|
3815 |
-
*
|
3816 |
-
*
|
3817 |
-
*
|
3818 |
-
|
3819 |
-
|
3820 |
-
|
3821 |
-
|
3822 |
-
|
3823 |
-
|
3824 |
-
|
3825 |
-
|
3826 |
-
|
3827 |
-
|
3828 |
-
case '
|
3829 |
-
|
3830 |
-
|
3831 |
-
|
3832 |
-
case '
|
3833 |
-
$message =
|
3834 |
-
break;
|
3835 |
-
case '
|
3836 |
-
$message = sprintf( __( '
|
3837 |
-
break;
|
3838 |
-
case '
|
3839 |
-
$message = sprintf( __( '%1$s could not be licensed
|
3840 |
-
break;
|
3841 |
-
|
3842 |
-
|
3843 |
-
|
3844 |
-
|
3845 |
-
|
3846 |
-
|
3847 |
-
|
3848 |
-
|
3849 |
-
|
3850 |
-
|
3851 |
-
|
3852 |
-
|
3853 |
-
|
3854 |
-
|
3855 |
-
|
3856 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Backup Buddy
|
4 |
+
*
|
5 |
+
* The code is used for the MainWP Buddy Extension.
|
6 |
+
*
|
7 |
+
* Credits
|
8 |
+
*
|
9 |
+
* Plugin-Name: BackupBuddy
|
10 |
+
* Plugin URI: http://ithemes.com/purchase/backupbuddy/
|
11 |
+
* Author: iThemes
|
12 |
+
* Author URI: http://ithemes.com/
|
13 |
+
* iThemes Package: backupbuddy
|
14 |
+
*
|
15 |
+
* The code is used for the MainWP Buddy Extension
|
16 |
+
* Extension URL: https://mainwp.com/extension/mainwpbuddy/
|
17 |
+
*
|
18 |
+
* @package MainWP\Child
|
19 |
+
*/
|
20 |
+
|
21 |
+
namespace MainWP\Child;
|
22 |
+
|
23 |
+
// phpcs:disable -- third party credit.
|
24 |
+
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Class MainWP_Child_Back_Up_Buddy
|
28 |
+
*/
|
29 |
+
class MainWP_Child_Back_Up_Buddy {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Public static variable to hold the single instance of MainWP_Child_Back_Up_Buddy.
|
33 |
+
* @var null
|
34 |
+
*/
|
35 |
+
public static $instance = null;
|
36 |
+
|
37 |
+
/** @var string $plugin_translate Plugin translation string. */
|
38 |
+
public $plugin_translate = 'mainwp-child';
|
39 |
+
|
40 |
+
/** @var bool $is_backupbuddy_installed Whether or not BackupBuddy is installed. Default: False. */
|
41 |
+
public $is_backupbuddy_installed = false;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_Back_Up_Buddy.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_Back_Up_Buddy|null
|
47 |
+
*/
|
48 |
+
public static function instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
+
}
|
52 |
+
return self::$instance;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* MainWP_Child_Back_Up_Buddy constructor.
|
57 |
+
*
|
58 |
+
* Run any time class is called.
|
59 |
+
*/
|
60 |
+
public function __construct() {
|
61 |
+
// To fix bug run dashboard on local machine.
|
62 |
+
if ( class_exists( '\pb_backupbuddy' ) ) {
|
63 |
+
$this->is_backupbuddy_installed = true;
|
64 |
+
}
|
65 |
+
|
66 |
+
if ( ! $this->is_backupbuddy_installed ) {
|
67 |
+
return;
|
68 |
+
}
|
69 |
+
|
70 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
71 |
+
|
72 |
+
add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) );
|
73 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
74 |
+
|
75 |
+
if ( get_option( 'mainwp_backupbuddy_hide_plugin' ) === 'hide' ) {
|
76 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
77 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
78 |
+
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
79 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Hide Backupbuddy update notice.
|
85 |
+
*
|
86 |
+
* @param string $slugs plugin slug.
|
87 |
+
* @return string $slugs Return slugs array.
|
88 |
+
*/
|
89 |
+
public function hide_update_notice( $slugs ) {
|
90 |
+
$slugs[] = 'backupbuddy/backupbuddy.php';
|
91 |
+
return $slugs;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Remove update nag.
|
96 |
+
*
|
97 |
+
* @param array $value Plugin slug array.
|
98 |
+
* @return array $value Plugin slug array.
|
99 |
+
*
|
100 |
+
* @uses \MainWP\Child\MainWP_Helper::is_updates_screen()
|
101 |
+
*/
|
102 |
+
public function remove_update_nag( $value ) {
|
103 |
+
if ( isset( $_POST['mainwpsignature'] ) ) {
|
104 |
+
return $value;
|
105 |
+
}
|
106 |
+
|
107 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
108 |
+
return $value;
|
109 |
+
}
|
110 |
+
|
111 |
+
if ( isset( $value->response['backupbuddy/backupbuddy.php'] ) ) {
|
112 |
+
unset( $value->response['backupbuddy/backupbuddy.php'] );
|
113 |
+
}
|
114 |
+
|
115 |
+
return $value;
|
116 |
+
}
|
117 |
+
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Remove Backup buddy from plugins list.
|
121 |
+
*
|
122 |
+
* @param array $plugins All plugins array.
|
123 |
+
* @return array $plugins All plugins array with backupbuddy removed.
|
124 |
+
*/
|
125 |
+
public function all_plugins( $plugins ) {
|
126 |
+
foreach ( $plugins as $key => $value ) {
|
127 |
+
$plugin_slug = basename( $key, '.php' );
|
128 |
+
if ( 'backupbuddy' === $plugin_slug ) {
|
129 |
+
unset( $plugins[ $key ] );
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
return $plugins;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Remove backupbuddy from admin menu.
|
138 |
+
*/
|
139 |
+
public function admin_menu() {
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Submenu array.
|
143 |
+
*
|
144 |
+
* @global object
|
145 |
+
*/
|
146 |
+
global $submenu;
|
147 |
+
|
148 |
+
remove_menu_page( 'pb_backupbuddy_backup' );
|
149 |
+
|
150 |
+
if ( isset( $_SERVER['REQUEST_URI'] ) && false !== stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=pb_backupbuddy_' ) ) {
|
151 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
152 |
+
exit();
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Backupbuddy Client Reports log.
|
159 |
+
*
|
160 |
+
* @uses MainWP_Child_Back_Up_Buddy::do_reports_log()
|
161 |
+
*/
|
162 |
+
public function do_site_stats() {
|
163 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
164 |
+
do_action( 'mainwp_child_reports_log', 'backupbuddy' );
|
165 |
+
} else {
|
166 |
+
$this->do_reports_log( 'backupbuddy' );
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Create BackupBuddy Client Reports log.
|
172 |
+
*
|
173 |
+
* @param string $ext Extension to create log for.
|
174 |
+
*
|
175 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::is_backupbuddy_installed()
|
176 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
177 |
+
* @uses \MainWP\Child\MainWP_Helper::check_properties()
|
178 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
179 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
180 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
181 |
+
* @uses \pb_backupbuddy_fileoptions()
|
182 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
183 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
184 |
+
* @uses \backupbuddy_live_periodic::get_stats()
|
185 |
+
* @uses \Exception
|
186 |
+
*/
|
187 |
+
public function do_reports_log( $ext = '' ) {
|
188 |
+
if ( 'backupbuddy' !== $ext ) {
|
189 |
+
return;
|
190 |
+
}
|
191 |
+
|
192 |
+
if ( ! $this->is_backupbuddy_installed ) {
|
193 |
+
return;
|
194 |
+
}
|
195 |
+
|
196 |
+
try {
|
197 |
+
|
198 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', array( 'plugin_path' ) );
|
199 |
+
|
200 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
201 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/core.php' ) ) {
|
202 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/core.php';
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ) ) {
|
207 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
208 |
+
}
|
209 |
+
|
210 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_core', '\pb_backupbuddy_fileoptions' ) );
|
211 |
+
MainWP_Helper::check_methods( '\backupbuddy_core', 'getLogDirectory' );
|
212 |
+
|
213 |
+
$pretty_type = array(
|
214 |
+
'full' => 'Full',
|
215 |
+
'db' => 'Database',
|
216 |
+
'files' => 'Files',
|
217 |
+
);
|
218 |
+
|
219 |
+
$recentBackups_list = glob( \backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' );
|
220 |
+
|
221 |
+
foreach ( $recentBackups_list as $backup_fileoptions ) {
|
222 |
+
|
223 |
+
$backup = new \pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
224 |
+
$result = $backup->is_ok();
|
225 |
+
if ( method_exists( $backup, 'is_ok' ) && true !== $result ) {
|
226 |
+
continue;
|
227 |
+
}
|
228 |
+
|
229 |
+
$backup = &$backup->options;
|
230 |
+
|
231 |
+
if ( ! isset( $backup['serial'] ) || ( '' == $backup['serial'] ) ) {
|
232 |
+
continue;
|
233 |
+
}
|
234 |
+
|
235 |
+
$check_finished = false;
|
236 |
+
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
237 |
+
$check_finished = true;
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( ! $check_finished ) {
|
241 |
+
continue;
|
242 |
+
}
|
243 |
+
|
244 |
+
$backupType = '';
|
245 |
+
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
246 |
+
if ( true === MainWP_Helper::check_properties( '\pb_backupbuddy', 'format', true ) ) {
|
247 |
+
if ( true === MainWP_Helper::check_methods( \pb_backupbuddy::$format, array( 'prettify' ), true ) ) {
|
248 |
+
$backupType = \pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type );
|
249 |
+
}
|
250 |
+
}
|
251 |
+
} else {
|
252 |
+
if ( true === MainWP_Helper::check_methods( '\backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true ) ) {
|
253 |
+
$backupType = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( '' == $backupType ) {
|
258 |
+
$backupType = 'Unknown';
|
259 |
+
}
|
260 |
+
|
261 |
+
$finish_time = $backup['finish_time'];
|
262 |
+
$message = 'BackupBuddy ' . $backupType . ' finished';
|
263 |
+
if ( ! empty( $finish_time ) ) {
|
264 |
+
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ) ) {
|
269 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
270 |
+
|
271 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_live_periodic' ) );
|
272 |
+
MainWP_Helper::check_methods( '\backupbuddy_live_periodic', 'get_stats' );
|
273 |
+
|
274 |
+
$state = \backupbuddy_live_periodic::get_stats();
|
275 |
+
if ( is_array( $state ) && isset( $state['stats'] ) ) {
|
276 |
+
|
277 |
+
if ( is_array( $state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] ) ) {
|
278 |
+
if ( isset( $state['stats']['last_remote_snapshot_response'] ) ) {
|
279 |
+
$resp = $state['stats']['last_remote_snapshot_response'];
|
280 |
+
if ( isset( $resp['success'] ) && $resp['success'] ) {
|
281 |
+
$finish_time = $state['stats']['last_remote_snapshot'];
|
282 |
+
$backupType = 'Live Backup to cloud';
|
283 |
+
$message = 'BackupBuddy ' . $backupType . ' finished';
|
284 |
+
if ( ! empty( $finish_time ) ) {
|
285 |
+
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
+
} catch ( \Exception $e ) {
|
293 |
+
// ok!
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* MainWP Child BackupBuddy actions.
|
299 |
+
*
|
300 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
301 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::is_backupbuddy_installed()
|
302 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::set_showhide()
|
303 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::save_settings()
|
304 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::reset_defaults()
|
305 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::get_notifications()
|
306 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::schedules_list()
|
307 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::run_scheduled_backup()
|
308 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::save_scheduled_backup()
|
309 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::delete_scheduled_backup()
|
310 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::save_profile()
|
311 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::delete_profile()
|
312 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::delete_backup()
|
313 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::backup_list()
|
314 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::save_note()
|
315 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::get_hash()
|
316 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::zip_viewer()
|
317 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::exclude_tree()
|
318 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::restore_file_view()
|
319 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::restore_file_restore()
|
320 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::view_log()
|
321 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::view_detail()
|
322 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::reset_integrity()
|
323 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::download_archive()
|
324 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::create_backup()
|
325 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::start_backup()
|
326 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::backup_status()
|
327 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::stop_backup()
|
328 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::remote_save()
|
329 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::remote_delete()
|
330 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::remote_send()
|
331 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::remote_list()
|
332 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::get_main_log()
|
333 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::settings_other()
|
334 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::malware_scan()
|
335 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::live_setup()
|
336 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::live_save_settings()
|
337 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::live_action_disconnect()
|
338 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::live_action()
|
339 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::download_troubleshooting()
|
340 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::get_live_backups()
|
341 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::copy_file_to_local()
|
342 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::delete_file_backup()
|
343 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::get_live_stats()
|
344 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::load_products_license()
|
345 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::save_license_settings()
|
346 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::activate_package()
|
347 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::deactivate_package()
|
348 |
+
*/
|
349 |
+
public function action() {
|
350 |
+
$information = array();
|
351 |
+
if ( ! $this->is_backupbuddy_installed ) {
|
352 |
+
MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) );
|
353 |
+
}
|
354 |
+
|
355 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
356 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/core.php';
|
357 |
+
}
|
358 |
+
|
359 |
+
if ( ! isset( \pb_backupbuddy::$options ) ) {
|
360 |
+
\pb_backupbuddy::load();
|
361 |
+
}
|
362 |
+
|
363 |
+
$mwp_action = isset( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
364 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
365 |
+
switch ( $mwp_action ) {
|
366 |
+
case 'set_showhide':
|
367 |
+
$information = $this->set_showhide();
|
368 |
+
break;
|
369 |
+
case 'save_settings':
|
370 |
+
$information = $this->save_settings();
|
371 |
+
break;
|
372 |
+
case 'reset_defaults':
|
373 |
+
$information = $this->reset_defaults();
|
374 |
+
break;
|
375 |
+
case 'get_notifications':
|
376 |
+
$information = $this->get_notifications();
|
377 |
+
break;
|
378 |
+
case 'schedules_list':
|
379 |
+
$information = $this->schedules_list();
|
380 |
+
break;
|
381 |
+
case 'run_scheduled_backup':
|
382 |
+
$information = $this->run_scheduled_backup();
|
383 |
+
break;
|
384 |
+
case 'save_scheduled_backup':
|
385 |
+
$information = $this->save_scheduled_backup();
|
386 |
+
break;
|
387 |
+
case 'delete_scheduled_backup':
|
388 |
+
$information = $this->delete_scheduled_backup();
|
389 |
+
break;
|
390 |
+
case 'save_profile':
|
391 |
+
$information = $this->save_profile();
|
392 |
+
break;
|
393 |
+
case 'delete_profile':
|
394 |
+
$information = $this->delete_profile();
|
395 |
+
break;
|
396 |
+
case 'delete_backup':
|
397 |
+
$information = $this->delete_backup();
|
398 |
+
break;
|
399 |
+
case 'backup_list':
|
400 |
+
$information = $this->backup_list();
|
401 |
+
break;
|
402 |
+
case 'save_note':
|
403 |
+
$information = $this->save_note();
|
404 |
+
break;
|
405 |
+
case 'get_hash':
|
406 |
+
$information = $this->get_hash();
|
407 |
+
break;
|
408 |
+
case 'zip_viewer':
|
409 |
+
$information = $this->zip_viewer();
|
410 |
+
break;
|
411 |
+
case 'exclude_tree':
|
412 |
+
$information = $this->exclude_tree();
|
413 |
+
break;
|
414 |
+
case 'restore_file_view':
|
415 |
+
$information = $this->restore_file_view();
|
416 |
+
break;
|
417 |
+
case 'restore_file_restore':
|
418 |
+
$information = $this->restore_file_restore();
|
419 |
+
break;
|
420 |
+
case 'view_log':
|
421 |
+
$information = $this->view_log();
|
422 |
+
break;
|
423 |
+
case 'view_detail':
|
424 |
+
$information = $this->view_detail();
|
425 |
+
break;
|
426 |
+
case 'reset_integrity':
|
427 |
+
$information = $this->reset_integrity();
|
428 |
+
break;
|
429 |
+
case 'download_archive':
|
430 |
+
$information = $this->download_archive();
|
431 |
+
break;
|
432 |
+
case 'create_backup':
|
433 |
+
$information = $this->create_backup();
|
434 |
+
break;
|
435 |
+
case 'start_backup':
|
436 |
+
$information = $this->start_backup();
|
437 |
+
break;
|
438 |
+
case 'backup_status':
|
439 |
+
$information = $this->backup_status();
|
440 |
+
break;
|
441 |
+
case 'stop_backup':
|
442 |
+
$information = $this->stop_backup();
|
443 |
+
break;
|
444 |
+
case 'remote_save':
|
445 |
+
$information = $this->remote_save();
|
446 |
+
break;
|
447 |
+
case 'remote_delete':
|
448 |
+
$information = $this->remote_delete();
|
449 |
+
break;
|
450 |
+
case 'remote_send':
|
451 |
+
$information = $this->remote_send();
|
452 |
+
break;
|
453 |
+
case 'remote_list':
|
454 |
+
$information = $this->remote_list();
|
455 |
+
break;
|
456 |
+
case 'get_main_log':
|
457 |
+
$information = $this->get_main_log();
|
458 |
+
break;
|
459 |
+
case 'settings_other':
|
460 |
+
$information = $this->settings_other();
|
461 |
+
break;
|
462 |
+
case 'malware_scan':
|
463 |
+
$information = $this->malware_scan();
|
464 |
+
break;
|
465 |
+
case 'live_setup':
|
466 |
+
$information = $this->live_setup();
|
467 |
+
break;
|
468 |
+
case 'live_save_settings':
|
469 |
+
$information = $this->live_save_settings();
|
470 |
+
break;
|
471 |
+
case 'live_action_disconnect':
|
472 |
+
$information = $this->live_action_disconnect();
|
473 |
+
break;
|
474 |
+
case 'live_action':
|
475 |
+
$information = $this->live_action();
|
476 |
+
break;
|
477 |
+
case 'download_troubleshooting':
|
478 |
+
$information = $this->download_troubleshooting();
|
479 |
+
break;
|
480 |
+
case 'get_live_backups':
|
481 |
+
$information = $this->get_live_backups();
|
482 |
+
break;
|
483 |
+
case 'copy_file_to_local':
|
484 |
+
$information = $this->copy_file_to_local();
|
485 |
+
break;
|
486 |
+
case 'delete_file_backup':
|
487 |
+
$information = $this->delete_file_backup();
|
488 |
+
break;
|
489 |
+
case 'get_live_stats':
|
490 |
+
$information = $this->get_live_stats();
|
491 |
+
break;
|
492 |
+
case 'load_products_license':
|
493 |
+
$information = $this->load_products_license();
|
494 |
+
break;
|
495 |
+
case 'save_license_settings':
|
496 |
+
$information = $this->save_license_settings();
|
497 |
+
break;
|
498 |
+
case 'activate_package':
|
499 |
+
$information = $this->activate_package();
|
500 |
+
break;
|
501 |
+
case 'deactivate_package':
|
502 |
+
$information = $this->deactivate_package();
|
503 |
+
break;
|
504 |
+
}
|
505 |
+
}
|
506 |
+
MainWP_Helper::write( $information );
|
507 |
+
}
|
508 |
+
|
509 |
+
/**
|
510 |
+
* Set show or hide BackupBuddy Plugin from Admin & plugins list.
|
511 |
+
*
|
512 |
+
* @return array $information Return results.
|
513 |
+
*
|
514 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
515 |
+
*/
|
516 |
+
public function set_showhide() {
|
517 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
518 |
+
MainWP_Helper::update_option( 'mainwp_backupbuddy_hide_plugin', $hide );
|
519 |
+
$information['result'] = 'SUCCESS';
|
520 |
+
return $information;
|
521 |
+
}
|
522 |
+
|
523 |
+
/**
|
524 |
+
* Save BackupBuddy settings.
|
525 |
+
*
|
526 |
+
* @return array $out Return response array.
|
527 |
+
*
|
528 |
+
* @uses \pb_backupbuddy::$options()
|
529 |
+
* @uses \backupbuddy_core::_getBackupDirectoryDefault()
|
530 |
+
*/
|
531 |
+
public function save_settings() {
|
532 |
+
|
533 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
534 |
+
|
535 |
+
if ( 'general_settings' !== $type && 'advanced_settings' !== $type && 'all' !== $type ) {
|
536 |
+
return array( 'error' => __( 'Invalid data. Please check and try again.' ) );
|
537 |
+
}
|
538 |
+
|
539 |
+
$filter_advanced_settings = array(
|
540 |
+
'backup_reminders',
|
541 |
+
'archive_name_format',
|
542 |
+
'archive_name_profile',
|
543 |
+
'lock_archives_directory',
|
544 |
+
'include_importbuddy',
|
545 |
+
'default_backup_tab',
|
546 |
+
'disable_localization',
|
547 |
+
'limit_single_cron_per_pass',
|
548 |
+
'use_internal_cron',
|
549 |
+
'cron_request_timeout_override',
|
550 |
+
'remote_send_timeout_retries',
|
551 |
+
'hide_live',
|
552 |
+
'hide_dashboard_widget',
|
553 |
+
'set_greedy_execution_time',
|
554 |
+
'archive_limit_size_big',
|
555 |
+
'max_execution_time',
|
556 |
+
'log_level',
|
557 |
+
'save_backup_sum_log',
|
558 |
+
'max_site_log_size',
|
559 |
+
'max_send_stats_days',
|
560 |
+
'max_send_stats_count',
|
561 |
+
'max_notifications_age_days',
|
562 |
+
'backup_mode',
|
563 |
+
'delete_archives_pre_backup',
|
564 |
+
'disable_https_local_ssl_verify',
|
565 |
+
'prevent_flush',
|
566 |
+
'save_comment_meta',
|
567 |
+
'integrity_check',
|
568 |
+
'backup_cron_rescheduling',
|
569 |
+
'skip_spawn_cron_call',
|
570 |
+
'backup_cron_passed_force_time',
|
571 |
+
'php_runtime_test_minimum_interval',
|
572 |
+
'php_memory_test_minimum_interval',
|
573 |
+
'database_method_strategy',
|
574 |
+
'skip_database_dump',
|
575 |
+
'breakout_tables',
|
576 |
+
'force_single_db_file',
|
577 |
+
'phpmysqldump_maxrows',
|
578 |
+
'ignore_command_length_check',
|
579 |
+
'compression',
|
580 |
+
'zip_method_strategy',
|
581 |
+
'alternative_zip_2',
|
582 |
+
'zip_build_strategy',
|
583 |
+
'zip_step_period',
|
584 |
+
'zip_burst_gap',
|
585 |
+
'zip_min_burst_content',
|
586 |
+
'zip_max_burst_content',
|
587 |
+
'disable_zipmethod_caching',
|
588 |
+
'ignore_zip_warnings',
|
589 |
+
'ignore_zip_symlinks',
|
590 |
+
);
|
591 |
+
|
592 |
+
$filter_general_settings = array(
|
593 |
+
'importbuddy_pass_hash',
|
594 |
+
'importbuddy_pass_length',
|
595 |
+
'backup_directory',
|
596 |
+
'role_access',
|
597 |
+
'archive_limit_age',
|
598 |
+
'archive_limit_full',
|
599 |
+
'archive_limit',
|
600 |
+
'archive_limit_size',
|
601 |
+
'archive_limit_db',
|
602 |
+
'archive_limit_files',
|
603 |
+
'title_multisite',
|
604 |
+
'multisite_export',
|
605 |
+
'backup_nonwp_tables',
|
606 |
+
'mysqldump_additional_includes',
|
607 |
+
'mysqldump_additional_excludes',
|
608 |
+
'excludes',
|
609 |
+
'email_notify_scheduled_start',
|
610 |
+
'email_notify_scheduled_start_subject',
|
611 |
+
'email_notify_scheduled_start_body',
|
612 |
+
'email_notify_scheduled_complete',
|
613 |
+
'email_notify_scheduled_complete_subject',
|
614 |
+
'email_notify_scheduled_complete_body',
|
615 |
+
'email_notify_send_finish',
|
616 |
+
'email_notify_send_finish_subject',
|
617 |
+
'email_notify_send_finish_body',
|
618 |
+
'no_new_backups_error_days',
|
619 |
+
'email_notify_error',
|
620 |
+
'email_notify_error_subject',
|
621 |
+
'email_notify_error_body',
|
622 |
+
'email_return',
|
623 |
+
);
|
624 |
+
|
625 |
+
$filter_profile0_values = array(
|
626 |
+
'mysqldump_additional_includes',
|
627 |
+
'mysqldump_additional_excludes',
|
628 |
+
'excludes',
|
629 |
+
'integrity_check',
|
630 |
+
'skip_database_dump',
|
631 |
+
'backup_nonwp_tables',
|
632 |
+
);
|
633 |
+
|
634 |
+
$settings = unserialize( base64_decode( wp_unslash( $_POST['options'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
635 |
+
|
636 |
+
$save_settings = array();
|
637 |
+
|
638 |
+
if ( is_array( $settings ) ) {
|
639 |
+
if ( 'all' === $type || 'general_settings' === $type ) {
|
640 |
+
foreach ( $filter_general_settings as $field ) {
|
641 |
+
if ( isset( $settings[ $field ] ) ) {
|
642 |
+
$save_settings[ $field ] = $settings[ $field ];
|
643 |
+
}
|
644 |
+
}
|
645 |
+
}
|
646 |
+
|
647 |
+
if ( 'all' === $type || 'advanced_settings' === $type ) {
|
648 |
+
foreach ( $filter_advanced_settings as $field ) {
|
649 |
+
if ( isset( $settings[ $field ] ) ) {
|
650 |
+
$save_settings[ $field ] = $settings[ $field ];
|
651 |
+
}
|
652 |
+
}
|
653 |
+
}
|
654 |
+
}
|
655 |
+
|
656 |
+
if ( ! empty( $save_settings ) ) {
|
657 |
+
$newOptions = \pb_backupbuddy::$options;
|
658 |
+
|
659 |
+
foreach ( $newOptions as $key => $val ) {
|
660 |
+
if ( isset( $save_settings[ $key ] ) ) {
|
661 |
+
$newOptions[ $key ] = $save_settings[ $key ];
|
662 |
+
}
|
663 |
+
}
|
664 |
+
|
665 |
+
if ( isset( $newOptions['profiles'] ) && isset( $newOptions['profiles'][0] ) ) {
|
666 |
+
foreach ( $filter_profile0_values as $field ) {
|
667 |
+
if ( isset( $settings[ $field ] ) ) {
|
668 |
+
$newOptions['profiles'][0][ $field ] = $settings[ $field ];
|
669 |
+
}
|
670 |
+
}
|
671 |
+
}
|
672 |
+
|
673 |
+
if ( 'general_settings' === $type || 'all' === $type ) {
|
674 |
+
$newOptions['importbuddy_pass_hash_confirm'] = '';
|
675 |
+
}
|
676 |
+
|
677 |
+
/** @global object $wpdb WordPres Database object. */
|
678 |
+
global $wpdb;
|
679 |
+
|
680 |
+
$option = 'pb_' . \pb_backupbuddy::settings( 'slug' );
|
681 |
+
$newOptions = sanitize_option( $option, $newOptions );
|
682 |
+
$newOptions = maybe_serialize( $newOptions ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- third party credit.
|
683 |
+
|
684 |
+
add_site_option( $option, $newOptions, '', 'no' ); // 'No' prevents autoload if we wont always need the data loaded.
|
685 |
+
$wpdb->update( $wpdb->options, array( 'option_value' => $newOptions ), array( 'option_name' => $option ) );
|
686 |
+
|
687 |
+
$information['backupDirectoryDefault'] = \backupbuddy_core::_getBackupDirectoryDefault();
|
688 |
+
$information['result'] = 'SUCCESS';
|
689 |
+
}
|
690 |
+
|
691 |
+
return $information;
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Reset BackupBuddy defaults.
|
696 |
+
*
|
697 |
+
* @return array $information Return success message & result.
|
698 |
+
*
|
699 |
+
* @uses \pb_backupbuddy::$options
|
700 |
+
* @uses \pb_backupbuddy::settings()
|
701 |
+
* @uses \pb_backupbuddy::save()
|
702 |
+
* @uses \backupbuddy_core::verify_directories()
|
703 |
+
* @uses \backupbuddy_core::addNotification()
|
704 |
+
*/
|
705 |
+
public function reset_defaults() {
|
706 |
+
|
707 |
+
// Keep log serial.
|
708 |
+
$old_log_serial = \pb_backupbuddy::$options['log_serial'];
|
709 |
+
|
710 |
+
$keepDestNote = '';
|
711 |
+
$remote_destinations = \pb_backupbuddy::$options['remote_destinations'];
|
712 |
+
\pb_backupbuddy::$options = \pb_backupbuddy::settings( 'default_options' );
|
713 |
+
if ( '1' == $_POST['keep_destinations'] ) {
|
714 |
+
\pb_backupbuddy::$options['remote_destinations'] = $remote_destinations;
|
715 |
+
$keepDestNote = ' ' . __( 'Remote destination settings were not reset.', 'mainwp-child' );
|
716 |
+
}
|
717 |
+
|
718 |
+
// Replace log serial.
|
719 |
+
\pb_backupbuddy::$options['log_serial'] = $old_log_serial;
|
720 |
+
|
721 |
+
\pb_backupbuddy::save();
|
722 |
+
$skipTempGeneration = true;
|
723 |
+
\backupbuddy_core::verify_directories( $skipTempGeneration ); // Re-verify directories such as backup dir, temp, etc.
|
724 |
+
$resetNote = __( 'Plugin settings have been reset to defaults.', 'mainwp-child' );
|
725 |
+
\backupbuddy_core::addNotification( 'settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote );
|
726 |
+
|
727 |
+
$information['message'] = $resetNote . $keepDestNote;
|
728 |
+
$information['result'] = 'SUCCESS';
|
729 |
+
return $information;
|
730 |
+
}
|
731 |
+
|
732 |
+
/**
|
733 |
+
* Get BackupBuddy core success notifications.
|
734 |
+
*
|
735 |
+
* @return array Return BackupBuddy SUCCESS notifications.
|
736 |
+
*
|
737 |
+
* @uses \backupbuddy_core::getNotifications()
|
738 |
+
*/
|
739 |
+
public function get_notifications() {
|
740 |
+
return array(
|
741 |
+
'result' => 'SUCCESS',
|
742 |
+
'notifications' => \backupbuddy_core::getNotifications(),
|
743 |
+
);
|
744 |
+
}
|
745 |
+
|
746 |
+
/**
|
747 |
+
* Get schedules run time.
|
748 |
+
*
|
749 |
+
* @return array Return $schedules_run_time.
|
750 |
+
*
|
751 |
+
* @uses \pb_backupbuddy::$options
|
752 |
+
* @uses \pb_backupbuddy::$format::date()
|
753 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
754 |
+
*/
|
755 |
+
public function get_schedules_run_time() {
|
756 |
+
$schedules_run_time = array();
|
757 |
+
foreach ( \pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) {
|
758 |
+
// Determine first run.
|
759 |
+
$first_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $schedule['first_run'] ) );
|
760 |
+
// Determine last run.
|
761 |
+
if ( isset( $schedule['last_run'] ) ) { // backward compatibility before last run tracking added. Pre v2.2.11. Eventually remove this.
|
762 |
+
if ( 0 == $schedule['last_run'] ) {
|
763 |
+
$last_run = '<i>' . __( 'Never', 'mainwp-child' ) . '</i>';
|
764 |
+
} else {
|
765 |
+
$last_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $schedule['last_run'] ) );
|
766 |
+
}
|
767 |
+
} else { // backward compatibility for before last run tracking was added.
|
768 |
+
$last_run = '<i> ' . __( 'Unknown', 'mainwp-child' ) . '</i>';
|
769 |
+
}
|
770 |
+
|
771 |
+
// Determine next run.
|
772 |
+
$next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
773 |
+
if ( false === $next_run ) {
|
774 |
+
$next_run = '<font color=red>Error: Cron event not found</font>';
|
775 |
+
} else {
|
776 |
+
$next_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $next_run ) );
|
777 |
+
}
|
778 |
+
|
779 |
+
$run_time = 'First run: ' . $first_run . '<br>' .
|
780 |
+
'Last run: ' . $last_run . '<br>' .
|
781 |
+
'Next run: ' . $next_run;
|
782 |
+
|
783 |
+
$schedules_run_time[ $schedule_id ] = $run_time;
|
784 |
+
|
785 |
+
}
|
786 |
+
|
787 |
+
return $schedules_run_time;
|
788 |
+
}
|
789 |
+
|
790 |
+
/**
|
791 |
+
* List schedules.
|
792 |
+
*
|
793 |
+
* @return array $information Return results array.
|
794 |
+
*
|
795 |
+
* @uses \pb_backupbuddy::$options
|
796 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_schedules_run_time()
|
797 |
+
*/
|
798 |
+
public function schedules_list() {
|
799 |
+
$information = array();
|
800 |
+
$information['schedules'] = \pb_backupbuddy::$options['schedules'];
|
801 |
+
$information['next_schedule_index'] = \pb_backupbuddy::$options['next_schedule_index'];
|
802 |
+
$information['schedules_run_time'] = $this->get_schedules_run_time();
|
803 |
+
|
804 |
+
// to fix missing destination notice.
|
805 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'] ) ) {
|
806 |
+
$information['remote_destinations'] = \pb_backupbuddy::$options['remote_destinations'];
|
807 |
+
}
|
808 |
+
|
809 |
+
$information['result'] = 'SUCCESS';
|
810 |
+
return $information;
|
811 |
+
}
|
812 |
+
|
813 |
+
|
814 |
+
/**
|
815 |
+
* Run scheduled backup.
|
816 |
+
*
|
817 |
+
* @return array $information Return results array.
|
818 |
+
*
|
819 |
+
* @uses \pb_backupbuddy::$options
|
820 |
+
* @uses \pb_backupbuddy::alert()
|
821 |
+
* @uses \pb_backupbuddy_cron::_run_scheduled_backup()
|
822 |
+
*/
|
823 |
+
public function run_scheduled_backup() {
|
824 |
+
if ( ! is_main_site() ) { // Only run for main site or standalone. Multisite subsites do not allow schedules.
|
825 |
+
return array( 'error' => __( 'Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child' ) );
|
826 |
+
}
|
827 |
+
|
828 |
+
$schedule_id = (int) $_POST['schedule_id'];
|
829 |
+
|
830 |
+
if ( ! isset( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) || ! is_array( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) ) {
|
831 |
+
return array( 'error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' ) );
|
832 |
+
}
|
833 |
+
|
834 |
+
\pb_backupbuddy::alert( 'Manually running scheduled backup "' . \pb_backupbuddy::$options['schedules'][ $schedule_id ]['title'] . '" in the background.<br>' . __( 'Note: If there is no site activity there may be delays between steps in the backup. Access the site or use a 3rd party service, such as a free pinging service, to generate site activity.', 'mainwp-child' ) );
|
835 |
+
\pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id );
|
836 |
+
|
837 |
+
$information['result'] = 'SUCCESS';
|
838 |
+
|
839 |
+
return $information;
|
840 |
+
}
|
841 |
+
|
842 |
+
|
843 |
+
/**
|
844 |
+
* Save scheduled backup.
|
845 |
+
*
|
846 |
+
* @return array|string[] $information Return results array.
|
847 |
+
*
|
848 |
+
* @uses \pb_backupbuddy::$options
|
849 |
+
* @uses \backupbuddy_core::schedule_event()
|
850 |
+
* @uses \backupbuddy_core::unschedule_event()
|
851 |
+
* @uses \pb_backupbuddy::save()
|
852 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_schedules_run_time()
|
853 |
+
*/
|
854 |
+
public function save_scheduled_backup() {
|
855 |
+
$schedule_id = intval( $_POST['schedule_id'] );
|
856 |
+
$schedule = unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
857 |
+
|
858 |
+
if ( ! is_array( $schedule ) ) {
|
859 |
+
return array( 'error' => __( 'Invalid schedule data', 'mainwp-child' ) );
|
860 |
+
}
|
861 |
+
$information = array();
|
862 |
+
|
863 |
+
if ( ! isset( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) ) {
|
864 |
+
$next_index = \pb_backupbuddy::$options['next_schedule_index'];
|
865 |
+
\pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below.
|
866 |
+
\pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule;
|
867 |
+
$result = \backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) );
|
868 |
+
if ( false === $result ) {
|
869 |
+
return array( 'error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.' );
|
870 |
+
}
|
871 |
+
} else {
|
872 |
+
$first_run = $schedule['first_run'];
|
873 |
+
$next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
874 |
+
\backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
875 |
+
\backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int) $schedule_id ) ); // Add new schedule.
|
876 |
+
\pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule;
|
877 |
+
}
|
878 |
+
\pb_backupbuddy::save();
|
879 |
+
$information['result'] = 'SUCCESS';
|
880 |
+
$information['schedules'] = \pb_backupbuddy::$options['schedules'];
|
881 |
+
$information['next_schedule_index'] = \pb_backupbuddy::$options['next_schedule_index'];
|
882 |
+
$information['schedules_run_time'] = $this->get_schedules_run_time();
|
883 |
+
return $information;
|
884 |
+
}
|
885 |
+
|
886 |
+
|
887 |
+
/**
|
888 |
+
* Save profile.
|
889 |
+
*
|
890 |
+
* @return array $information Return response array.
|
891 |
+
*
|
892 |
+
* @uses \pb_backupbuddy::$options
|
893 |
+
* @uses \pb_backupbuddy::save()
|
894 |
+
*/
|
895 |
+
public function save_profile() {
|
896 |
+
$profile_id = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
897 |
+
$profile = unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
898 |
+
|
899 |
+
if ( ! is_array( $profile ) ) {
|
900 |
+
return array( 'error' => __( 'Invalid profile data', 'mainwp-child' ) );
|
901 |
+
}
|
902 |
+
|
903 |
+
\pb_backupbuddy::$options['profiles'][ $profile_id ] = $profile;
|
904 |
+
\pb_backupbuddy::save();
|
905 |
+
|
906 |
+
$information['result'] = 'SUCCESS';
|
907 |
+
return $information;
|
908 |
+
}
|
909 |
+
|
910 |
+
|
911 |
+
/**
|
912 |
+
* Delete profile.
|
913 |
+
*
|
914 |
+
* @return array $information Return results array.
|
915 |
+
*
|
916 |
+
* @uses \pb_backupbuddy::$options
|
917 |
+
* @uses \pb_backupbuddy::save()
|
918 |
+
*/
|
919 |
+
public function delete_profile() {
|
920 |
+
$profile_id = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
921 |
+
|
922 |
+
if ( isset( \pb_backupbuddy::$options['profiles'][ $profile_id ] ) ) {
|
923 |
+
unset( \pb_backupbuddy::$options['profiles'][ $profile_id ] );
|
924 |
+
}
|
925 |
+
|
926 |
+
\pb_backupbuddy::save();
|
927 |
+
$information['result'] = 'SUCCESS';
|
928 |
+
return $information;
|
929 |
+
}
|
930 |
+
|
931 |
+
/**
|
932 |
+
* Delete backup.
|
933 |
+
*
|
934 |
+
* @param string $type Type of backup.
|
935 |
+
* @param bool $subsite_mode Whether or not the backup is for a subsite. Default: false.
|
936 |
+
*
|
937 |
+
* @return array $information Return results array.
|
938 |
+
*
|
939 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
940 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
941 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
942 |
+
* @uses \backupbuddy_core::getLogDirectory::re::get_serial_from_file()
|
943 |
+
* @uses \pb_backupbuddy::save()
|
944 |
+
*/
|
945 |
+
public function delete_backup( $type = 'default', $subsite_mode = false ) {
|
946 |
+
$item_ids = isset( $_POST['item_ids'] ) ? explode( ',', wp_unslash( $_POST['item_ids'] ) ) : array();
|
947 |
+
$information = array();
|
948 |
+
if ( is_array( $item_ids ) && count( $item_ids ) > 0 ) {
|
949 |
+
$needs_save = false;
|
950 |
+
$deleted_files = array();
|
951 |
+
foreach ( $item_ids as $item ) {
|
952 |
+
if ( file_exists( \backupbuddy_core::getBackupDirectory() . $item ) ) {
|
953 |
+
if ( unlink( \backupbuddy_core::getBackupDirectory() . $item ) === true ) {
|
954 |
+
$deleted_files[] = $item;
|
955 |
+
|
956 |
+
// Cleanup any related fileoptions files.
|
957 |
+
$serial = \backupbuddy_core::get_serial_from_file( $item );
|
958 |
+
|
959 |
+
$backup_files = glob( \backupbuddy_core::getBackupDirectory() . '*.zip' );
|
960 |
+
if ( ! is_array( $backup_files ) ) {
|
961 |
+
$backup_files = array();
|
962 |
+
}
|
963 |
+
if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats.
|
964 |
+
$this_serial = \backupbuddy_core::get_serial_from_file( $item );
|
965 |
+
$fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt';
|
966 |
+
if ( file_exists( $fileoptions_file ) ) {
|
967 |
+
unlink( $fileoptions_file );
|
968 |
+
}
|
969 |
+
if ( file_exists( $fileoptions_file . '.lock' ) ) {
|
970 |
+
unlink( $fileoptions_file . '.lock' );
|
971 |
+
}
|
972 |
+
$needs_save = true;
|
973 |
+
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
}
|
977 |
+
if ( true === $needs_save ) {
|
978 |
+
\pb_backupbuddy::save();
|
979 |
+
}
|
980 |
+
|
981 |
+
$information['result'] = 'SUCCESS';
|
982 |
+
|
983 |
+
}
|
984 |
+
return $information;
|
985 |
+
}
|
986 |
+
|
987 |
+
/**
|
988 |
+
* Sync other data from $data[] and merge with $information[]
|
989 |
+
*
|
990 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
991 |
+
* @param array $data Other data to sync to $information array.
|
992 |
+
*
|
993 |
+
* @return array $information Returned information array with both sets of data.
|
994 |
+
*/
|
995 |
+
public function sync_others_data( $information, $data = array() ) {
|
996 |
+
if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) {
|
997 |
+
try {
|
998 |
+
$information['syncBackupBuddy'] = $this->get_sync_data();
|
999 |
+
} catch ( \Exception $e ) {
|
1000 |
+
// ok!
|
1001 |
+
}
|
1002 |
+
}
|
1003 |
+
return $information;
|
1004 |
+
}
|
1005 |
+
|
1006 |
+
/**
|
1007 |
+
* Get sync data.
|
1008 |
+
*
|
1009 |
+
* @return array|bool $out Return Updraft data array or FALSE on failure.
|
1010 |
+
* @throws Exception Error message.
|
1011 |
+
*
|
1012 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
1013 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1014 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1015 |
+
* @uses \backupbuddy_core::get_plugins_root()
|
1016 |
+
* @uses \backupbuddy_core::get_themes_root()
|
1017 |
+
* @uses \backupbuddy_core::get_media_root()
|
1018 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::pb_additional_tables()
|
1019 |
+
* @uses \MainWP\Child\MainWP_Utility::update_lasttime_backup()
|
1020 |
+
*/
|
1021 |
+
public function get_sync_data() {
|
1022 |
+
try {
|
1023 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
1024 |
+
MainWP_Helper::check_classes_exists( '\pb_backupbuddy' );
|
1025 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', array( 'plugin_path' ) );
|
1026 |
+
|
1027 |
+
$plugin_path = \pb_backupbuddy::plugin_path();
|
1028 |
+
if ( file_exists( $plugin_path . '/classes/core.php' ) ) {
|
1029 |
+
require_once $plugin_path . '/classes/core.php';
|
1030 |
+
}
|
1031 |
+
}
|
1032 |
+
|
1033 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_core', '\backupbuddy_api' ) );
|
1034 |
+
MainWP_Helper::check_methods( '\backupbuddy_core', array( 'get_plugins_root', 'get_themes_root', 'get_media_root' ) );
|
1035 |
+
MainWP_Helper::check_methods( '\backupbuddy_api', array( 'getOverview' ) );
|
1036 |
+
|
1037 |
+
$data = array();
|
1038 |
+
$data['plugins_root'] = \backupbuddy_core::get_plugins_root();
|
1039 |
+
$data['themes_root'] = \backupbuddy_core::get_themes_root();
|
1040 |
+
$data['media_root'] = \backupbuddy_core::get_media_root();
|
1041 |
+
$data['additional_tables'] = $this->pb_additional_tables();
|
1042 |
+
$data['abspath'] = ABSPATH;
|
1043 |
+
|
1044 |
+
$getOverview = \backupbuddy_api::getOverview();
|
1045 |
+
$data['editsSinceLastBackup'] = $getOverview['editsSinceLastBackup'];
|
1046 |
+
|
1047 |
+
if ( isset( $getOverview['lastBackupStats']['finish'] ) ) {
|
1048 |
+
$finish_time = $getOverview['lastBackupStats']['finish'];
|
1049 |
+
$time = $this->localize_time( $finish_time );
|
1050 |
+
$data['lastBackupStats'] = date( 'M j - g:i A', $time ); // phpcs:ignore -- local time.
|
1051 |
+
$data['lasttime_backup'] = $finish_time;
|
1052 |
+
MainWP_Utility::update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature.
|
1053 |
+
} else {
|
1054 |
+
$data['lastBackupStats'] = 'Unknown';
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
return $data;
|
1058 |
+
} catch ( \Exception $e ) {
|
1059 |
+
// not exit here!
|
1060 |
+
}
|
1061 |
+
|
1062 |
+
return false;
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
/**
|
1066 |
+
* Localize time.
|
1067 |
+
*
|
1068 |
+
* @param float $timestamp Time to localize.
|
1069 |
+
*
|
1070 |
+
* @return float|int Return localized timestamp.
|
1071 |
+
*/
|
1072 |
+
public function localize_time($timestamp ) {
|
1073 |
+
if ( function_exists( 'get_option' ) ) {
|
1074 |
+
$gmt_offset = get_option( 'gmt_offset' );
|
1075 |
+
} else {
|
1076 |
+
$gmt_offset = 0;
|
1077 |
+
}
|
1078 |
+
return $timestamp + ( $gmt_offset * 3600 );
|
1079 |
+
}
|
1080 |
+
|
1081 |
+
/**
|
1082 |
+
* Backup list.
|
1083 |
+
*
|
1084 |
+
* @return array $information Return results array.
|
1085 |
+
*
|
1086 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1087 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_backup_list()
|
1088 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_recent_backup_list()
|
1089 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1090 |
+
*/
|
1091 |
+
public function backup_list() {
|
1092 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
1093 |
+
$information = array();
|
1094 |
+
$information['backup_list'] = $this->get_backup_list();
|
1095 |
+
$information['recent_backup_list'] = $this->get_recent_backup_list();
|
1096 |
+
$backup_directory = \backupbuddy_core::getBackupDirectory();
|
1097 |
+
$backup_directory = str_replace( '\\', '/', $backup_directory );
|
1098 |
+
$backup_directory = rtrim( $backup_directory, '/\\' ) . '/';
|
1099 |
+
$information['backupDirectoryWithinSiteRoot'] = ( false !== stristr( $backup_directory, ABSPATH ) ) ? 'yes' : 'no';
|
1100 |
+
$information['result'] = 'SUCCESS';
|
1101 |
+
return $information;
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
/**
|
1105 |
+
* Save note.
|
1106 |
+
*
|
1107 |
+
* @return array $information Return results array.
|
1108 |
+
*
|
1109 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1110 |
+
* @uses \pb_backupbuddy::$classes
|
1111 |
+
* @uses \pb_backupbuddy::$classes::get_comment()
|
1112 |
+
* @uses \pb_backupbuddy::status()
|
1113 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1114 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1115 |
+
* @uses \pb_backupbuddy_fileoptions::save()
|
1116 |
+
* @uses \pb_backupbuddy::$classes::set_comment()
|
1117 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1118 |
+
* @uses \backupbuddy_core::normalize_comment_data()
|
1119 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1120 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1121 |
+
*/
|
1122 |
+
public function save_note() {
|
1123 |
+
if ( ! isset( \pb_backupbuddy::$classes['zipbuddy'] ) ) {
|
1124 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1125 |
+
\pb_backupbuddy::$classes['zipbuddy'] = new \pluginbuddy_zipbuddy( \backupbuddy_core::getBackupDirectory() );
|
1126 |
+
}
|
1127 |
+
$backup_file = isset( $_POST['backup_file'] ) ? wp_unslash( $_POST['backup_file'] ) : '';
|
1128 |
+
$note = isset( $_POST['backup_file'] ) ? wp_unslash( $_POST['note'] ) : '';
|
1129 |
+
$note = preg_replace( '/[[:space:]]+/', ' ', $note );
|
1130 |
+
$note = preg_replace( '/[^[:print:]]/', '', $note );
|
1131 |
+
$note = substr( $note, 0, 200 );
|
1132 |
+
|
1133 |
+
// Returns true on success, else the error message.
|
1134 |
+
$old_comment = \pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_file );
|
1135 |
+
$comment = \backupbuddy_core::normalize_comment_data( $old_comment );
|
1136 |
+
$comment['note'] = $note;
|
1137 |
+
|
1138 |
+
$comment_result = \pb_backupbuddy::$classes['zipbuddy']->set_comment( $backup_file, $comment );
|
1139 |
+
|
1140 |
+
$information = array();
|
1141 |
+
if ( true === $comment_result ) {
|
1142 |
+
$information['result'] = 'SUCCESS';
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
// Even if we cannot save the note into the archive file, store it in internal settings.
|
1146 |
+
$serial = \backupbuddy_core::get_serial_from_file( $backup_file );
|
1147 |
+
|
1148 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1149 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #24.' );
|
1150 |
+
$backup_options = new \pb_backupbuddy_fileoptions( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' );
|
1151 |
+
$result = $backup_options->is_ok();
|
1152 |
+
if ( true === $result ) {
|
1153 |
+
$backup_options->options['integrity']['comment'] = $note;
|
1154 |
+
$backup_options->save();
|
1155 |
+
}
|
1156 |
+
return $information;
|
1157 |
+
}
|
1158 |
+
|
1159 |
+
/**
|
1160 |
+
* Get hash.
|
1161 |
+
*
|
1162 |
+
* @return array|string[] Return results array.
|
1163 |
+
*
|
1164 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1165 |
+
*/
|
1166 |
+
public function get_hash() {
|
1167 |
+
$callback_data = isset( $_POST['callback_data'] ) ? wp_unslash( $_POST['callback_data'] ) : '';
|
1168 |
+
$file = \backupbuddy_core::getBackupDirectory() . $callback_data;
|
1169 |
+
if ( file_exists( $file ) ) {
|
1170 |
+
return array(
|
1171 |
+
'result' => 'SUCCESS',
|
1172 |
+
'hash' => md5_file( $file ),
|
1173 |
+
);
|
1174 |
+
} else {
|
1175 |
+
return array( 'error' => 'Not found the file' );
|
1176 |
+
}
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
/**
|
1180 |
+
* Zip viewer.
|
1181 |
+
*
|
1182 |
+
* @return array|string[] Return results array.
|
1183 |
+
*
|
1184 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1185 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1186 |
+
* @uses \pb_backupbuddy::status()
|
1187 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1188 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1189 |
+
* @uses \pb_backupbuddy_fileoptions::save()
|
1190 |
+
* @uses \pb_backupbuddy::$classes
|
1191 |
+
* @uses \pb_backupbuddy::$classes::get_file_list()
|
1192 |
+
* @uses \pluginbuddy_zipbuddy()
|
1193 |
+
*/
|
1194 |
+
public function zip_viewer() {
|
1195 |
+
|
1196 |
+
// How long to cache the specific backup file tree information for (seconds).
|
1197 |
+
$max_cache_time = 86400;
|
1198 |
+
|
1199 |
+
// This is the root directory we want the listing for.
|
1200 |
+
$root = isset( $_POST['dir'] ) ? wp_unslash( $_POST['dir'] ) : '';
|
1201 |
+
$root_len = strlen( $root );
|
1202 |
+
|
1203 |
+
// This will identify the backup zip file we want to list.
|
1204 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1205 |
+
$alerts = array();
|
1206 |
+
// The fileoptions file that contains the file tree information.
|
1207 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1208 |
+
$fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt';
|
1209 |
+
|
1210 |
+
// Purge cache if too old.
|
1211 |
+
if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) {
|
1212 |
+
if ( false === unlink( $fileoptions_file ) ) {
|
1213 |
+
$alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.';
|
1214 |
+
}
|
1215 |
+
}
|
1216 |
+
|
1217 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #28.' );
|
1218 |
+
$fileoptions = new \pb_backupbuddy_fileoptions( $fileoptions_file );
|
1219 |
+
$zip_viewer = isset( $_POST['zip_viewer'] ) ? wp_unslash( $_POST['zip_viewer'] ) : '';
|
1220 |
+
// Either we are getting cached file tree information or we need to create afresh.
|
1221 |
+
$result = $fileoptions->is_ok();
|
1222 |
+
if ( true !== $result ) {
|
1223 |
+
// Get file listing.
|
1224 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1225 |
+
\pb_backupbuddy::$classes['zipbuddy'] = new \pluginbuddy_zipbuddy( ABSPATH, array(), 'unzip' );
|
1226 |
+
$files = \pb_backupbuddy::$classes['zipbuddy']->get_file_list( \backupbuddy_core::getBackupDirectory() . str_replace( '\\/', '', $zip_viewer ) );
|
1227 |
+
$fileoptions->options = $files;
|
1228 |
+
$fileoptions->save();
|
1229 |
+
} else {
|
1230 |
+
$files = &$fileoptions->options;
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
if ( ! is_array( $files ) ) {
|
1234 |
+
return array( 'error' => 'Error #548484. Unable to retrieve file listing from backup file `' . htmlentities( $zip_viewer ) . '`.' );
|
1235 |
+
}
|
1236 |
+
$subdirs = array();
|
1237 |
+
|
1238 |
+
foreach ( $files as $key => $file ) {
|
1239 |
+
if ( strlen( $file[0] ) < $root_len ) {
|
1240 |
+
unset( $files[ $key ] );
|
1241 |
+
continue;
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
if ( substr( $file[0], 0, $root_len ) != $root ) {
|
1245 |
+
unset( $files[ $key ] );
|
1246 |
+
continue;
|
1247 |
+
}
|
1248 |
+
|
1249 |
+
if ( 0 == strcmp( $file[0], $root ) ) {
|
1250 |
+
unset( $files[ $key ] );
|
1251 |
+
continue;
|
1252 |
+
}
|
1253 |
+
$unrooted_file = substr( $file[0], $root_len );
|
1254 |
+
$pos = strpos( $unrooted_file, '/' );
|
1255 |
+
if ( false !== $pos ) {
|
1256 |
+
$subdir = substr( $unrooted_file, 0, ( $pos + 1 ) );
|
1257 |
+
if ( ! in_array( $subdir, $subdirs ) ) {
|
1258 |
+
$subdirs[] = $subdir;
|
1259 |
+
$files[ $key ][0] = $subdir;
|
1260 |
+
} else {
|
1261 |
+
unset( $files[ $key ] );
|
1262 |
+
continue;
|
1263 |
+
|
1264 |
+
}
|
1265 |
+
} else {
|
1266 |
+
$files[ $key ][0] = $unrooted_file;
|
1267 |
+
}
|
1268 |
+
}
|
1269 |
+
|
1270 |
+
return array(
|
1271 |
+
'result' => 'SUCCESS',
|
1272 |
+
'files' => $files,
|
1273 |
+
'message' => implode( '<br/>', $alerts ),
|
1274 |
+
);
|
1275 |
+
}
|
1276 |
+
|
1277 |
+
/**
|
1278 |
+
* Exclude tree.
|
1279 |
+
*
|
1280 |
+
* @return array|string[] Return excluded files & directories list html or ERROR message.
|
1281 |
+
*/
|
1282 |
+
public function exclude_tree() {
|
1283 |
+
$root = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 ) . '/' . ( isset( $_POST['dir'] ) ? ltrim( urldecode( $_POST['dir'] ), '/\\' ) : '' );
|
1284 |
+
if ( file_exists( $root ) ) {
|
1285 |
+
$files = scandir( $root );
|
1286 |
+
|
1287 |
+
natcasesort( $files );
|
1288 |
+
|
1289 |
+
// Sort with directories first.
|
1290 |
+
$sorted_files = array(); // Temporary holder for sorting files.
|
1291 |
+
$sorted_directories = array(); // Temporary holder for sorting directories.
|
1292 |
+
foreach ( $files as $file ) {
|
1293 |
+
if ( ( '.' == $file ) || ( '..' == $file ) ) {
|
1294 |
+
continue;
|
1295 |
+
}
|
1296 |
+
if ( is_file( str_replace( '//', '/', $root . $file ) ) ) {
|
1297 |
+
array_push( $sorted_files, $file );
|
1298 |
+
} else {
|
1299 |
+
array_unshift( $sorted_directories, $file );
|
1300 |
+
}
|
1301 |
+
}
|
1302 |
+
$files = array_merge( array_reverse( $sorted_directories ), $sorted_files );
|
1303 |
+
unset( $sorted_files );
|
1304 |
+
unset( $sorted_directories );
|
1305 |
+
unset( $file );
|
1306 |
+
|
1307 |
+
ob_start();
|
1308 |
+
|
1309 |
+
if ( count( $files ) > 0 ) { // Files found.
|
1310 |
+
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1311 |
+
foreach ( $files as $file ) {
|
1312 |
+
if ( file_exists( str_replace( '//', '/', $root . $file ) ) ) {
|
1313 |
+
if ( is_dir( str_replace( '//', '/', $root . $file ) ) ) { // Directory.
|
1314 |
+
echo '<li class="directory collapsed">';
|
1315 |
+
$return = '';
|
1316 |
+
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1317 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1318 |
+
$return .= '</div>';
|
1319 |
+
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file ) . '/" title="Toggle expand...">' . htmlentities( $file ) . $return . '</a>';
|
1320 |
+
echo '</li>';
|
1321 |
+
} else { // File.
|
1322 |
+
echo '<li class="file collapsed">';
|
1323 |
+
$return = '';
|
1324 |
+
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1325 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1326 |
+
$return .= '</div>';
|
1327 |
+
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file ) . '">' . htmlentities( $file ) . $return . '</a>';
|
1328 |
+
echo '</li>';
|
1329 |
+
}
|
1330 |
+
}
|
1331 |
+
}
|
1332 |
+
echo '</ul>';
|
1333 |
+
} else {
|
1334 |
+
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1335 |
+
echo '<li><a href="#" rel="' . htmlentities( \pb_backupbuddy::_POST( 'dir' ) . 'NONE' ) . '"><i>Empty Directory ...</i></a></li>';
|
1336 |
+
echo '</ul>';
|
1337 |
+
}
|
1338 |
+
|
1339 |
+
$html = ob_get_clean();
|
1340 |
+
return array( 'result' => $html );
|
1341 |
+
} else {
|
1342 |
+
return array( 'error' => 'Error #1127555. Unable to read child site root.' );
|
1343 |
+
}
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
/**
|
1347 |
+
* Additional tables.
|
1348 |
+
*
|
1349 |
+
* @param bool $display_size Display size. Default: false.
|
1350 |
+
*
|
1351 |
+
* @return string Additional table html.
|
1352 |
+
* @throws Exception|\Exception Error message.
|
1353 |
+
*
|
1354 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
1355 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1356 |
+
* @uses \MainWP\Child\MainWP_Helper::check_properties()
|
1357 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1358 |
+
* @uses $wpdb::get_results()
|
1359 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1360 |
+
* @uses \pb_backupbuddy::plugin_url()
|
1361 |
+
*/
|
1362 |
+
public function pb_additional_tables( $display_size = false ) {
|
1363 |
+
|
1364 |
+
MainWP_Helper::check_classes_exists( '\pb_backupbuddy' );
|
1365 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', 'plugin_url' );
|
1366 |
+
MainWP_Helper::check_properties( '\pb_backupbuddy', 'format' );
|
1367 |
+
MainWP_Helper::check_methods( \pb_backupbuddy::$format, 'file_size' );
|
1368 |
+
|
1369 |
+
$return = '';
|
1370 |
+
$size_string = '';
|
1371 |
+
|
1372 |
+
/** @global object $wpdb WordPress Database. */
|
1373 |
+
global $wpdb;
|
1374 |
+
|
1375 |
+
if ( true === $display_size ) {
|
1376 |
+
$results = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
|
1377 |
+
} else {
|
1378 |
+
$results = $wpdb->get_results( 'SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE()', ARRAY_A );
|
1379 |
+
}
|
1380 |
+
foreach ( $results as $result ) {
|
1381 |
+
|
1382 |
+
if ( true === $display_size ) {
|
1383 |
+
// Fix up row count and average row length for InnoDB engine which returns inaccurate (and changing) values for these.
|
1384 |
+
if ( 'InnoDB' === $result['Engine'] ) {
|
1385 |
+
$rowCount = $wpdb->get_var( "SELECT COUNT(1) as rowCount FROM `{$result[ 'Name' ]}`", ARRAY_A ); // phpcs:ignore -- safe query.
|
1386 |
+
if ( false !== $rowCount ) {
|
1387 |
+
$result['Rows'] = $rowCount;
|
1388 |
+
if ( 0 < $result['Rows'] ) {
|
1389 |
+
$result['Avg_row_length'] = ( $result['Data_length'] / $result['Rows'] );
|
1390 |
+
}
|
1391 |
+
}
|
1392 |
+
unset( $rowCount );
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
// Table size.
|
1396 |
+
$size_string = ' (' . \pb_backupbuddy::$format->file_size( ( $result['Data_length'] + $result['Index_length'] ) ) . ') ';
|
1397 |
+
|
1398 |
+
} // end if display size enabled.
|
1399 |
+
|
1400 |
+
$return .= '<li class="file ext_sql collapsed">';
|
1401 |
+
$return .= '<a rel="/" alt="' . $result['table_name'] . '">' . $result['table_name'] . $size_string;
|
1402 |
+
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1403 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_table_addexclude"> <img src="' . \pb_backupbuddy::plugin_url() . '/images/greenplus.png" style="vertical-align: -3px;" title="Add to inclusions..." class="pb_backupbuddy_table_addinclude">';
|
1404 |
+
$return .= '</div>';
|
1405 |
+
$return .= '</a>';
|
1406 |
+
$return .= '</li>';
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
return '<div class="jQueryOuterTree" style="position: absolute; height: 160px;"><ul class="jqueryFileTree">' . $return . '</ul></div>';
|
1410 |
+
}
|
1411 |
+
|
1412 |
+
/**
|
1413 |
+
* Restore file view.
|
1414 |
+
*
|
1415 |
+
* @return array|string[] Return results array. ERROR message on failure.
|
1416 |
+
*
|
1417 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1418 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1419 |
+
* @uses \pluginbuddy_zipbuddy()
|
1420 |
+
* @uses \pluginbuddy_zipbuddy::extract()
|
1421 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1422 |
+
* @uses \pb_backupbuddy::status()
|
1423 |
+
* @uses \pb_backupbuddy::anti_directory_browsing()
|
1424 |
+
* @uses \pb_backupbuddy::$filesystem::unlink_recursive()
|
1425 |
+
*/
|
1426 |
+
public function restore_file_view() {
|
1427 |
+
|
1428 |
+
$archive_file = isset( $_POST['archive'] ) ? wp_unslash( $_POST['archive'] ) : ''; // archive to extract from.
|
1429 |
+
$file = isset( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : ''; // file to extract.
|
1430 |
+
$serial = \backupbuddy_core::get_serial_from_file( $archive_file ); // serial of archive.
|
1431 |
+
$temp_file = uniqid(); // temp filename to extract into.
|
1432 |
+
|
1433 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1434 |
+
$zipbuddy = new \pluginbuddy_zipbuddy( \backupbuddy_core::getBackupDirectory() );
|
1435 |
+
|
1436 |
+
// Calculate temp directory & lock it down.
|
1437 |
+
$temp_dir = get_temp_dir();
|
1438 |
+
$destination = $temp_dir . 'backupbuddy-' . $serial;
|
1439 |
+
if ( ( ( ! file_exists( $destination ) ) && ( false === mkdir( $destination ) ) ) ) {
|
1440 |
+
$error = 'Error #458485945b: Unable to create temporary location.';
|
1441 |
+
\pb_backupbuddy::status( 'error', $error );
|
1442 |
+
return array( 'error' => $error );
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
// If temp directory is within webroot then lock it down.
|
1446 |
+
$temp_dir = str_replace( '\\', '/', $temp_dir ); // Normalize for Windows.
|
1447 |
+
$temp_dir = rtrim( $temp_dir, '/\\' ) . '/'; // Enforce single trailing slash.
|
1448 |
+
if ( false !== stristr( $temp_dir, ABSPATH ) ) { // Temp dir is within webroot.
|
1449 |
+
\pb_backupbuddy::anti_directory_browsing( $destination );
|
1450 |
+
}
|
1451 |
+
unset( $temp_dir );
|
1452 |
+
|
1453 |
+
$message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". ';
|
1454 |
+
\pb_backupbuddy::status( 'details', $message );
|
1455 |
+
|
1456 |
+
$file_content = '';
|
1457 |
+
|
1458 |
+
$extractions = array( $file => $temp_file );
|
1459 |
+
$extract_result = $zipbuddy->extract( \backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $extractions );
|
1460 |
+
if ( false === $extract_result ) { // failed.
|
1461 |
+
$error = 'Error #584984458. Unable to extract.';
|
1462 |
+
\pb_backupbuddy::status( 'error', $error );
|
1463 |
+
return array( 'error' => $error );
|
1464 |
+
} else { // success.
|
1465 |
+
$file_content = file_get_contents( $destination . '/' . $temp_file );
|
1466 |
+
}
|
1467 |
+
|
1468 |
+
// Try to cleanup.
|
1469 |
+
if ( file_exists( $destination ) ) {
|
1470 |
+
if ( false === \pb_backupbuddy::$filesystem->unlink_recursive( $destination ) ) {
|
1471 |
+
\pb_backupbuddy::status( 'details', 'Unable to delete temporary holding directory `' . $destination . '`.' );
|
1472 |
+
} else {
|
1473 |
+
\pb_backupbuddy::status( 'details', 'Cleaned up temporary files.' );
|
1474 |
+
}
|
1475 |
+
}
|
1476 |
+
|
1477 |
+
return array(
|
1478 |
+
'result' => 'SUCCESS',
|
1479 |
+
'file_content' => $file_content,
|
1480 |
+
);
|
1481 |
+
}
|
1482 |
+
|
1483 |
+
|
1484 |
+
/**
|
1485 |
+
* Backupbuddy Restore files.
|
1486 |
+
*
|
1487 |
+
* @return array Return results array.
|
1488 |
+
*
|
1489 |
+
* @uses \pb_backupbuddy::set_status_serial()
|
1490 |
+
* @uses \pb_backupbuddy::status()
|
1491 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1492 |
+
* @uses \backupbuddy_restore_files::restore()
|
1493 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1494 |
+
* @uses \pb_backupbuddy::flush()
|
1495 |
+
*/
|
1496 |
+
public function restore_file_restore() {
|
1497 |
+
|
1498 |
+
$files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : ''; // file to extract.
|
1499 |
+
$archive_file = isset( $_POST['archive'] ) ? wp_unslash( $_POST['archive'] ) : ''; // archive to extract from.
|
1500 |
+
|
1501 |
+
$files_array = explode( ',', $files );
|
1502 |
+
$files = array();
|
1503 |
+
foreach ( $files_array as $file ) {
|
1504 |
+
if ( substr( $file, -1 ) == '/' ) { // If directory then add wildcard.
|
1505 |
+
$file = $file . '*';
|
1506 |
+
}
|
1507 |
+
$files[ $file ] = $file;
|
1508 |
+
}
|
1509 |
+
unset( $files_array );
|
1510 |
+
|
1511 |
+
$success = false;
|
1512 |
+
|
1513 |
+
/** @global object $pb_backupbuddy_js_status BackupBuddy js status. */
|
1514 |
+
global $pb_backupbuddy_js_status;
|
1515 |
+
|
1516 |
+
$pb_backupbuddy_js_status = true;
|
1517 |
+
|
1518 |
+
\pb_backupbuddy::set_status_serial( 'restore' );
|
1519 |
+
|
1520 |
+
/** @global string $wp_version WordPress version. */
|
1521 |
+
global $wp_version;
|
1522 |
+
|
1523 |
+
\pb_backupbuddy::status( 'details', 'BackupBuddy v' . \pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.' );
|
1524 |
+
|
1525 |
+
require \pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
|
1526 |
+
|
1527 |
+
ob_start();
|
1528 |
+
$result = \backupbuddy_restore_files::restore( \backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH );
|
1529 |
+
$restore_result = ob_get_clean();
|
1530 |
+
\pb_backupbuddy::flush();
|
1531 |
+
return array( 'restore_result' => $restore_result );
|
1532 |
+
}
|
1533 |
+
|
1534 |
+
/**
|
1535 |
+
* Get backup list.
|
1536 |
+
*
|
1537 |
+
* @param string $type Type of backup.
|
1538 |
+
* @param bool $subsite_mode Whether or not the backup is for a subsite. Default: false.
|
1539 |
+
*
|
1540 |
+
* @return array Return $sorted_backups array.
|
1541 |
+
*
|
1542 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1543 |
+
* @uses \backupbuddy_core::backup_prefix()
|
1544 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1545 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1546 |
+
* @uses \backupbuddy_core::backup_integrity_check()
|
1547 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1548 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1549 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1550 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1551 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1552 |
+
* @uses \pb_backupbuddy::status()
|
1553 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1554 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1555 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1556 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
1557 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
1558 |
+
* @uses \pb_backupbuddy::$format::date()
|
1559 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1560 |
+
* @uses \MainWP\Child\MainWP_Utility::create_nonce_without_session()
|
1561 |
+
*/
|
1562 |
+
public function get_backup_list( $type = 'default', $subsite_mode = false ) {
|
1563 |
+
$backups = array();
|
1564 |
+
$backup_sort_dates = array();
|
1565 |
+
|
1566 |
+
$files = glob( \backupbuddy_core::getBackupDirectory() . 'backup*.zip' );
|
1567 |
+
if ( ! is_array( $files ) ) {
|
1568 |
+
$files = array();
|
1569 |
+
}
|
1570 |
+
|
1571 |
+
$files2 = glob( \backupbuddy_core::getBackupDirectory() . 'snapshot*.zip' );
|
1572 |
+
if ( ! is_array( $files2 ) ) {
|
1573 |
+
$files2 = array();
|
1574 |
+
}
|
1575 |
+
|
1576 |
+
$files = array_merge( $files, $files2 );
|
1577 |
+
|
1578 |
+
if ( is_array( $files ) && ! empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
|
1579 |
+
|
1580 |
+
$backup_prefix = \backupbuddy_core::backup_prefix(); // To checking that this user can see this backup.
|
1581 |
+
foreach ( $files as $file_id => $file ) {
|
1582 |
+
|
1583 |
+
if ( ( true === $subsite_mode ) && is_multisite() ) { // If a Network and NOT the superadmin must make sure they can only see the specific subsite backups for security purposes.
|
1584 |
+
|
1585 |
+
// Only allow viewing of their own backups.
|
1586 |
+
if ( ! strstr( $file, $backup_prefix ) ) {
|
1587 |
+
unset( $files[ $file_id ] ); // Remove this backup from the list. This user does not have access to it.
|
1588 |
+
continue; // Skip processing to next file.
|
1589 |
+
}
|
1590 |
+
}
|
1591 |
+
|
1592 |
+
$serial = \backupbuddy_core::get_serial_from_file( $file );
|
1593 |
+
|
1594 |
+
$options = array();
|
1595 |
+
if ( file_exists( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) {
|
1596 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1597 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #33.' );
|
1598 |
+
$backup_options = new \pb_backupbuddy_fileoptions( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true ); // Will create file to hold integrity data if nothing exists.
|
1599 |
+
} else {
|
1600 |
+
$backup_options = '';
|
1601 |
+
}
|
1602 |
+
$backup_integrity = \backupbuddy_core::backup_integrity_check( $file, $backup_options, $options );
|
1603 |
+
|
1604 |
+
// Backup status.
|
1605 |
+
$pretty_status = array(
|
1606 |
+
true => '<span class="pb_label pb_label-success">Good</span>', // v4.0+ Good.
|
1607 |
+
'pass' => '<span class="pb_label pb_label-success">Good</span>', // Pre-v4.0 Good.
|
1608 |
+
false => '<span class="pb_label pb_label-important">Bad</span>', // v4.0+ Bad.
|
1609 |
+
'fail' => '<span class="pb_label pb_label-important">Bad</span>', // Pre-v4.0 Bad.
|
1610 |
+
);
|
1611 |
+
|
1612 |
+
// Backup type.
|
1613 |
+
$pretty_type = array(
|
1614 |
+
'full' => 'Full',
|
1615 |
+
'db' => 'Database',
|
1616 |
+
'files' => 'Files',
|
1617 |
+
'themes' => 'Themes',
|
1618 |
+
'plugins' => 'Plugins',
|
1619 |
+
);
|
1620 |
+
|
1621 |
+
// Defaults.
|
1622 |
+
$detected_type = '';
|
1623 |
+
$file_size = '';
|
1624 |
+
$modified = '';
|
1625 |
+
$modified_time = 0;
|
1626 |
+
$integrity = '';
|
1627 |
+
|
1628 |
+
$main_string = 'Warn#284.';
|
1629 |
+
if ( is_array( $backup_integrity ) ) { // Data intact... put it all together.
|
1630 |
+
// Calculate time ago.
|
1631 |
+
$time_ago = '';
|
1632 |
+
if ( isset( $backup_integrity['modified'] ) ) {
|
1633 |
+
$time_ago = \pb_backupbuddy::$format->time_ago( $backup_integrity['modified'] ) . ' ago';
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
$detected_type = \pb_backupbuddy::$format->prettify( $backup_integrity['detected_type'], $pretty_type );
|
1637 |
+
if ( '' == $detected_type ) {
|
1638 |
+
$detected_type = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $file ) );
|
1639 |
+
if ( '' == $detected_type ) {
|
1640 |
+
$detected_type = '<span class="description">Unknown</span>';
|
1641 |
+
}
|
1642 |
+
} else {
|
1643 |
+
if ( isset( $backup_options->options['profile'] ) ) {
|
1644 |
+
$detected_type = '
|
1645 |
+
<div>
|
1646 |
+
<span style="color: #AAA; float: left;">' . $detected_type . '</span>
|
1647 |
+
<span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>
|
1648 |
+
' . htmlentities( $backup_options->options['profile']['title'] ) . '
|
1649 |
+
</div>
|
1650 |
+
';
|
1651 |
+
}
|
1652 |
+
}
|
1653 |
+
|
1654 |
+
$file_size = \pb_backupbuddy::$format->file_size( $backup_integrity['size'] );
|
1655 |
+
$modified = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_integrity['modified'] ), 'l, F j, Y - g:i:s a' );
|
1656 |
+
$modified_time = $backup_integrity['modified'];
|
1657 |
+
if ( isset( $backup_integrity['status'] ) ) { // Pre-v4.0.
|
1658 |
+
$status = $backup_integrity['status'];
|
1659 |
+
} else { // v4.0+.
|
1660 |
+
$status = $backup_integrity['is_ok'];
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
// Calculate main row string.
|
1664 |
+
if ( 'default' == $type ) { // Default backup listing.
|
1665 |
+
$download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Utility::create_nonce_without_session( 'mainwp_download_backup' );
|
1666 |
+
$main_string = '<a href="#" download-url="' . $download_url . '"class="backupbuddyFileTitle mwp_bb_download_backup_lnk" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
1667 |
+
} elseif ( 'migrate' == $type ) { // Migration backup listing.
|
1668 |
+
$main_string = '<a class="pb_backupbuddy_hoveraction_migrate backupbuddyFileTitle" rel="' . basename( $file ) . '" href="' . \pb_backupbuddy::page_url() . '&migrate=' . basename( $file ) . '&value=' . basename( $file ) . '" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
1669 |
+
} else {
|
1670 |
+
$main_string = '{Unknown type.}';
|
1671 |
+
}
|
1672 |
+
// Add comment to main row string if applicable.
|
1673 |
+
if ( isset( $backup_integrity['comment'] ) && ( false !== $backup_integrity['comment'] ) && ( '' !== $backup_integrity['comment'] ) ) {
|
1674 |
+
$main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . htmlentities( $backup_integrity['comment'] ) . '</span></span>';
|
1675 |
+
}
|
1676 |
+
|
1677 |
+
$integrity = \pb_backupbuddy::$format->prettify( $status, $pretty_status ) . ' ';
|
1678 |
+
if ( isset( $backup_integrity['scan_notes'] ) && count( (array) $backup_integrity['scan_notes'] ) > 0 ) {
|
1679 |
+
foreach ( (array) $backup_integrity['scan_notes'] as $scan_note ) {
|
1680 |
+
$integrity .= $scan_note . ' ';
|
1681 |
+
}
|
1682 |
+
}
|
1683 |
+
$integrity .= '<a href="#" serial="' . $serial . '" class="mwp_bb_reset_integrity_lnk" file-name="' . basename( $file ) . '" title="Rescan integrity. Last checked ' . \pb_backupbuddy::$format->date( $backup_integrity['scan_time'] ) . '."> <i class="fa fa-refresh" aria-hidden="true"></i></a>';
|
1684 |
+
$integrity .= '<div class="row-actions"><a title="' . __( 'Backup Status', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_details_lnk thickbox">' . __( 'View Details', 'mainwp-child' ) . '</a></div>';
|
1685 |
+
|
1686 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1687 |
+
if ( file_exists( $sumLogFile ) ) {
|
1688 |
+
$integrity .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1689 |
+
}
|
1690 |
+
}
|
1691 |
+
|
1692 |
+
// No integrity check for themes or plugins types.
|
1693 |
+
$raw_type = \backupbuddy_core::getBackupTypeFromFile( $file );
|
1694 |
+
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1695 |
+
$integrity = 'n/a';
|
1696 |
+
}
|
1697 |
+
|
1698 |
+
$backups[ basename( $file ) ] = array(
|
1699 |
+
array( basename( $file ), $main_string . '<br><span class="description" style="color: #AAA; display: inline-block; margin-top: 5px;">' . basename( $file ) . '</span>' ),
|
1700 |
+
$detected_type,
|
1701 |
+
$file_size,
|
1702 |
+
$integrity,
|
1703 |
+
);
|
1704 |
+
|
1705 |
+
$backup_sort_dates[ basename( $file ) ] = $modified_time;
|
1706 |
+
|
1707 |
+
}
|
1708 |
+
}
|
1709 |
+
|
1710 |
+
// Sort backup by date.
|
1711 |
+
arsort( $backup_sort_dates );
|
1712 |
+
// Re-arrange backups based on sort dates.
|
1713 |
+
$sorted_backups = array();
|
1714 |
+
foreach ( $backup_sort_dates as $backup_file => $backup_sort_date ) {
|
1715 |
+
$sorted_backups[ $backup_file ] = $backups[ $backup_file ];
|
1716 |
+
unset( $backups[ $backup_file ] );
|
1717 |
+
}
|
1718 |
+
unset( $backups );
|
1719 |
+
return $sorted_backups;
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
/**
|
1723 |
+
* Get recent backup list.
|
1724 |
+
*
|
1725 |
+
* @return array $recentBackups Return recent backups array.
|
1726 |
+
*
|
1727 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1728 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1729 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1730 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1731 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1732 |
+
* @uses \pb_backupbuddy::status()
|
1733 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1734 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1735 |
+
* @uses \pb_backupbuddy::$format::date()
|
1736 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1737 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
1738 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1739 |
+
*/
|
1740 |
+
public function get_recent_backup_list() {
|
1741 |
+
$recentBackups_list = glob( \backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' );
|
1742 |
+
if ( ! is_array( $recentBackups_list ) ) {
|
1743 |
+
$recentBackups_list = array();
|
1744 |
+
}
|
1745 |
+
|
1746 |
+
$recentBackups = array();
|
1747 |
+
if ( count( $recentBackups_list ) > 0 ) {
|
1748 |
+
|
1749 |
+
// Backup type.
|
1750 |
+
$pretty_type = array(
|
1751 |
+
'full' => 'Full',
|
1752 |
+
'db' => 'Database',
|
1753 |
+
'files' => 'Files',
|
1754 |
+
);
|
1755 |
+
|
1756 |
+
foreach ( $recentBackups_list as $backup_fileoptions ) {
|
1757 |
+
|
1758 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1759 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #1.' );
|
1760 |
+
$backup = new \pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
1761 |
+
$result = $backup->is_ok();
|
1762 |
+
if ( true !== $result ) {
|
1763 |
+
\pb_backupbuddy::status( 'error', __( 'Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result );
|
1764 |
+
continue;
|
1765 |
+
}
|
1766 |
+
$backup = &$backup->options;
|
1767 |
+
|
1768 |
+
if ( ! isset( $backup['serial'] ) || ( '' == $backup['serial'] ) ) {
|
1769 |
+
continue;
|
1770 |
+
}
|
1771 |
+
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
1772 |
+
$status = '<span class="pb_label pb_label-success">Completed</span>';
|
1773 |
+
} elseif ( -1 == $backup['finish_time'] ) {
|
1774 |
+
$status = '<span class="pb_label pb_label-warning">Cancelled</span>';
|
1775 |
+
} elseif ( false === $backup['finish_time'] ) {
|
1776 |
+
$status = '<span class="pb_label pb_label-error">Failed (timeout?)</span>';
|
1777 |
+
} elseif ( ( time() - $backup['updated_time'] ) > \backupbuddy_constants::TIME_BEFORE_CONSIDERED_TIMEOUT ) {
|
1778 |
+
$status = '<span class="pb_label pb_label-error">Failed (likely timeout)</span>';
|
1779 |
+
} else {
|
1780 |
+
$status = '<span class="pb_label pb_label-warning">In progress or timed out</span>';
|
1781 |
+
}
|
1782 |
+
$status .= '<br>';
|
1783 |
+
|
1784 |
+
// Technical details link.
|
1785 |
+
$status .= '<div class="row-actions">';
|
1786 |
+
$status .= '<a title="' . __( 'Backup Process Technical Details', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_details_lnk thickbox">View Details</a>';
|
1787 |
+
|
1788 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-' . $backup['serial'] . '_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1789 |
+
if ( file_exists( $sumLogFile ) ) {
|
1790 |
+
$status .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
$status .= '</div>';
|
1794 |
+
|
1795 |
+
// Calculate finish time (if finished).
|
1796 |
+
if ( $backup['finish_time'] > 0 ) {
|
1797 |
+
$finish_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup['finish_time'] ) ) . '<br><span class="description">' . \pb_backupbuddy::$format->time_ago( $backup['finish_time'] ) . ' ago</span>';
|
1798 |
+
} else { // unfinished.
|
1799 |
+
$finish_time = '<i>Unfinished</i>';
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
$backupTitle = '<span class="backupbuddyFileTitle" style="color: #000;" title="' . basename( $backup['archive_file'] ) . '">' . \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup['start_time'] ), 'l, F j, Y - g:i:s a' ) . ' (' . \pb_backupbuddy::$format->time_ago( $backup['start_time'] ) . ' ago)</span><br><span class="description">' . basename( $backup['archive_file'] ) . '</span>';
|
1803 |
+
|
1804 |
+
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
1805 |
+
$backupType = '<div><span style="color: #AAA; float: left;">' . \pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ) . '</span><span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>' . $backup['profile']['title'] . '</div>';
|
1806 |
+
} else {
|
1807 |
+
$backupType = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
1808 |
+
if ( '' == $backupType ) {
|
1809 |
+
$backupType = '<span class="description">Unknown</span>';
|
1810 |
+
}
|
1811 |
+
}
|
1812 |
+
|
1813 |
+
if ( isset( $backup['archive_size'] ) && ( $backup['archive_size'] > 0 ) ) {
|
1814 |
+
$archive_size = \pb_backupbuddy::$format->file_size( $backup['archive_size'] );
|
1815 |
+
} else {
|
1816 |
+
$archive_size = 'n/a';
|
1817 |
+
}
|
1818 |
+
|
1819 |
+
// No integrity check for themes or plugins types.
|
1820 |
+
$raw_type = \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] );
|
1821 |
+
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1822 |
+
$status = 'n/a';
|
1823 |
+
}
|
1824 |
+
|
1825 |
+
// Append to list.
|
1826 |
+
$recentBackups[ $backup['serial'] ] = array(
|
1827 |
+
array( basename( $backup['archive_file'] ), $backupTitle ),
|
1828 |
+
$backupType,
|
1829 |
+
$archive_size,
|
1830 |
+
ucfirst( $backup['trigger'] ),
|
1831 |
+
$status,
|
1832 |
+
'start_timestamp' => $backup['start_time'], // Used by array sorter later to put backups in proper order.
|
1833 |
+
);
|
1834 |
+
|
1835 |
+
}
|
1836 |
+
|
1837 |
+
$columns = array(
|
1838 |
+
__( 'Recently Made Backups (Start Time)', 'mainwp-child' ),
|
1839 |
+
__( 'Type | Profile', 'mainwp-child' ),
|
1840 |
+
__( 'File Size', 'mainwp-child' ),
|
1841 |
+
__( 'Trigger', 'mainwp-child' ),
|
1842 |
+
__( 'Status', 'mainwp-child' ) . ' <span class="description">(hover for options)</span>',
|
1843 |
+
);
|
1844 |
+
|
1845 |
+
/**
|
1846 |
+
* Backupbuddy Sort.
|
1847 |
+
*
|
1848 |
+
* @param array $array Array to sort.
|
1849 |
+
* @param strign $key Sort key.
|
1850 |
+
*
|
1851 |
+
* @return array $array Return sorted array.
|
1852 |
+
*/
|
1853 |
+
function pb_backupbuddy_aasort( &$array, $key ) {
|
1854 |
+
$sorter = array();
|
1855 |
+
$ret = array();
|
1856 |
+
reset( $array );
|
1857 |
+
foreach ( $array as $ii => $va ) {
|
1858 |
+
$sorter[ $ii ] = $va[ $key ];
|
1859 |
+
}
|
1860 |
+
asort( $sorter );
|
1861 |
+
foreach ( $sorter as $ii => $va ) {
|
1862 |
+
$ret[ $ii ] = $array[ $ii ];
|
1863 |
+
}
|
1864 |
+
$array = $ret;
|
1865 |
+
}
|
1866 |
+
|
1867 |
+
\pb_backupbuddy_aasort( $recentBackups, 'start_timestamp' ); // Sort by multidimensional array with key start_timestamp.
|
1868 |
+
$recentBackups = array_reverse( $recentBackups ); // Reverse array order to show newest first.
|
1869 |
+
}
|
1870 |
+
|
1871 |
+
return $recentBackups;
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
/**
|
1875 |
+
* Delete sheduled backup.
|
1876 |
+
*
|
1877 |
+
* @return array $information Return results array.
|
1878 |
+
*
|
1879 |
+
* @uses \pb_backupbuddy::$options
|
1880 |
+
* @uses \pb_backupbuddy::save()
|
1881 |
+
*/
|
1882 |
+
public function delete_scheduled_backup() {
|
1883 |
+
$schedule_ids = isset( $_POST['schedule_ids'] ) ? wp_unslash( $_POST['schedule_ids'] ) : '';
|
1884 |
+
$schedule_ids = explode( ',', $schedule_ids );
|
1885 |
+
|
1886 |
+
if ( empty( $schedule_ids ) ) {
|
1887 |
+
return array( 'error' => __( 'Empty schedule ids', 'mainwp-child' ) );
|
1888 |
+
}
|
1889 |
+
foreach ( $schedule_ids as $sch_id ) {
|
1890 |
+
if ( isset( \pb_backupbuddy::$options['schedules'][ $sch_id ] ) ) {
|
1891 |
+
unset( \pb_backupbuddy::$options['schedules'][ $sch_id ] );
|
1892 |
+
}
|
1893 |
+
}
|
1894 |
+
\pb_backupbuddy::save();
|
1895 |
+
$information['result'] = 'SUCCESS';
|
1896 |
+
return $information;
|
1897 |
+
}
|
1898 |
+
|
1899 |
+
/**
|
1900 |
+
* View log.
|
1901 |
+
*
|
1902 |
+
* @return array|string[] Return log html.
|
1903 |
+
*
|
1904 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1905 |
+
* @uses \pb_backupbuddy::$format::date()
|
1906 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
1907 |
+
* @uses \pb_backupbuddy::flush()
|
1908 |
+
*/
|
1909 |
+
public function view_log() {
|
1910 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1911 |
+
$logFile = \backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_sum_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1912 |
+
|
1913 |
+
if ( ! file_exists( $logFile ) ) {
|
1914 |
+
return array( 'error' => 'Error #858733: Log file `' . $logFile . '` not found or access denied.' );
|
1915 |
+
}
|
1916 |
+
|
1917 |
+
$lines = file_get_contents( $logFile );
|
1918 |
+
$lines = explode( "\n", $lines );
|
1919 |
+
ob_start();
|
1920 |
+
?>
|
1921 |
+
|
1922 |
+
<textarea readonly="readonly" id="backupbuddy_messages" wrap="off" style="width: 100%; min-height: 400px; height: 500px; height: 80%; background: #FFF;">
|
1923 |
+
<?php
|
1924 |
+
foreach ( (array) $lines as $rawline ) {
|
1925 |
+
$line = json_decode( $rawline, true );
|
1926 |
+
if ( is_array( $line ) ) {
|
1927 |
+
$u = '';
|
1928 |
+
if ( isset( $line['u'] ) ) {
|
1929 |
+
$u = '.' . $line['u'];
|
1930 |
+
}
|
1931 |
+
echo \pb_backupbuddy::$format->date( $line['time'], 'G:i:s' ) . $u . "\t\t";
|
1932 |
+
echo $line['run'] . "sec\t";
|
1933 |
+
echo $line['mem'] . "MB\t";
|
1934 |
+
echo $line['event'] . "\t";
|
1935 |
+
echo $line['data'] . "\n";
|
1936 |
+
} else {
|
1937 |
+
echo $rawline . "\n";
|
1938 |
+
}
|
1939 |
+
}
|
1940 |
+
?>
|
1941 |
+
</textarea><br><br>
|
1942 |
+
<small>Log file: <?php echo $logFile; ?></small>
|
1943 |
+
<br>
|
1944 |
+
<?php
|
1945 |
+
echo '<small>Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)';
|
1946 |
+
?>
|
1947 |
+
<br><br>
|
1948 |
+
<?php
|
1949 |
+
$html = ob_get_clean();
|
1950 |
+
\pb_backupbuddy::flush();
|
1951 |
+
return array(
|
1952 |
+
'result' => 'SUCCESS',
|
1953 |
+
'html_log' => $html,
|
1954 |
+
);
|
1955 |
+
}
|
1956 |
+
|
1957 |
+
|
1958 |
+
/**
|
1959 |
+
* Pretty results.
|
1960 |
+
*
|
1961 |
+
* @param bool $value Results TRUE|FALSE.
|
1962 |
+
*
|
1963 |
+
* @return string Return Pass or Fail message.
|
1964 |
+
*/
|
1965 |
+
function pb_pretty_results( $value ) {
|
1966 |
+
if ( true === $value ) {
|
1967 |
+
return '<span class="pb_label pb_label-success">Pass</span>';
|
1968 |
+
} else {
|
1969 |
+
return '<span class="pb_label pb_label-important">Fail</span>';
|
1970 |
+
}
|
1971 |
+
}
|
1972 |
+
|
1973 |
+
|
1974 |
+
/**
|
1975 |
+
* View details.
|
1976 |
+
*
|
1977 |
+
* @return array|string[] Return results array & echo details.
|
1978 |
+
*
|
1979 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1980 |
+
* @uses \backupbuddy_core::getZipMeta()
|
1981 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1982 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1983 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1984 |
+
* @uses \pb_backupbuddy::$format::date()
|
1985 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1986 |
+
* @uses \pb_backupbuddy::$ui::list_table()
|
1987 |
+
* @uses \pb_backupbuddy::load()
|
1988 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1989 |
+
* @uses \pb_backupbuddy::status()
|
1990 |
+
* @uses \pb_backupbuddy::flush()
|
1991 |
+
*/
|
1992 |
+
public function view_detail() {
|
1993 |
+
|
1994 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1995 |
+
$serial = str_replace( '/\\', '', $serial );
|
1996 |
+
\pb_backupbuddy::load();
|
1997 |
+
|
1998 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1999 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #27.' );
|
2000 |
+
$optionsFile = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt';
|
2001 |
+
$backup_options = new \pb_backupbuddy_fileoptions( $optionsFile, $read_only = true );
|
2002 |
+
$result = $backup_options->is_ok();
|
2003 |
+
if ( true !== $result ) {
|
2004 |
+
return array( 'error' => __( 'Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result );
|
2005 |
+
}
|
2006 |
+
ob_start();
|
2007 |
+
$integrity = $backup_options->options['integrity'];
|
2008 |
+
|
2009 |
+
$start_time = 'Unknown';
|
2010 |
+
$finish_time = 'Unknown';
|
2011 |
+
if ( isset( $backup_options->options['start_time'] ) ) {
|
2012 |
+
$start_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_options->options['start_time'] ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $backup_options->options['start_time'] ) . ' ago)</span>';
|
2013 |
+
if ( $backup_options->options['finish_time'] > 0 ) {
|
2014 |
+
$finish_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_options->options['finish_time'] ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $backup_options->options['finish_time'] ) . ' ago)</span>';
|
2015 |
+
} else { // unfinished.
|
2016 |
+
$finish_time = '<i>Unfinished</i>';
|
2017 |
+
}
|
2018 |
+
}
|
2019 |
+
|
2020 |
+
// ***** BEGIN TESTS AND RESULTS.
|
2021 |
+
if ( isset( $integrity['status_details'] ) ) {
|
2022 |
+
echo '<h3>Integrity Technical Details</h3>';
|
2023 |
+
echo '<textarea style="width: 100%; height: 175px;" wrap="off">';
|
2024 |
+
foreach ( $integrity as $item_name => $item_value ) {
|
2025 |
+
$item_value = str_replace( '<br />', '<br>', $item_value );
|
2026 |
+
$item_value = str_replace( '<br><br>', '<br>', $item_value );
|
2027 |
+
$item_value = str_replace( '<br>', "\n ", $item_value );
|
2028 |
+
echo $item_name . ' => ' . $item_value . "\n";
|
2029 |
+
}
|
2030 |
+
echo '</textarea><br><br><b>Note:</b> It is normal to see several "file not found" entries as BackupBuddy checks for expected files in multiple locations, expecting to only find each file once in one of those locations.';
|
2031 |
+
} else {
|
2032 |
+
|
2033 |
+
echo '<br>';
|
2034 |
+
|
2035 |
+
if ( isset( $integrity['status_details'] ) ) { // PRE-v4.0 Tests.
|
2036 |
+
|
2037 |
+
|
2038 |
+
// The tests & their status.
|
2039 |
+
$tests = array();
|
2040 |
+
$tests[] = array( 'BackupBackup data file exists', $this->pb_pretty_results( $integrity['status_details']['found_dat'] ) );
|
2041 |
+
$tests[] = array( 'Database SQL file exists', $this->pb_pretty_results( $integrity['status_details']['found_sql'] ) );
|
2042 |
+
if ( 'full' == $integrity['detected_type'] ) {
|
2043 |
+
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', $this->pb_pretty_results( $integrity['status_details']['found_wpconfig'] ) );
|
2044 |
+
} elseif ( 'files' == $integrity['detected_type'] ) {
|
2045 |
+
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', $this->pb_pretty_results( $integrity['status_details']['found_wpconfig'] ) );
|
2046 |
+
} else { // DB only.
|
2047 |
+
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', '<span class="pb_label pb_label-success">N/A</span>' );
|
2048 |
+
}
|
2049 |
+
} else { // 4.0+ Tests.
|
2050 |
+
$tests = array();
|
2051 |
+
if ( isset( $integrity['tests'] ) ) {
|
2052 |
+
foreach ( (array) $integrity['tests'] as $test ) {
|
2053 |
+
if ( true === $test['pass'] ) {
|
2054 |
+
$status_text = '<span class="pb_label pb_label-success">Pass</span>';
|
2055 |
+
} else {
|
2056 |
+
$status_text = '<span class="pb_label pb_label-important">Fail</span>';
|
2057 |
+
}
|
2058 |
+
$tests[] = array( $test['test'], $status_text );
|
2059 |
+
}
|
2060 |
+
}
|
2061 |
+
}
|
2062 |
+
|
2063 |
+
$columns = array(
|
2064 |
+
__( 'Integrity Test', 'mainwp-child' ),
|
2065 |
+
__( 'Status', 'mainwp-child' ),
|
2066 |
+
);
|
2067 |
+
|
2068 |
+
\pb_backupbuddy::$ui->list_table(
|
2069 |
+
$tests,
|
2070 |
+
array(
|
2071 |
+
'columns' => $columns,
|
2072 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2073 |
+
)
|
2074 |
+
);
|
2075 |
+
|
2076 |
+
}
|
2077 |
+
echo '<br><br>';
|
2078 |
+
// ***** END TESTS AND RESULTS.
|
2079 |
+
|
2080 |
+
// Output meta info table (if any).
|
2081 |
+
$metaInfo = array();
|
2082 |
+
$metaInfo = \backupbuddy_core::getZipMeta( \backupbuddy_core::getBackupDirectory() . $integrity['file'] );
|
2083 |
+
if ( isset( $integrity['file'] ) && ( false === $metaInfo ) ) {
|
2084 |
+
echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
|
2085 |
+
} else {
|
2086 |
+
\pb_backupbuddy::$ui->list_table(
|
2087 |
+
$metaInfo,
|
2088 |
+
array(
|
2089 |
+
'columns' => array( 'Backup Details', 'Value' ),
|
2090 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2091 |
+
)
|
2092 |
+
);
|
2093 |
+
}
|
2094 |
+
echo '<br><br>';
|
2095 |
+
|
2096 |
+
// ***** BEGIN STEPS.
|
2097 |
+
$steps = array();
|
2098 |
+
$steps[] = array( 'Start Time', $start_time, '' );
|
2099 |
+
if ( isset( $backup_options->options['steps'] ) ) {
|
2100 |
+
foreach ( $backup_options->options['steps'] as $step ) {
|
2101 |
+
if ( isset( $step['finish_time'] ) && ( 0 != $step['finish_time'] ) ) {
|
2102 |
+
|
2103 |
+
// Step name.
|
2104 |
+
if ( 'backup_create_database_dump' == $step['function'] ) {
|
2105 |
+
if ( count( $step['args'][0] ) == 1 ) {
|
2106 |
+
$step_name = 'Database dump (breakout: ' . $step['args'][0][0] . ')';
|
2107 |
+
} else {
|
2108 |
+
$step_name = 'Database dump';
|
2109 |
+
}
|
2110 |
+
} elseif ( 'backup_zip_files' == $step['function'] ) {
|
2111 |
+
if ( isset( $backup_options->options['steps']['backup_zip_files'] ) ) {
|
2112 |
+
$zip_time = $backup_options->options['steps']['backup_zip_files'];
|
2113 |
+
} else {
|
2114 |
+
$zip_time = 0;
|
2115 |
+
}
|
2116 |
+
|
2117 |
+
// Calculate write speed in MB/sec for this backup.
|
2118 |
+
if ( '0' == $zip_time ) { // Took approx 0 seconds to backup so report this speed.
|
2119 |
+
$write_speed = '> ' . \pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] );
|
2120 |
+
} else {
|
2121 |
+
if ( 0 == $zip_time ) {
|
2122 |
+
$write_speed = '';
|
2123 |
+
} else {
|
2124 |
+
$write_speed = \pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] / $zip_time ) . '/sec';
|
2125 |
+
}
|
2126 |
+
}
|
2127 |
+
$step_name = 'Zip archive creation (Write speed: ' . $write_speed . ')';
|
2128 |
+
} elseif ( 'post_backup' == $step['function'] ) {
|
2129 |
+
$step_name = 'Post-backup cleanup';
|
2130 |
+
} elseif ( 'integrity_check' == $step['function'] ) {
|
2131 |
+
$step_name = 'Integrity Check';
|
2132 |
+
} else {
|
2133 |
+
$step_name = $step['function'];
|
2134 |
+
}
|
2135 |
+
|
2136 |
+
// Step time taken.
|
2137 |
+
$seconds = (int) ( $step['finish_time'] - $step['start_time'] );
|
2138 |
+
if ( $seconds < 1 ) {
|
2139 |
+
$step_time = '< 1 second';
|
2140 |
+
} else {
|
2141 |
+
$step_time = $seconds . ' seconds';
|
2142 |
+
}
|
2143 |
+
|
2144 |
+
// Compile details for this step into array.
|
2145 |
+
$steps[] = array(
|
2146 |
+
$step_name,
|
2147 |
+
$step_time,
|
2148 |
+
$step['attempts'],
|
2149 |
+
);
|
2150 |
+
|
2151 |
+
}
|
2152 |
+
}
|
2153 |
+
} else {
|
2154 |
+
$step_times[] = 'unknown';
|
2155 |
+
}
|
2156 |
+
|
2157 |
+
// Total overall time from initiation to end.
|
2158 |
+
if ( isset( $backup_options->options['finish_time'] ) && isset( $backup_options->options['start_time'] ) && ( 0 != $backup_options->options['finish_time'] ) && ( 0 != $backup_options->options['start_time'] ) ) {
|
2159 |
+
$seconds = ( $backup_options->options['finish_time'] - $backup_options->options['start_time'] );
|
2160 |
+
if ( $seconds < 1 ) {
|
2161 |
+
$total_time = '< 1 second';
|
2162 |
+
} else {
|
2163 |
+
$total_time = $seconds . ' seconds';
|
2164 |
+
}
|
2165 |
+
} else {
|
2166 |
+
$total_time = '<i>Unknown</i>';
|
2167 |
+
}
|
2168 |
+
$steps[] = array( 'Finish Time', $finish_time, '' );
|
2169 |
+
$steps[] = array(
|
2170 |
+
'<b>Total Overall Time</b>',
|
2171 |
+
$total_time,
|
2172 |
+
'',
|
2173 |
+
);
|
2174 |
+
|
2175 |
+
$columns = array(
|
2176 |
+
__( 'Backup Steps', 'mainwp-child' ),
|
2177 |
+
__( 'Time', 'mainwp-child' ),
|
2178 |
+
__( 'Attempts', 'mainwp-child' ),
|
2179 |
+
);
|
2180 |
+
|
2181 |
+
if ( count( $steps ) == 0 ) {
|
2182 |
+
_e( 'No step statistics were found for this backup.', 'mainwp-child' );
|
2183 |
+
} else {
|
2184 |
+
\pb_backupbuddy::$ui->list_table(
|
2185 |
+
$steps,
|
2186 |
+
array(
|
2187 |
+
'columns' => $columns,
|
2188 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2189 |
+
)
|
2190 |
+
);
|
2191 |
+
}
|
2192 |
+
echo '<br><br>';
|
2193 |
+
// ***** END STEPS.
|
2194 |
+
|
2195 |
+
if ( isset( $backup_options->options['trigger'] ) ) {
|
2196 |
+
$trigger = $backup_options->options['trigger'];
|
2197 |
+
} else {
|
2198 |
+
$trigger = 'Unknown trigger';
|
2199 |
+
}
|
2200 |
+
if ( isset( $integrity['scan_time'] ) ) {
|
2201 |
+
$scanned = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $integrity['scan_time'] ) );
|
2202 |
+
echo ucfirst( $trigger ) . " backup {$integrity['file']} last scanned {$scanned}.";
|
2203 |
+
}
|
2204 |
+
echo '<br><br><br>';
|
2205 |
+
|
2206 |
+
echo '<a class="button secondary-button" onclick="jQuery(\'#pb_backupbuddy_advanced_debug\').slideToggle();">Display Advanced Debugging</a>';
|
2207 |
+
echo '<div id="pb_backupbuddy_advanced_debug" style="display: none;">From options file: `' . $optionsFile . '`.<br>';
|
2208 |
+
echo '<textarea style="width: 100%; height: 400px;" wrap="on">';
|
2209 |
+
echo print_r( $backup_options->options, true ); // phpcs:ignore -- debug feature.
|
2210 |
+
echo '</textarea><br><br>';
|
2211 |
+
echo '</div><br><br>';
|
2212 |
+
|
2213 |
+
$html = ob_get_clean();
|
2214 |
+
\pb_backupbuddy::flush();
|
2215 |
+
return array(
|
2216 |
+
'result' => 'SUCCESS',
|
2217 |
+
'html_detail' => $html,
|
2218 |
+
);
|
2219 |
+
}
|
2220 |
+
|
2221 |
+
/**
|
2222 |
+
* Reset Integrity.
|
2223 |
+
*
|
2224 |
+
* @return array $information Return results array.
|
2225 |
+
*/
|
2226 |
+
public function reset_integrity() {
|
2227 |
+
$_GET['reset_integrity'] = isset( $_POST['reset_integrity'] ) ? sanitize_text_field( wp_unslash( $_POST['reset_integrity'] ) ) : '';
|
2228 |
+
$information['backup_list'] = $this->get_backup_list();
|
2229 |
+
$information['result'] = 'SUCCESS';
|
2230 |
+
return $information;
|
2231 |
+
}
|
2232 |
+
|
2233 |
+
/**
|
2234 |
+
* Download backup archive.
|
2235 |
+
*
|
2236 |
+
* @uses \MainWP\Child\MainWP_Utility::verify_nonce_without_session()
|
2237 |
+
* @uses \pb_backupbuddy::_GET()
|
2238 |
+
* @uses \pb_backupbuddy::$option
|
2239 |
+
* @uses \backupbuddy_core::verifyAjaxAccess()
|
2240 |
+
* @uses \backupbuddy_core::backup_prefix()
|
2241 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
2242 |
+
*/
|
2243 |
+
public function download_archive() {
|
2244 |
+
|
2245 |
+
if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
2246 |
+
die( '-1' );
|
2247 |
+
}
|
2248 |
+
|
2249 |
+
if ( ! MainWP_Utility::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
2250 |
+
die( '-2' );
|
2251 |
+
}
|
2252 |
+
|
2253 |
+
\backupbuddy_core::verifyAjaxAccess();
|
2254 |
+
|
2255 |
+
if ( is_multisite() && ! current_user_can( 'manage_network' ) ) { // If a Network and NOT the superadmin must make sure they can only download the specific subsite backups for security purposes.
|
2256 |
+
|
2257 |
+
if ( ! strstr( \pb_backupbuddy::_GET( 'backupbuddy_backup' ), \backupbuddy_core::backup_prefix() ) ) {
|
2258 |
+
die( 'Access Denied. You may only download backups specific to your Multisite Subsite. Only Network Admins may download backups for another subsite in the network.' );
|
2259 |
+
}
|
2260 |
+
}
|
2261 |
+
|
2262 |
+
if ( ! file_exists( \backupbuddy_core::getBackupDirectory() . \pb_backupbuddy::_GET( 'backupbuddy_backup' ) ) ) { // Does not exist.
|
2263 |
+
die( 'Error #548957857584784332. The requested backup file does not exist. It may have already been deleted.' );
|
2264 |
+
}
|
2265 |
+
|
2266 |
+
$abspath = str_replace( '\\', '/', ABSPATH );
|
2267 |
+
$backup_dir = str_replace( '\\', '/', \backupbuddy_core::getBackupDirectory() );
|
2268 |
+
|
2269 |
+
if ( false === stristr( $backup_dir, $abspath ) ) {
|
2270 |
+
die( 'Error #5432532. You cannot download backups stored outside of the WordPress web root. Please use FTP or other means.' );
|
2271 |
+
}
|
2272 |
+
|
2273 |
+
$sitepath = str_replace( $abspath, '', $backup_dir );
|
2274 |
+
$download_url = rtrim( site_url(), '/\\' ) . '/' . trim( $sitepath, '/\\' ) . '/' . \pb_backupbuddy::_GET( 'backupbuddy_backup' );
|
2275 |
+
|
2276 |
+
if ( '1' == \pb_backupbuddy::$options['lock_archives_directory'] ) {
|
2277 |
+
|
2278 |
+
if ( file_exists( \backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) {
|
2279 |
+
$unlink_status = unlink( \backupbuddy_core::getBackupDirectory() . '.htaccess' );
|
2280 |
+
if ( false === $unlink_status ) {
|
2281 |
+
die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' );
|
2282 |
+
}
|
2283 |
+
}
|
2284 |
+
|
2285 |
+
header( 'Location: ' . $download_url );
|
2286 |
+
ob_clean();
|
2287 |
+
flush();
|
2288 |
+
sleep( 8 );
|
2289 |
+
|
2290 |
+
$htaccess_creation_status = file_put_contents( \backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' );
|
2291 |
+
if ( false === $htaccess_creation_status ) {
|
2292 |
+
die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' );
|
2293 |
+
}
|
2294 |
+
} else {
|
2295 |
+
header( 'Location: ' . $download_url );
|
2296 |
+
}
|
2297 |
+
die();
|
2298 |
+
}
|
2299 |
+
|
2300 |
+
/**
|
2301 |
+
* Create backup.
|
2302 |
+
*
|
2303 |
+
* @return array|string[] Return SUCCESS message or ERROR message.
|
2304 |
+
*
|
2305 |
+
* @uses \pb_backupbuddy::$options
|
2306 |
+
* @uses \pb_backupbuddy_backup()
|
2307 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2308 |
+
* @uses \pb_backupbuddy::random_string()
|
2309 |
+
* @uses \pb_backupbuddy_backup::start_backup_process()
|
2310 |
+
*/
|
2311 |
+
public function create_backup() {
|
2312 |
+
$requested_profile = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
2313 |
+
|
2314 |
+
if ( ! isset( \pb_backupbuddy::$options['profiles'][ $requested_profile ] ) ) {
|
2315 |
+
return array( 'error' => 'Invalid Profile. Not found.' );
|
2316 |
+
}
|
2317 |
+
|
2318 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/backup.php';
|
2319 |
+
$newBackup = new \pb_backupbuddy_backup();
|
2320 |
+
|
2321 |
+
$profile_array = \pb_backupbuddy::$options['profiles'][ $requested_profile ];
|
2322 |
+
$serial_override = \pb_backupbuddy::random_string( 10 );
|
2323 |
+
|
2324 |
+
if ( true !== $newBackup->start_backup_process( $profile_array, 'manual', array(), isset( $_POST['post_backup_steps'] ) && is_array( $_POST['post_backup_steps'] ) ? wp_unslash( $_POST['post_backup_steps'] ) : array(), '', $serial_override, '', '', '' ) ) {
|
2325 |
+
return array( 'error' => __( 'Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'mainwp-child' ) );
|
2326 |
+
}
|
2327 |
+
return array( 'result' => 'SUCCESS' );
|
2328 |
+
}
|
2329 |
+
|
2330 |
+
/**
|
2331 |
+
* Start backup.
|
2332 |
+
*
|
2333 |
+
* @return array|int[]|string[] Return results array containing either OK->1 OR ERROR message.
|
2334 |
+
*
|
2335 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2336 |
+
* @uses \pb_backupbuddy_backup()
|
2337 |
+
* @uses \pb_backupbuddy_backup::start_backup_process()
|
2338 |
+
*/
|
2339 |
+
public function start_backup() {
|
2340 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/backup.php';
|
2341 |
+
$newBackup = new \pb_backupbuddy_backup();
|
2342 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '';
|
2343 |
+
if ( is_array( $data ) && isset( $data['serial_override'] ) ) {
|
2344 |
+
if ( $newBackup->start_backup_process(
|
2345 |
+
$data['profile_array'],
|
2346 |
+
$data['trigger'],
|
2347 |
+
array(),
|
2348 |
+
isset( $data['post_backup_steps'] ) && is_array( $data['post_backup_steps'] ) ? $data['post_backup_steps'] : array(),
|
2349 |
+
'',
|
2350 |
+
$data['serial_override'],
|
2351 |
+
isset( $data['export_plugins'] ) ? $data['export_plugins'] : '',
|
2352 |
+
$data['direction'],
|
2353 |
+
isset( $data['deployDestination'] ) ? $data['deployDestination'] : ''
|
2354 |
+
) !== true ) {
|
2355 |
+
return array( 'error' => __( 'Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'mainwp-child' ) );
|
2356 |
+
}
|
2357 |
+
} else {
|
2358 |
+
return array( 'error' => 'Invalid backup request.' );
|
2359 |
+
}
|
2360 |
+
|
2361 |
+
return array( 'ok' => 1 );
|
2362 |
+
}
|
2363 |
+
|
2364 |
+
/**
|
2365 |
+
* Backup status.
|
2366 |
+
*
|
2367 |
+
* @return array|string[] Return results array or ERROR message on failure.
|
2368 |
+
*
|
2369 |
+
* @uses \backupbuddy_api::getBackupStatus()
|
2370 |
+
*
|
2371 |
+
*/
|
2372 |
+
public function backup_status() {
|
2373 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '';
|
2374 |
+
$result = '';
|
2375 |
+
if ( is_array( $data ) && isset( $data['serial'] ) ) {
|
2376 |
+
ob_start();
|
2377 |
+
\backupbuddy_api::getBackupStatus( $data['serial'], $data['specialAction'], $data['initwaitretrycount'], $data['sqlFile'], $echo = true );
|
2378 |
+
$result = ob_get_clean();
|
2379 |
+
} else {
|
2380 |
+
return array( 'error' => 'Invalid backup request.' );
|
2381 |
+
}
|
2382 |
+
return array(
|
2383 |
+
'ok' => 1,
|
2384 |
+
'result' => $result,
|
2385 |
+
);
|
2386 |
+
}
|
2387 |
+
|
2388 |
+
/**
|
2389 |
+
* Stop Backup.
|
2390 |
+
*
|
2391 |
+
* @return int[] Return 1 on success.
|
2392 |
+
*/
|
2393 |
+
public function stop_backup() {
|
2394 |
+
$serial = isset( $_POST['serial'] ) ? wp_unslash( $_POST['serial'] ) : '';
|
2395 |
+
set_transient( 'pb_backupbuddy_stop_backup-' . $serial, true, ( 60 * 60 * 24 ) );
|
2396 |
+
return array( 'ok' => 1 );
|
2397 |
+
}
|
2398 |
+
|
2399 |
+
/**
|
2400 |
+
* Remove Save.
|
2401 |
+
*
|
2402 |
+
* @return int[]|string[] Return 1 on success or ERROR message on failure.
|
2403 |
+
*
|
2404 |
+
* @uses \pb_backupbuddy::$options
|
2405 |
+
* @uses \pb_backupbuddy::save()
|
2406 |
+
*/
|
2407 |
+
public function remote_save() {
|
2408 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : false;
|
2409 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : 0;
|
2410 |
+
|
2411 |
+
if ( is_array( $data ) && isset( $data['do_not_override'] ) ) {
|
2412 |
+
|
2413 |
+
if ( true == $data['do_not_override'] ) {
|
2414 |
+
if ( ( 's32' == $data['type'] || 's33' == $data['type'] ) ) {
|
2415 |
+
$not_override = array(
|
2416 |
+
'accesskey',
|
2417 |
+
'secretkey',
|
2418 |
+
'bucket',
|
2419 |
+
'region',
|
2420 |
+
);
|
2421 |
+
foreach ( $not_override as $opt ) {
|
2422 |
+
if ( isset( $data[ $opt ] ) ) {
|
2423 |
+
unset( $data[ $opt ] );
|
2424 |
+
}
|
2425 |
+
}
|
2426 |
+
}
|
2427 |
+
}
|
2428 |
+
|
2429 |
+
unset( $data['do_not_override'] );
|
2430 |
+
}
|
2431 |
+
|
2432 |
+
if ( is_array( $data ) ) {
|
2433 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2434 |
+
\pb_backupbuddy::$options['remote_destinations'][ $destination_id ] = array_merge( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ], $data );
|
2435 |
+
} else {
|
2436 |
+
$data['token'] = \pb_backupbuddy::$options['dropboxtemptoken'];
|
2437 |
+
\pb_backupbuddy::$options['remote_destinations'][ $destination_id ] = $data;
|
2438 |
+
}
|
2439 |
+
\pb_backupbuddy::save();
|
2440 |
+
return array( 'ok' => 1 );
|
2441 |
+
} else {
|
2442 |
+
return array( 'error' => 'Invalid request.' );
|
2443 |
+
}
|
2444 |
+
}
|
2445 |
+
|
2446 |
+
/**
|
2447 |
+
* Remove backup list.
|
2448 |
+
*
|
2449 |
+
* @return array $information Return results array.
|
2450 |
+
*
|
2451 |
+
* @uses \pb_backupbuddy::$options
|
2452 |
+
*/
|
2453 |
+
public function remote_list() {
|
2454 |
+
$information = array();
|
2455 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'] ) ) {
|
2456 |
+
$information['remote_destinations'] = \pb_backupbuddy::$options['remote_destinations'];
|
2457 |
+
}
|
2458 |
+
$information['result'] = 'SUCCESS';
|
2459 |
+
return $information;
|
2460 |
+
}
|
2461 |
+
|
2462 |
+
/**
|
2463 |
+
* Remote backup delete.
|
2464 |
+
*
|
2465 |
+
* @return array|int[]|string[] Returm OK on success or ERROR message on failure.
|
2466 |
+
*
|
2467 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2468 |
+
* @uses \pb_backupbuddy_destinations::delete_destination()
|
2469 |
+
*/
|
2470 |
+
public function remote_delete() {
|
2471 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : null;
|
2472 |
+
if ( null !== $destination_id ) {
|
2473 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
2474 |
+
$delete_response = \pb_backupbuddy_destinations::delete_destination( $destination_id, true );
|
2475 |
+
|
2476 |
+
if ( true !== $delete_response ) {
|
2477 |
+
return array( 'error' => $delete_response );
|
2478 |
+
} else {
|
2479 |
+
return array( 'ok' => 1 );
|
2480 |
+
}
|
2481 |
+
} else {
|
2482 |
+
return array( 'error' => 'Invalid request.' );
|
2483 |
+
}
|
2484 |
+
}
|
2485 |
+
|
2486 |
+
/**
|
2487 |
+
* Remove send.
|
2488 |
+
*
|
2489 |
+
* @return array|int[]|string[] Return 1 on sucess or ERROR message on failure.
|
2490 |
+
*
|
2491 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
2492 |
+
* @uses \backupbuddy_core::status()
|
2493 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
2494 |
+
* @uses \pb_backupbuddy::$options
|
2495 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2496 |
+
* @uses \pb_backupbuddy_destinations::get_info()
|
2497 |
+
* @uses \pb_backupbuddy_destination_stash::get_quota()
|
2498 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
2499 |
+
*/
|
2500 |
+
public function remote_send() {
|
2501 |
+
|
2502 |
+
$destination_id = isset( $_POST['destination_id'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['destination_id'] ) ) : null;
|
2503 |
+
$file = isset( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : null;
|
2504 |
+
$trigger = isset( $_POST['trigger'] ) ? wp_unslash( $_POST['trigger'] ) : 'manual';
|
2505 |
+
|
2506 |
+
if ( 'importbuddy.php' != $file ) {
|
2507 |
+
$backup_file = \backupbuddy_core::getBackupDirectory() . $file;
|
2508 |
+
if ( ! file_exists( $backup_file ) ) { // Error if file to send did not exist!
|
2509 |
+
$error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.';
|
2510 |
+
\pb_backupbuddy::status( 'error', $error_message );
|
2511 |
+
return array( 'error' => $error_message );
|
2512 |
+
}
|
2513 |
+
if ( is_dir( $backup_file ) ) { // Error if a directory is trying to be sent.
|
2514 |
+
$error_message = 'You are attempting to send a directory, `' . $backup_file . '`. Try again and verify there were no javascript errors.';
|
2515 |
+
\pb_backupbuddy::status( 'error', $error_message );
|
2516 |
+
return array( 'error' => $error_message );
|
2517 |
+
}
|
2518 |
+
} else {
|
2519 |
+
$backup_file = '';
|
2520 |
+
}
|
2521 |
+
|
2522 |
+
if ( isset( $_POST['send_importbuddy'] ) && '1' == $_POST['send_importbuddy'] ) {
|
2523 |
+
$send_importbuddy = true;
|
2524 |
+
\pb_backupbuddy::status( 'details', 'Cron send to be scheduled with importbuddy sending.' );
|
2525 |
+
} else {
|
2526 |
+
$send_importbuddy = false;
|
2527 |
+
\pb_backupbuddy::status( 'details', 'Cron send to be scheduled WITHOUT importbuddy sending.' );
|
2528 |
+
}
|
2529 |
+
|
2530 |
+
if ( isset( $_POST['delete_after'] ) && '1' == $_POST['delete_after'] ) {
|
2531 |
+
$delete_after = true;
|
2532 |
+
\pb_backupbuddy::status( 'details', 'Remote send set to delete after successful send.' );
|
2533 |
+
} else {
|
2534 |
+
$delete_after = false;
|
2535 |
+
\pb_backupbuddy::status( 'details', 'Remote send NOT set to delete after successful send.' );
|
2536 |
+
}
|
2537 |
+
|
2538 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2539 |
+
return array( 'error' => 'Error #833383: Invalid destination ID `' . htmlentities( $destination_id ) . '`.' );
|
2540 |
+
}
|
2541 |
+
|
2542 |
+
// For Stash we will check the quota prior to initiating send.
|
2543 |
+
if ( 'stash' == \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]['type'] ) {
|
2544 |
+
// Pass off to destination handler.
|
2545 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
2546 |
+
$send_result = \pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life.
|
2547 |
+
$stash_quota = \pb_backupbuddy_destination_stash::get_quota( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ], true );
|
2548 |
+
|
2549 |
+
if ( isset( $stash_quota['error'] ) ) {
|
2550 |
+
return array( 'error' => ' Error accessing Stash account. Send aborted. Details: `' . implode( ' - ', $stash_quota['error'] ) . '`.' );
|
2551 |
+
}
|
2552 |
+
|
2553 |
+
if ( '' != $backup_file ) {
|
2554 |
+
$backup_file_size = filesize( $backup_file );
|
2555 |
+
} else {
|
2556 |
+
$backup_file_size = 50000;
|
2557 |
+
}
|
2558 |
+
if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) {
|
2559 |
+
ob_start();
|
2560 |
+
echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n";
|
2561 |
+
echo 'Attempting to send file of size ' . \pb_backupbuddy::$format->file_size( $backup_file_size ) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. ';
|
2562 |
+
echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
|
2563 |
+
$error = ob_get_clean();
|
2564 |
+
return array( 'error' => $error );
|
2565 |
+
} else {
|
2566 |
+
if ( isset( $stash_quota['quota_warning'] ) && ( '' != $stash_quota['quota_warning'] ) ) {
|
2567 |
+
$warning = 'Warning: ' . $stash_quota['quota_warning'] . "\n\n";
|
2568 |
+
$success_output = true;
|
2569 |
+
}
|
2570 |
+
}
|
2571 |
+
}
|
2572 |
+
|
2573 |
+
\pb_backupbuddy::status( 'details', 'Scheduling cron to send to this remote destination...' );
|
2574 |
+
|
2575 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'remote_send', array( $destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after ) );
|
2576 |
+
if ( false === $schedule_result ) {
|
2577 |
+
$error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.';
|
2578 |
+
\pb_backupbuddy::status( 'error', $error );
|
2579 |
+
return array( 'error' => $error );
|
2580 |
+
} else {
|
2581 |
+
\pb_backupbuddy::status( 'details', 'Cron to send to remote destination scheduled.' );
|
2582 |
+
}
|
2583 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2584 |
+
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2585 |
+
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2586 |
+
}
|
2587 |
+
return array( 'ok' => 1 );
|
2588 |
+
}
|
2589 |
+
|
2590 |
+
/**
|
2591 |
+
* Get main log.
|
2592 |
+
*
|
2593 |
+
* @return array Return result array or ERROR message on failure.
|
2594 |
+
*
|
2595 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2596 |
+
* @uses \pb_backupbuddy::$options
|
2597 |
+
*/
|
2598 |
+
public function get_main_log() {
|
2599 |
+
$log_file = \backupbuddy_core::getLogDirectory() . 'log-' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
2600 |
+
ob_start();
|
2601 |
+
if ( file_exists( $log_file ) ) {
|
2602 |
+
readfile( $log_file );
|
2603 |
+
} else {
|
2604 |
+
echo __( 'Nothing has been logged.', 'mainwp-child' );
|
2605 |
+
}
|
2606 |
+
$result = ob_get_clean();
|
2607 |
+
return array( 'result' => $result );
|
2608 |
+
}
|
2609 |
+
|
2610 |
+
/**
|
2611 |
+
* Other settings.
|
2612 |
+
*
|
2613 |
+
* @return string[] Return results array.
|
2614 |
+
*
|
2615 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2616 |
+
* @uses \backupbuddy_housekeeping::run_periodic()
|
2617 |
+
* @uses \backupbuddy_core::getTempDirectory()
|
2618 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2619 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2620 |
+
* @uses \pb_backupbuddy::$filesystem->unlink_recursive()
|
2621 |
+
* @uses \pb_backupbuddy::anti_directory_browsing()
|
2622 |
+
* @uses \pb_backupbuddy::save()
|
2623 |
+
* @uses \pb_backupbuddy_fileoptions()
|
2624 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
2625 |
+
*/
|
2626 |
+
public function settings_other() {
|
2627 |
+
|
2628 |
+
$other_action = isset( $_POST['other_action'] ) ? wp_unslash( $_POST['other_action'] ) : '';
|
2629 |
+
|
2630 |
+
$message = '';
|
2631 |
+
$error = '';
|
2632 |
+
|
2633 |
+
if ( 'cleanup_now' == $other_action ) {
|
2634 |
+
$message = 'Performing cleanup procedures now trimming old files and data.';
|
2635 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/housekeeping.php';
|
2636 |
+
\backupbuddy_housekeeping::run_periodic( 0 ); // 0 cleans up everything even if not very old.
|
2637 |
+
|
2638 |
+
} elseif ( 'delete_tempfiles_now' == $other_action ) {
|
2639 |
+
$tempDir = \backupbuddy_core::getTempDirectory();
|
2640 |
+
$logDir = \backupbuddy_core::getLogDirectory();
|
2641 |
+
$message = 'Deleting all files contained within `' . $tempDir . '` and `' . $logDir . '`.';
|
2642 |
+
\pb_backupbuddy::$filesystem->unlink_recursive( $tempDir );
|
2643 |
+
\pb_backupbuddy::$filesystem->unlink_recursive( $logDir );
|
2644 |
+
\pb_backupbuddy::anti_directory_browsing( $logDir, $die = false ); // Put log dir back in place.
|
2645 |
+
} elseif ( 'reset_log' == $other_action ) {
|
2646 |
+
$log_file = \backupbuddy_core::getLogDirectory() . 'log-' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
2647 |
+
if ( file_exists( $log_file ) ) {
|
2648 |
+
unlink( $log_file );
|
2649 |
+
}
|
2650 |
+
if ( file_exists( $log_file ) ) { // Didnt unlink.
|
2651 |
+
$error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.';
|
2652 |
+
} else { // Unlinked.
|
2653 |
+
$message = 'Cleared log file.';
|
2654 |
+
}
|
2655 |
+
} elseif ( 'reset_disalerts' == $other_action ) {
|
2656 |
+
\pb_backupbuddy::$options['disalerts'] = array();
|
2657 |
+
\pb_backupbuddy::save();
|
2658 |
+
$message = 'Dismissed alerts have been reset. They may now be visible again.';
|
2659 |
+
|
2660 |
+
} elseif ( 'cancel_running_backups' == $other_action ) {
|
2661 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
2662 |
+
|
2663 |
+
$fileoptions_directory = \backupbuddy_core::getLogDirectory() . 'fileoptions/';
|
2664 |
+
$files = glob( $fileoptions_directory . '*.txt' );
|
2665 |
+
if ( ! is_array( $files ) ) {
|
2666 |
+
$files = array();
|
2667 |
+
}
|
2668 |
+
$cancelCount = 0;
|
2669 |
+
for ( $x = 0; $x <= 3; $x++ ) { // Try this a few times since there may be race conditions on an open file.
|
2670 |
+
foreach ( $files as $file ) {
|
2671 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #383.' );
|
2672 |
+
|
2673 |
+
$backup_options = new \pb_backupbuddy_fileoptions( $file, $read_only = false );
|
2674 |
+
$result = $backup_options->is_ok();
|
2675 |
+
if ( true !== $result ) {
|
2676 |
+
\pb_backupbuddy::status( 'error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.' );
|
2677 |
+
} else {
|
2678 |
+
if ( empty( $backup_options->options['finish_time'] ) || ( ( false !== $backup_options->options['finish_time'] ) && ( '-1' != $backup_options->options['finish_time'] ) ) ) {
|
2679 |
+
$backup_options->options['finish_time'] = -1; // Force marked as cancelled by user.
|
2680 |
+
$backup_options->save();
|
2681 |
+
$cancelCount++;
|
2682 |
+
}
|
2683 |
+
}
|
2684 |
+
}
|
2685 |
+
sleep( 1 );
|
2686 |
+
}
|
2687 |
+
|
2688 |
+
$message = 'Marked all timed out or running backups & transfers as officially cancelled (`' . $cancelCount . '` total found).';
|
2689 |
+
}
|
2690 |
+
|
2691 |
+
return array(
|
2692 |
+
'_error' => $error,
|
2693 |
+
'_message' => $message,
|
2694 |
+
);
|
2695 |
+
}
|
2696 |
+
|
2697 |
+
/**
|
2698 |
+
* Malware scan.
|
2699 |
+
*
|
2700 |
+
* @return array $result Return result array.
|
2701 |
+
*
|
2702 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
2703 |
+
* @uses \backupbuddy_core::addNotification()
|
2704 |
+
* @uses \pb_backupbuddy::$ui::start_metabox()
|
2705 |
+
* @uses \pb_backupbuddy::alert()
|
2706 |
+
*/
|
2707 |
+
public function malware_scan() {
|
2708 |
+
|
2709 |
+
\backupbuddy_core::schedule_single_event( time(), 'housekeeping', array() );
|
2710 |
+
update_option( '_transient_doing_cron', 0 );
|
2711 |
+
spawn_cron( time() + 150 );
|
2712 |
+
|
2713 |
+
ob_start();
|
2714 |
+
|
2715 |
+
if ( ! defined( 'pluginbuddy_importbuddy' ) ) {
|
2716 |
+
$url = home_url();
|
2717 |
+
} else {
|
2718 |
+
$url = str_replace( $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI'] );
|
2719 |
+
$url = str_replace( basename( $url ), '', $url );
|
2720 |
+
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
|
2721 |
+
}
|
2722 |
+
?>
|
2723 |
+
<style type="text/css">
|
2724 |
+
.inside label {
|
2725 |
+
display: block;
|
2726 |
+
vertical-align: top;
|
2727 |
+
width: 140px;
|
2728 |
+
font-weight: bold;
|
2729 |
+
}
|
2730 |
+
</style>
|
2731 |
+
|
2732 |
+
|
2733 |
+
<?php
|
2734 |
+
\pb_backupbuddy::$ui->start_metabox( __( 'Malware Scan URL', 'mainwp-child' ), true, 'width: 100%;' );
|
2735 |
+
|
2736 |
+
?>
|
2737 |
+
|
2738 |
+
<?php echo $url; ?>
|
2739 |
+
|
2740 |
+
<?php
|
2741 |
+
|
2742 |
+
$continue_1 = true;
|
2743 |
+
if ( 'http://localhost' == $url ) {
|
2744 |
+
_e( 'ERROR: You are currently running your site locally. Your site must be internet accessible to scan.', 'mainwp-child' );
|
2745 |
+
$continue_1 = false;
|
2746 |
+
}
|
2747 |
+
|
2748 |
+
if ( true === $continue_1 ) {
|
2749 |
+
|
2750 |
+
if ( ! empty( $_POST['refresh'] ) ) {
|
2751 |
+
delete_transient( 'pb_backupbuddy_malwarescan' );
|
2752 |
+
}
|
2753 |
+
|
2754 |
+
if ( ! defined( 'pluginbuddy_importbuddy' ) ) {
|
2755 |
+
$scan = get_transient( 'pb_backupbuddy_malwarescan' );
|
2756 |
+
} else {
|
2757 |
+
$scan = false;
|
2758 |
+
}
|
2759 |
+
|
2760 |
+
if ( false === $scan ) {
|
2761 |
+
flush();
|
2762 |
+
|
2763 |
+
$scan = wp_remote_get(
|
2764 |
+
'http://sitecheck.sucuri.net/scanner/?scan=' . rawurlencode( $url ) . '&serialized&clear=true',
|
2765 |
+
array(
|
2766 |
+
'method' => 'GET',
|
2767 |
+
'timeout' => 45,
|
2768 |
+
'redirection' => 5,
|
2769 |
+
'httpversion' => '1.0',
|
2770 |
+
'blocking' => true,
|
2771 |
+
'headers' => array(),
|
2772 |
+
'body' => null,
|
2773 |
+
'cookies' => array(),
|
2774 |
+
)
|
2775 |
+
);
|
2776 |
+
|
2777 |
+
if ( is_wp_error( $scan ) ) {
|
2778 |
+
\pb_backupbuddy::alert( __( 'ERROR #24452. Unable to load Malware Scan results. Details:', 'mainwp-child' ) . ' ' . $scan->get_error_message(), true );
|
2779 |
+
$scan = 'N;';
|
2780 |
+
} else {
|
2781 |
+
$scan = $scan['body'];
|
2782 |
+
set_transient( 'pb_backupbuddy_malwarescan', $scan, 60 * 60 * 1 ); // 1 hour cache.
|
2783 |
+
}
|
2784 |
+
}
|
2785 |
+
|
2786 |
+
$continue_2 = true;
|
2787 |
+
if ( substr( $scan, 0, 2 ) == 'N;' ) {
|
2788 |
+
echo __( 'An error was encountered attempting to scan this site.', 'mainwp-child' ), '<br />';
|
2789 |
+
echo __( 'An internet connection is required and this site must be accessible on the public internet.', 'mainwp-child' );
|
2790 |
+
echo '<br>';
|
2791 |
+
$scan = array();
|
2792 |
+
$continue_2 = false;
|
2793 |
+
} else {
|
2794 |
+
$scan = maybe_unserialize( $scan );
|
2795 |
+
}
|
2796 |
+
}
|
2797 |
+
\pb_backupbuddy::$ui->end_metabox();
|
2798 |
+
|
2799 |
+
if ( true === $continue_2 ) {
|
2800 |
+
|
2801 |
+
/**
|
2802 |
+
* Turn array into html li.
|
2803 |
+
*
|
2804 |
+
* @param array $array Array of data to convert.
|
2805 |
+
*
|
2806 |
+
* @return string Return html list.
|
2807 |
+
*/
|
2808 |
+
function lined_array( $array ) {
|
2809 |
+
if ( is_array( $array ) ) {
|
2810 |
+
foreach ( $array as $array_key => $array_item ) {
|
2811 |
+
if ( is_array( $array_item ) ) {
|
2812 |
+
$array[ $array_key ] = lined_array( $array_item );
|
2813 |
+
}
|
2814 |
+
}
|
2815 |
+
$return = '';
|
2816 |
+
foreach ( $array as $array_item ) {
|
2817 |
+
$return .= $array_item . '<br />';
|
2818 |
+
}
|
2819 |
+
return $return;
|
2820 |
+
} else {
|
2821 |
+
if ( empty( $array ) ) {
|
2822 |
+
return '<i>' . __( 'none', 'mainwp-child' ) . '</i><br />';
|
2823 |
+
} else {
|
2824 |
+
return $array . '<br />';
|
2825 |
+
}
|
2826 |
+
}
|
2827 |
+
}
|
2828 |
+
|
2829 |
+
if ( ! empty( $scan['MALWARE'] ) && ( 'E' != $scan['MALWARE'] ) ) {
|
2830 |
+
echo '<table><tr><td><i class="fa fa-exclamation-circle fa-5x" style="color: red"></i></td><td><h1>', __( 'Warning: Possible Malware Detected!', 'mainwp-child' ), '</h1>', __( 'See details below.', 'mainwp-child' ), '</td></tr></table>';
|
2831 |
+
}
|
2832 |
+
?>
|
2833 |
+
<div class="postbox-container" style="width: 100%; min-width: 750px;">
|
2834 |
+
<div class="metabox-holder">
|
2835 |
+
<div class="meta-box-sortables">
|
2836 |
+
|
2837 |
+
<div id="breadcrumbslike" class="postbox">
|
2838 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2839 |
+
<h3 class="hndle"><span><?php _e( 'Malware Detection', 'mainwp-child' ); ?></span></h3>
|
2840 |
+
<div class="inside">
|
2841 |
+
<label><?php _e( 'Malware', 'mainwp-child' ); ?></label>
|
2842 |
+
<?php
|
2843 |
+
if ( ! empty( $scan['MALWARE']['WARN'] ) ) { // Malware found.
|
2844 |
+
echo lined_array( $scan['MALWARE']['WARN'] );
|
2845 |
+
\backupbuddy_core::addNotification( 'malware_found', 'Malware detected on `' . $url . '`.', 'A malware scan was run on the site and detected malware.', array(), true );
|
2846 |
+
} else { // No malware found.
|
2847 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2848 |
+
\backupbuddy_core::addNotification( 'malware_not_found', 'No malware detected on `' . $url . '`.', 'A malware scan was run on the site and did not detect malware.' );
|
2849 |
+
}
|
2850 |
+
?>
|
2851 |
+
<br />
|
2852 |
+
</div>
|
2853 |
+
</div>
|
2854 |
+
|
2855 |
+
<div id="breadcrumbslike" class="postbox">
|
2856 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2857 |
+
<h3 class="hndle"><span><?php _e( 'Web server details', 'mainwp-child' ); ?></span></h3>
|
2858 |
+
<div class="inside">
|
2859 |
+
<label><?php _e( 'Site', 'mainwp-child' ); ?></label>
|
2860 |
+
<?php
|
2861 |
+
if ( ! empty( $scan['SCAN']['SITE'] ) ) {
|
2862 |
+
echo lined_array( $scan['SCAN']['SITE'] );
|
2863 |
+
} else {
|
2864 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2865 |
+
}
|
2866 |
+
?>
|
2867 |
+
<br />
|
2868 |
+
<label><?php _e( 'Hostname', 'mainwp-child' ); ?></label>
|
2869 |
+
<?php
|
2870 |
+
if ( ! empty( $scan['SCAN']['DOMAIN'] ) ) {
|
2871 |
+
echo lined_array( $scan['SCAN']['DOMAIN'] );
|
2872 |
+
} else {
|
2873 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2874 |
+
}
|
2875 |
+
?>
|
2876 |
+
<br />
|
2877 |
+
<label><?php _e( 'IP Address', 'mainwp-child' ); ?></label>
|
2878 |
+
<?php
|
2879 |
+
if ( ! empty( $scan['SCAN']['IP'] ) ) {
|
2880 |
+
echo lined_array( $scan['SCAN']['IP'] );
|
2881 |
+
} else {
|
2882 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2883 |
+
}
|
2884 |
+
?>
|
2885 |
+
<br />
|
2886 |
+
<label><?php _e( 'System details', 'mainwp-child' ); ?></label>
|
2887 |
+
<?php
|
2888 |
+
if ( ! empty( $scan['SYSTEM']['NOTICE'] ) ) {
|
2889 |
+
echo lined_array( $scan['SYSTEM']['NOTICE'] );
|
2890 |
+
} else {
|
2891 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2892 |
+
}
|
2893 |
+
?>
|
2894 |
+
<br />
|
2895 |
+
<label><?php _e( 'Information', 'mainwp-child' ); ?></label>
|
2896 |
+
<?php
|
2897 |
+
if ( ! empty( $scan['SYSTEM']['INFO'] ) ) {
|
2898 |
+
echo lined_array( $scan['SYSTEM']['INFO'] );
|
2899 |
+
} else {
|
2900 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2901 |
+
}
|
2902 |
+
?>
|
2903 |
+
<br />
|
2904 |
+
</div>
|
2905 |
+
</div>
|
2906 |
+
<div id="breadcrumbslike" class="postbox">
|
2907 |
+
<div class="handlediv" title="Click to toggle"><br /></div>
|
2908 |
+
<h3 class="hndle"><span><?php _e( 'Web application', 'mainwp-child' ); ?></span></h3>
|
2909 |
+
<div class="inside">
|
2910 |
+
<label><?php _e( 'Details', 'mainwp-child' ); ?></label>
|
2911 |
+
<?php
|
2912 |
+
if ( ! empty( $scan['WEBAPP']['INFO'] ) ) {
|
2913 |
+
echo lined_array( $scan['WEBAPP']['INFO'] );
|
2914 |
+
} else {
|
2915 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2916 |
+
}
|
2917 |
+
?>
|
2918 |
+
<br />
|
2919 |
+
<label><?php _e( 'Versions', 'mainwp-child' ); ?></label>
|
2920 |
+
<?php
|
2921 |
+
if ( ! empty( $scan['WEBAPP']['VERSION'] ) ) {
|
2922 |
+
echo lined_array( $scan['WEBAPP']['VERSION'] );
|
2923 |
+
} else {
|
2924 |
+
echo '<i>',__( 'none', 'mainwp-child' ), '</i><br />';
|
2925 |
+
}
|
2926 |
+
?>
|
2927 |
+
<br />
|
2928 |
+
<label><?php _e( 'Notices', 'mainwp-child' ); ?></label>
|
2929 |
+
<?php
|
2930 |
+
if ( ! empty( $scan['WEBAPP']['NOTICE'] ) ) {
|
2931 |
+
echo lined_array( $scan['WEBAPP']['NOTICE'] );
|
2932 |
+
} else {
|
2933 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />'; }
|
2934 |
+
?>
|
2935 |
+
<br />
|
2936 |
+
<label><?php _e( 'Errors', 'mainwp-child' ); ?></label>
|
2937 |
+
<?php
|
2938 |
+
if ( ! empty( $scan['WEBAPP']['ERROR'] ) ) {
|
2939 |
+
echo lined_array( $scan['WEBAPP']['ERROR'] );
|
2940 |
+
} else {
|
2941 |
+
echo '<i>',__( 'none', 'mainwp-child' ), '</i><br />';
|
2942 |
+
}
|
2943 |
+
?>
|
2944 |
+
<br />
|
2945 |
+
<label><?php _e( 'Warnings', 'mainwp-child' ); ?></label>
|
2946 |
+
<?php
|
2947 |
+
if ( ! empty( $scan['WEBAPP']['WARN'] ) ) {
|
2948 |
+
echo lined_array( $scan['WEBAPP']['WARN'] );
|
2949 |
+
} else {
|
2950 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2951 |
+
}
|
2952 |
+
?>
|
2953 |
+
<br />
|
2954 |
+
</div>
|
2955 |
+
</div>
|
2956 |
+
|
2957 |
+
<div id="breadcrumbslike" class="postbox">
|
2958 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2959 |
+
<h3 class="hndle"><span><?php _e( 'Links', 'mainwp-child' ); ?></span></h3>
|
2960 |
+
<div class="inside">
|
2961 |
+
<?php
|
2962 |
+
if ( ! empty( $scan['LINKS']['URL'] ) ) {
|
2963 |
+
echo lined_array( $scan['LINKS']['URL'] );
|
2964 |
+
} else {
|
2965 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2966 |
+
}
|
2967 |
+
?>
|
2968 |
+
</div>
|
2969 |
+
</div>
|
2970 |
+
|
2971 |
+
<div id="breadcrumbslike" class="postbox">
|
2972 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2973 |
+
<h3 class="hndle"><span><?php _e( 'Local Javascript', 'mainwp-child' ); ?></span></h3>
|
2974 |
+
<div class="inside">
|
2975 |
+
<?php
|
2976 |
+
if ( ! empty( $scan['LINKS']['JSLOCAL'] ) ) {
|
2977 |
+
echo lined_array( $scan['LINKS']['JSLOCAL'] );
|
2978 |
+
} else {
|
2979 |
+
echo '<i>', __( 'none', 'mainwp-child' ),'</i><br />';
|
2980 |
+
}
|
2981 |
+
?>
|
2982 |
+
</div>
|
2983 |
+
</div>
|
2984 |
+
|
2985 |
+
<div id="breadcrumbslike" class="postbox">
|
2986 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2987 |
+
<h3 class="hndle"><span><?php _e( 'External Javascript', 'mainwp-child' ); ?></span></h3>
|
2988 |
+
<div class="inside">
|
2989 |
+
<?php
|
2990 |
+
if ( ! empty( $scan['LINKS']['JSEXTERNAL'] ) ) {
|
2991 |
+
echo lined_array( $scan['LINKS']['JSEXTERNAL'] );
|
2992 |
+
} else {
|
2993 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />'; }
|
2994 |
+
?>
|
2995 |
+
</div>
|
2996 |
+
</div>
|
2997 |
+
|
2998 |
+
<div id="breadcrumbslike" class="postbox">
|
2999 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
3000 |
+
<h3 class="hndle"><span><?php esc_html_e( 'Iframes Included', 'mainwp-child' ); ?></span></h3>
|
3001 |
+
<div class="inside">
|
3002 |
+
<?php
|
3003 |
+
if ( ! empty( $scan['LINKS']['IFRAME'] ) ) {
|
3004 |
+
echo lined_array( $scan['LINKS']['IFRAME'] );
|
3005 |
+
} else {
|
3006 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
3007 |
+
}
|
3008 |
+
?>
|
3009 |
+
</div>
|
3010 |
+
</div>
|
3011 |
+
|
3012 |
+
<div id="breadcrumbslike" class="postbox">
|
3013 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
3014 |
+
<h3 class="hndle"><span><?php esc_html_e( ' Blacklisting Status', 'mainwp-child' ); ?></span></h3>
|
3015 |
+
<div class="inside">
|
3016 |
+
<?php
|
3017 |
+
if ( ! empty( $scan['BLACKLIST']['INFO'] ) ) {
|
3018 |
+
echo lined_array( $scan['BLACKLIST']['INFO'] );
|
3019 |
+
} else {
|
3020 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
3021 |
+
}
|
3022 |
+
?>
|
3023 |
+
</div>
|
3024 |
+
</div>
|
3025 |
+
|
3026 |
+
</div>
|
3027 |
+
</div>
|
3028 |
+
</div>
|
3029 |
+
<?php
|
3030 |
+
|
3031 |
+
}
|
3032 |
+
$result = ob_get_clean();
|
3033 |
+
|
3034 |
+
return array( 'result' => $result );
|
3035 |
+
}
|
3036 |
+
|
3037 |
+
|
3038 |
+
/**
|
3039 |
+
* Live setup.
|
3040 |
+
*
|
3041 |
+
* @return array|array[]
|
3042 |
+
*
|
3043 |
+
* @uses iThemes_Credentials::get_password_hash()
|
3044 |
+
* @uses ITXAPI_Helper2::get_access_token()
|
3045 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3046 |
+
* @uses \pb_backupbuddy::save()
|
3047 |
+
* @uses \pb_backupbuddy::status()
|
3048 |
+
* @uses \pb_backupbuddy_destination_stash2::stashAPI()
|
3049 |
+
* @uses \pb_backupbuddy::$options
|
3050 |
+
* @uses \pb_backupbuddy_destination_live::$default_settings
|
3051 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3052 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3053 |
+
*/
|
3054 |
+
public function live_setup() {
|
3055 |
+
|
3056 |
+
$errors = array();
|
3057 |
+
|
3058 |
+
$archive_types = array(
|
3059 |
+
'db' => __( 'Database Backup', 'mainwp-child' ),
|
3060 |
+
'full' => __( 'Full Backup', 'mainwp-child' ),
|
3061 |
+
'plugins' => __( 'Plugins Backup', 'mainwp-child' ),
|
3062 |
+
'themes' => __( 'Themes Backup', 'mainwp-child' ),
|
3063 |
+
);
|
3064 |
+
|
3065 |
+
$archive_periods = array(
|
3066 |
+
'daily',
|
3067 |
+
'weekly',
|
3068 |
+
'monthly',
|
3069 |
+
'yearly',
|
3070 |
+
);
|
3071 |
+
|
3072 |
+
if ( ( '' == $_POST['live_username'] ) || ( '' == $_POST['live_password'] ) ) { // A field is blank.
|
3073 |
+
$errors[] = 'You must enter your iThemes username & password to log in to BackupBuddy Stash Live.';
|
3074 |
+
} else { // Username and password provided.
|
3075 |
+
|
3076 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/class.itx_helper2.php';
|
3077 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php';
|
3078 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/init.php';
|
3079 |
+
|
3080 |
+
/** @global string $wp_version WordPress version. */
|
3081 |
+
global $wp_version;
|
3082 |
+
|
3083 |
+
$itxapi_username = strtolower( $_POST['live_username'] );
|
3084 |
+
$password_hash = \iThemes_Credentials::get_password_hash( $itxapi_username, $_POST['live_password'] );
|
3085 |
+
$access_token = \ITXAPI_Helper2::get_access_token( $itxapi_username, $password_hash, site_url(), $wp_version );
|
3086 |
+
|
3087 |
+
$settings = array(
|
3088 |
+
'itxapi_username' => $itxapi_username,
|
3089 |
+
'itxapi_password' => $access_token,
|
3090 |
+
);
|
3091 |
+
$response = \pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' );
|
3092 |
+
|
3093 |
+
if ( ! is_array( $response ) ) { // Error message.
|
3094 |
+
$errors[] = print_r( $response, true ); // phpcs:ignore -- debug feature.
|
3095 |
+
} else {
|
3096 |
+
if ( isset( $response['error'] ) ) {
|
3097 |
+
$errors[] = $response['error']['message'];
|
3098 |
+
} else {
|
3099 |
+
if ( isset( $response['token'] ) ) {
|
3100 |
+
$itxapi_token = $response['token'];
|
3101 |
+
} else {
|
3102 |
+
$errors[] = 'Error #2308832: Unexpected server response. Token missing. Check your BackupBuddy Stash Live login and try again. Detailed response: `' . print_r( $response, true ) . '`.'; // phpcs:ignore -- debug feature.
|
3103 |
+
}
|
3104 |
+
}
|
3105 |
+
}
|
3106 |
+
|
3107 |
+
// If we have the token then create the Live destination.
|
3108 |
+
if ( isset( $itxapi_token ) ) {
|
3109 |
+
if ( count( \pb_backupbuddy::$options['remote_destinations'] ) > 0 ) {
|
3110 |
+
$nextDestKey = max( array_keys( \pb_backupbuddy::$options['remote_destinations'] ) ) + 1;
|
3111 |
+
} else { // no destinations yet. first index.
|
3112 |
+
$nextDestKey = 0;
|
3113 |
+
}
|
3114 |
+
|
3115 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ] = \pb_backupbuddy_destination_live::$default_settings;
|
3116 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_username'] = isset( $_POST['live_username'] ) ? wp_unslash( $_POST['live_username'] ) : '';
|
3117 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_token'] = $itxapi_token;
|
3118 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['title'] = 'My BackupBuddy Stash Live';
|
3119 |
+
|
3120 |
+
// Notification email.
|
3121 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['email'] = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
|
3122 |
+
|
3123 |
+
// Archive limits.
|
3124 |
+
foreach ( $archive_types as $archive_type => $archive_type_name ) {
|
3125 |
+
foreach ( $archive_periods as $archive_period ) {
|
3126 |
+
$settings_name = 'limit_' . $archive_type . '_' . $archive_period;
|
3127 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ][ $settings_name ] = isset( $_POST['live_settings'][ $settings_name ] ) ? wp_unslash( $_POST['live_settings'][ $settings_name ] ) : '';
|
3128 |
+
}
|
3129 |
+
}
|
3130 |
+
|
3131 |
+
if ( '1' == $_POST['send_snapshot_notification'] ) {
|
3132 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = isset( $_POST['send_snapshot_notification'] ) ? wp_unslash( $_POST['send_snapshot_notification'] ) : '';
|
3133 |
+
} else {
|
3134 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = '0';
|
3135 |
+
}
|
3136 |
+
|
3137 |
+
\pb_backupbuddy::save();
|
3138 |
+
$destination_id = $nextDestKey;
|
3139 |
+
|
3140 |
+
// Send new settings for archive limiting to Stash API.
|
3141 |
+
\backupbuddy_live::send_trim_settings();
|
3142 |
+
|
3143 |
+
// Set first run of BackupBuddy Stash Live so it begins immediately.
|
3144 |
+
$cronArgs = array();
|
3145 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
3146 |
+
if ( true === $schedule_result ) {
|
3147 |
+
\pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
3148 |
+
} else {
|
3149 |
+
\pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
3150 |
+
}
|
3151 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3152 |
+
\pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
3153 |
+
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3154 |
+
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3155 |
+
}
|
3156 |
+
}
|
3157 |
+
} // end if user and pass set.
|
3158 |
+
|
3159 |
+
if ( 0 == count( $errors ) ) {
|
3160 |
+
\pb_backupbuddy::save();
|
3161 |
+
$data = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3162 |
+
return array(
|
3163 |
+
'destination_id' => $destination_id,
|
3164 |
+
'data' => $data,
|
3165 |
+
);
|
3166 |
+
} else {
|
3167 |
+
return array( 'errors' => $errors );
|
3168 |
+
}
|
3169 |
+
}
|
3170 |
+
|
3171 |
+
/**
|
3172 |
+
* Live save settings.
|
3173 |
+
*
|
3174 |
+
* @return int[]|string[] Return 1 on success or ERROR message on failure.
|
3175 |
+
*
|
3176 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3177 |
+
* @uses \pb_backupbuddy::$options
|
3178 |
+
* @uses \pb_backupbuddy::save()
|
3179 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3180 |
+
* @uses \backupbuddy_live::getLiveID()
|
3181 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3182 |
+
*/
|
3183 |
+
public function live_save_settings() {
|
3184 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : array();
|
3185 |
+
$new_destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3186 |
+
|
3187 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
3188 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live.php';
|
3189 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
3190 |
+
|
3191 |
+
$destination_id = \backupbuddy_live::getLiveID();
|
3192 |
+
$destination_settings = isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ? \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] : array();
|
3193 |
+
|
3194 |
+
$check_current = ! empty( $destination_settings ) ? true : false;
|
3195 |
+
|
3196 |
+
$error = '';
|
3197 |
+
if ( $new_destination_id && is_array( $data ) ) {
|
3198 |
+
$itxapi_username = isset( $destination_settings['itxapi_username'] ) ? $destination_settings['itxapi_username'] : '';
|
3199 |
+
$itxapi_token = isset( $destination_settings['itxapi_token'] ) ? $destination_settings['itxapi_token'] : '';
|
3200 |
+
$destination_settings = array_merge( $destination_settings, $data );
|
3201 |
+
$destination_settings['itxapi_username'] = $itxapi_username;
|
3202 |
+
$destination_settings['itxapi_token'] = $itxapi_token;
|
3203 |
+
\pb_backupbuddy::$options['remote_destinations'][ $new_destination_id ] = $destination_settings;
|
3204 |
+
|
3205 |
+
if ( $check_current && $destination_id != $new_destination_id ) {
|
3206 |
+
unset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] );
|
3207 |
+
}
|
3208 |
+
|
3209 |
+
\pb_backupbuddy::save();
|
3210 |
+
set_transient( 'backupbuddy_live_jump', array( 'daily_init', array() ), 60 * 60 * 48 ); // Tells Live process to restart from the beginning (if mid-process) so new settigns apply.
|
3211 |
+
|
3212 |
+
\backupbuddy_live::send_trim_settings();
|
3213 |
+
return array( 'ok' => 1 );
|
3214 |
+
} else {
|
3215 |
+
$error = 'Invalid data. Please check and try again.';
|
3216 |
+
}
|
3217 |
+
return array( 'error' => $error );
|
3218 |
+
}
|
3219 |
+
|
3220 |
+
/**
|
3221 |
+
* Live action disconnect.
|
3222 |
+
*
|
3223 |
+
* @return array $return Return 1 on success or ERROR message on failure.
|
3224 |
+
*
|
3225 |
+
* @uses \pb_backupbuddy::$options
|
3226 |
+
* @uses \pb_backupbuddy::save()
|
3227 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3228 |
+
*/
|
3229 |
+
public function live_action_disconnect() {
|
3230 |
+
$error = '';
|
3231 |
+
$liveDestinationID = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3232 |
+
|
3233 |
+
$return = array();
|
3234 |
+
if ( $liveDestinationID ) {
|
3235 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] ) ) {
|
3236 |
+
// Clear destination settings.
|
3237 |
+
unset( \pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] );
|
3238 |
+
\pb_backupbuddy::save();
|
3239 |
+
// Clear cached Live credentials.
|
3240 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/init.php';
|
3241 |
+
delete_transient( \pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME );
|
3242 |
+
} else {
|
3243 |
+
$error = 'Error: destination not found.';
|
3244 |
+
}
|
3245 |
+
$return['ok'] = 1;
|
3246 |
+
} else {
|
3247 |
+
$error = 'Error: Empty destination id.';
|
3248 |
+
}
|
3249 |
+
|
3250 |
+
if ( ! empty( $error ) ) {
|
3251 |
+
$return['error'] = $error;
|
3252 |
+
}
|
3253 |
+
|
3254 |
+
return $return;
|
3255 |
+
}
|
3256 |
+
|
3257 |
+
/**
|
3258 |
+
* Live action.
|
3259 |
+
*
|
3260 |
+
* @return array Return results array.
|
3261 |
+
*
|
3262 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3263 |
+
* @uses \pb_backupbuddy::$options
|
3264 |
+
* @uses \pb_backupbuddy::_GET()
|
3265 |
+
* @uses \backupbuddy_live_periodic::get_stats()
|
3266 |
+
* @uses \backupbuddy_live::getLiveID()
|
3267 |
+
* @uses \backupbuddy_live_periodic::get_destination_settings()
|
3268 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
3269 |
+
* @uses \backupbuddy_api::runLiveSnapshot()
|
3270 |
+
* @uses \backupbuddy_api::setLiveStatus()
|
3271 |
+
*/
|
3272 |
+
public function live_action() {
|
3273 |
+
$action = isset( $_POST['live_action'] ) ? sanitize_text_field( wp_unslash( $_POST['live_action'] ) ) : '';
|
3274 |
+
$error = '';
|
3275 |
+
$message = '';
|
3276 |
+
|
3277 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
3278 |
+
$state = \backupbuddy_live_periodic::get_stats();
|
3279 |
+
|
3280 |
+
$destination_id = \backupbuddy_live::getLiveID();
|
3281 |
+
$destination = \backupbuddy_live_periodic::get_destination_settings();
|
3282 |
+
|
3283 |
+
if ( 'clear_log' == $action ) {
|
3284 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
3285 |
+
unlink( $sumLogFile );
|
3286 |
+
if ( file_exists( $sumLogFile ) ) {
|
3287 |
+
$error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.';
|
3288 |
+
} else {
|
3289 |
+
$message = 'Log file cleared.';
|
3290 |
+
}
|
3291 |
+
} elseif ( 'create_snapshot' == $action ) { // < 100% backed up _OR_ ( we are on a step other than daily_init and the last_activity is more recent than the php runtime ).
|
3292 |
+
if ( true === \backupbuddy_api::runLiveSnapshot() ) {
|
3293 |
+
$message = '<h3>' . __( 'Verifying everything is up to date before Snapshot', 'mainwp-child' ) . '</h3><p class="description" style="max-width: 700px; display: inline-block;">' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'mainwp-child' ) . '</p>';
|
3294 |
+
require \pb_backupbuddy::plugin_path() . '/destinations/live/_manual_snapshot.php';
|
3295 |
+
}
|
3296 |
+
} elseif ( 'pause_periodic' == $action ) {
|
3297 |
+
$pause_continuous = '';
|
3298 |
+
$pause_periodic = true;
|
3299 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3300 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; // Update local var.
|
3301 |
+
$message = __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'mainwp-child' );
|
3302 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php';
|
3303 |
+
} elseif ( 'resume_periodic' == $action ) {
|
3304 |
+
$launchNowText = ' ' . __( 'Unpaused but not running now.', 'mainwp-child' );
|
3305 |
+
$start_run = false;
|
3306 |
+
if ( '1' != \pb_backupbuddy::_GET( 'skip_run_live_now' ) ) {
|
3307 |
+
$launchNowText = '';
|
3308 |
+
$start_run = true;
|
3309 |
+
}
|
3310 |
+
$pause_continuous = '';
|
3311 |
+
$pause_periodic = false;
|
3312 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic, $start_run );
|
3313 |
+
$message = __( 'Live File Backup has resumed.', 'mainwp-child' ) . $launchNowText;
|
3314 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php';
|
3315 |
+
} elseif ( 'pause_continuous' == $action ) {
|
3316 |
+
$pause_continuous = true;
|
3317 |
+
$pause_periodic = '';
|
3318 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3319 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3320 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php'; // Recalculate stats.
|
3321 |
+
$message = __( 'Live Database Backup paused.', 'mainwp-child' );
|
3322 |
+
} elseif ( 'resume_continuous' == $action ) {
|
3323 |
+
$pause_continuous = false;
|
3324 |
+
$pause_periodic = '';
|
3325 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3326 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; // Update local var.
|
3327 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php'; // Recalculate stats.
|
3328 |
+
$message = __( 'Live Database Backup resumed.', 'mainwp-child' );
|
3329 |
+
} else {
|
3330 |
+
$error = 'Error #1000. Invalid request.';
|
3331 |
+
}
|
3332 |
+
|
3333 |
+
return array(
|
3334 |
+
'ok' => 1,
|
3335 |
+
'_error' => $error,
|
3336 |
+
'_message' => $message,
|
3337 |
+
);
|
3338 |
+
}
|
3339 |
+
|
3340 |
+
|
3341 |
+
/**
|
3342 |
+
* Download troubleshooting.
|
3343 |
+
*
|
3344 |
+
* @return array Return results array.
|
3345 |
+
*
|
3346 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3347 |
+
* @uses \backupbuddy_live_troubleshooting::run()
|
3348 |
+
* @uses \backupbuddy_live_troubleshooting::get_raw_results()
|
3349 |
+
* @uses \backupbuddy_core::backup_prefix()
|
3350 |
+
*/
|
3351 |
+
public function download_troubleshooting() {
|
3352 |
+
require \pb_backupbuddy::plugin_path() . '/destinations/live/_troubleshooting.php';
|
3353 |
+
\backupbuddy_live_troubleshooting::run();
|
3354 |
+
$output = "**File best viewed with wordwrap OFF**\n\n" . print_r( backupbuddy_live_troubleshooting::get_raw_results(), true ); // phpcs:ignore -- debug feature.
|
3355 |
+
$backup_prefix = \backupbuddy_core::backup_prefix();
|
3356 |
+
return array(
|
3357 |
+
'output' => $output,
|
3358 |
+
'backup_prefix' => $backup_prefix,
|
3359 |
+
);
|
3360 |
+
}
|
3361 |
+
|
3362 |
+
/**
|
3363 |
+
* Get live backups.
|
3364 |
+
*
|
3365 |
+
* @return array[]|string[] Return backup list.
|
3366 |
+
*
|
3367 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3368 |
+
* @uses \pb_backupbuddy::$options
|
3369 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3370 |
+
* @uses \pb_backupbuddy_destination_stash2::listFiles()
|
3371 |
+
* @uses \pb_backupbuddy::$format::date()
|
3372 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
3373 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
3374 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
3375 |
+
* @uses \backupbuddy_core::startsWith()
|
3376 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
3377 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
3378 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
3379 |
+
*/
|
3380 |
+
public function get_live_backups() {
|
3381 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3382 |
+
// Load required files.
|
3383 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3384 |
+
|
3385 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3386 |
+
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3387 |
+
}
|
3388 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php';
|
3389 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3390 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3391 |
+
|
3392 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3393 |
+
|
3394 |
+
if ( 'live' == $destination['type'] ) {
|
3395 |
+
$remotePath = 'snapshot-';
|
3396 |
+
$site_only = true;
|
3397 |
+
} else {
|
3398 |
+
// Get list of files for this site.
|
3399 |
+
$remotePath = 'backup-';
|
3400 |
+
$site_only = true;
|
3401 |
+
}
|
3402 |
+
|
3403 |
+
$files = \pb_backupbuddy_destination_stash2::listFiles( $settings, '', $site_only ); // 2nd param was $remotePath.
|
3404 |
+
if ( ! is_array( $files ) ) {
|
3405 |
+
return array( 'error' => 'Error #892329c: ' . $files );
|
3406 |
+
}
|
3407 |
+
|
3408 |
+
$backup_list_temp = array();
|
3409 |
+
foreach ( (array) $files as $file ) {
|
3410 |
+
|
3411 |
+
if ( ( '' != $remotePath ) && ( ! \backupbuddy_core::startsWith( basename( $file['filename'] ), $remotePath ) ) ) { // Only show backups for this site unless set to show all.
|
3412 |
+
continue;
|
3413 |
+
}
|
3414 |
+
|
3415 |
+
$last_modified = $file['uploaded_timestamp'];
|
3416 |
+
$size = (float) $file['size'];
|
3417 |
+
$backup_type = \backupbuddy_core::getBackupTypeFromFile( $file['filename'], $quiet = false, $skip_fileoptions = true );
|
3418 |
+
|
3419 |
+
// Generate array of table rows.
|
3420 |
+
while ( isset( $backup_list_temp[ $last_modified ] ) ) { // Avoid collisions.
|
3421 |
+
$last_modified += 0.1;
|
3422 |
+
}
|
3423 |
+
|
3424 |
+
if ( 'live' == $destination['type'] ) {
|
3425 |
+
$backup_list_temp[ $last_modified ] = array(
|
3426 |
+
array( base64_encode( $file['url'] ), '<span class="backupbuddy-stash-file-list-title">' . \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span></span><br><span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3427 |
+
\pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
3428 |
+
\pb_backupbuddy::$format->file_size( $size ),
|
3429 |
+
\backupbuddy_core::pretty_backup_type( $backup_type ),
|
3430 |
+
);
|
3431 |
+
} else {
|
3432 |
+
$backup_list_temp[ $last_modified ] = array(
|
3433 |
+
array( base64_encode( $file['url'] ), '<span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- to compatible http encoding.
|
3434 |
+
\pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
3435 |
+
\pb_backupbuddy::$format->file_size( $size ),
|
3436 |
+
\backupbuddy_core::pretty_backup_type( $backup_type ),
|
3437 |
+
);
|
3438 |
+
}
|
3439 |
+
}
|
3440 |
+
|
3441 |
+
krsort( $backup_list_temp );
|
3442 |
+
$backup_list = array();
|
3443 |
+
foreach ( $backup_list_temp as $backup_item ) {
|
3444 |
+
$backup_list[ $backup_item[0][0] ] = $backup_item;
|
3445 |
+
}
|
3446 |
+
unset( $backup_list_temp );
|
3447 |
+
|
3448 |
+
return array( 'backup_list' => $backup_list );
|
3449 |
+
}
|
3450 |
+
|
3451 |
+
/**
|
3452 |
+
* Copy file to local.
|
3453 |
+
*
|
3454 |
+
* @return int[]|string[] Return 1 on success and ERROR message on failure.
|
3455 |
+
*
|
3456 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3457 |
+
* @uses \pb_backupbuddy::$options
|
3458 |
+
* @uses \pb_backupbuddy::status()
|
3459 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3460 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3461 |
+
*
|
3462 |
+
*/
|
3463 |
+
public function copy_file_to_local() {
|
3464 |
+
|
3465 |
+
$file = isset( $_POST['cpy_file'] ) ? base64_decode( wp_unslash( $_POST['cpy_file'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3466 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3467 |
+
|
3468 |
+
// Load required files.
|
3469 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3470 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3471 |
+
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3472 |
+
}
|
3473 |
+
|
3474 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3475 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3476 |
+
|
3477 |
+
\pb_backupbuddy::status( 'details', 'Scheduling Cron for creating Stash copy.' );
|
3478 |
+
\backupbuddy_core::schedule_single_event( time(), 'process_remote_copy', array( 'stash2', $file, $settings ) );
|
3479 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3480 |
+
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3481 |
+
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3482 |
+
}
|
3483 |
+
return array( 'ok' => 1 );
|
3484 |
+
}
|
3485 |
+
|
3486 |
+
/**
|
3487 |
+
* Delete backup file.
|
3488 |
+
*
|
3489 |
+
* @return int[]|string[] Return 1 on success and ERROR message on failure.
|
3490 |
+
*
|
3491 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3492 |
+
* @uses \pb_backupbuddy::$options
|
3493 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3494 |
+
* @uses \pb_backupbuddy_destination_stash2::strrpos_count()
|
3495 |
+
* @uses \pb_backupbuddy_destination_stash2::deleteFiles()
|
3496 |
+
*/
|
3497 |
+
public function delete_file_backup() {
|
3498 |
+
// Handle deletion.
|
3499 |
+
$files = isset( $_POST['items'] ) ? wp_unslash( $_POST['items'] ) : array();
|
3500 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3501 |
+
|
3502 |
+
// Load required files.
|
3503 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3504 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3505 |
+
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3506 |
+
}
|
3507 |
+
|
3508 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3509 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3510 |
+
|
3511 |
+
$deleteFiles = array();
|
3512 |
+
foreach ( (array) $files as $file ) {
|
3513 |
+
$file = base64_decode( $file ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3514 |
+
|
3515 |
+
$startPos = \pb_backupbuddy_destination_stash2::strrpos_count( $file, '/', 2 ) + 1; // next to last slash.
|
3516 |
+
$file = substr( $file, $startPos );
|
3517 |
+
if ( false !== strstr( $file, '?' ) ) {
|
3518 |
+
$file = substr( $file, 0, strpos( $file, '?' ) );
|
3519 |
+
}
|
3520 |
+
$deleteFiles[] = $file;
|
3521 |
+
}
|
3522 |
+
$response = \pb_backupbuddy_destination_stash2::deleteFiles( $settings, $deleteFiles );
|
3523 |
+
|
3524 |
+
if ( true === $response ) {
|
3525 |
+
$msg = 'Deleted ' . implode( ', ', $deleteFiles ) . '.';
|
3526 |
+
} else {
|
3527 |
+
$msg = 'Failed to delete one or more files. Details: `' . $response . '`.';
|
3528 |
+
}
|
3529 |
+
|
3530 |
+
return array(
|
3531 |
+
'ok' => 1,
|
3532 |
+
'msg' => $msg,
|
3533 |
+
);
|
3534 |
+
}
|
3535 |
+
|
3536 |
+
/**
|
3537 |
+
* Get live stats.
|
3538 |
+
*
|
3539 |
+
* @return array|string[] Return json encoded results or ERROR message on failure.
|
3540 |
+
*
|
3541 |
+
* @uses \backupbuddy_api::getLiveStats()
|
3542 |
+
* @uses \backupbuddy_core::detectLikelyHighestExecutionTime()
|
3543 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3544 |
+
* @uses \backupbuddy_live::getLiveID();
|
3545 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3546 |
+
* @uses \pb_backupbuddy::$options
|
3547 |
+
* @uses \pb_backupbuddy::status()
|
3548 |
+
*/
|
3549 |
+
public function get_live_stats() {
|
3550 |
+
|
3551 |
+
// Check if running PHP 5.3+.
|
3552 |
+
$php_minimum = 5.3;
|
3553 |
+
if ( version_compare( PHP_VERSION, $php_minimum, '<' ) ) { // Server's PHP is insufficient.
|
3554 |
+
return array( 'error' => '-1' );
|
3555 |
+
}
|
3556 |
+
|
3557 |
+
$stats = \backupbuddy_api::getLiveStats();
|
3558 |
+
|
3559 |
+
if ( false === $stats ) { // Live is disconnected.
|
3560 |
+
return array( 'error' => '-1' );
|
3561 |
+
}
|
3562 |
+
|
3563 |
+
// If there is more to do and too long of time has passed since activity then try to jumpstart the process at the beginning.
|
3564 |
+
if ( ( ( 0 == $stats['files_total'] ) || ( $stats['files_sent'] < $stats['files_total'] ) ) && ( 'wait_on_transfers' != $stats['current_function'] ) ) { // ( Files to send not yet calculated OR more remain to send ) AND not on the wait_on_transfers step.
|
3565 |
+
$time_since_last_activity = microtime( true ) - $stats['last_periodic_activity'];
|
3566 |
+
|
3567 |
+
if ( $time_since_last_activity >= 30 ) { // More than 30 seconds since last activity.
|
3568 |
+
|
3569 |
+
// Detect max PHP execution time. If TESTED value is higher than PHP value then go with that since we want to err on not overlapping processes here.
|
3570 |
+
$detected_execution = \backupbuddy_core::detectLikelyHighestExecutionTime();
|
3571 |
+
|
3572 |
+
if ( $time_since_last_activity > ( $detected_execution + \backupbuddy_constants::TIMED_OUT_PROCESS_RESUME_WIGGLE_ROOM ) ) { // Enough time has passed to assume timed out.
|
3573 |
+
|
3574 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live.php';
|
3575 |
+
$liveID = \backupbuddy_live::getLiveID();
|
3576 |
+
if ( false === $liveID ) {
|
3577 |
+
die( '-1' );
|
3578 |
+
}
|
3579 |
+
if ( '1' != \pb_backupbuddy::$options['remote_destinations'][ $liveID ]['pause_periodic'] ) { // Only proceed if NOT paused.
|
3580 |
+
|
3581 |
+
\pb_backupbuddy::status( 'warning', 'BackupBuddy Stash Live process appears timed out while user it viewing Live page. Forcing run now.' );
|
3582 |
+
|
3583 |
+
$cronArgs = array();
|
3584 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
3585 |
+
if ( true === $schedule_result ) {
|
3586 |
+
\pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
3587 |
+
} else {
|
3588 |
+
\pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
3589 |
+
}
|
3590 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3591 |
+
\pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
3592 |
+
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3593 |
+
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3594 |
+
}
|
3595 |
+
}
|
3596 |
+
}
|
3597 |
+
}
|
3598 |
+
}
|
3599 |
+
|
3600 |
+
return array( 'result' => wp_json_encode( $stats ) );
|
3601 |
+
}
|
3602 |
+
|
3603 |
+
/**
|
3604 |
+
* Save license settings.
|
3605 |
+
*
|
3606 |
+
* @return bool|int[] Return 1 on success and FALSE on failure.
|
3607 |
+
*/
|
3608 |
+
public function save_license_settings() {
|
3609 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : false;
|
3610 |
+
if ( is_array( $settings ) && isset( $GLOBALS['ithemes-updater-settings'] ) ) {
|
3611 |
+
$GLOBALS['ithemes-updater-settings']->update_options( $settings );
|
3612 |
+
return array( 'ok' => 1 );
|
3613 |
+
}
|
3614 |
+
return false;
|
3615 |
+
}
|
3616 |
+
|
3617 |
+
/**
|
3618 |
+
* Load product license.
|
3619 |
+
*
|
3620 |
+
* @return array Return results array.
|
3621 |
+
*
|
3622 |
+
* @uses Ithemes_Updater_Packages::get_full_details()
|
3623 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3624 |
+
*/
|
3625 |
+
public function load_products_license() {
|
3626 |
+
$packages = array();
|
3627 |
+
$packages_name = array();
|
3628 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3629 |
+
|
3630 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3631 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3632 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3633 |
+
|
3634 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3635 |
+
|
3636 |
+
$details = \Ithemes_Updater_Packages::get_full_details();
|
3637 |
+
$packages = isset( $details['packages'] ) ? $details['packages'] : array();
|
3638 |
+
if ( is_array( $packages ) ) {
|
3639 |
+
foreach ( $packages as $path => $data ) {
|
3640 |
+
$packages_name[ $path ] = \Ithemes_Updater_Functions::get_package_name( $data['package'] );
|
3641 |
+
}
|
3642 |
+
}
|
3643 |
+
}
|
3644 |
+
return array(
|
3645 |
+
'ok' => 1,
|
3646 |
+
'packages' => $packages,
|
3647 |
+
'packages_name' => $packages_name,
|
3648 |
+
);
|
3649 |
+
}
|
3650 |
+
|
3651 |
+
/**
|
3652 |
+
* Activate package.
|
3653 |
+
*
|
3654 |
+
* @return array $return Return response array.
|
3655 |
+
*
|
3656 |
+
* @uses Ithemes_Updater_API::activate_package()
|
3657 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3658 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_error_explanation()
|
3659 |
+
*/
|
3660 |
+
public function activate_package() {
|
3661 |
+
|
3662 |
+
$username = isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '';
|
3663 |
+
$password = isset( $_POST['password'] ) ? wp_unslash( $_POST['password'] ) : '';
|
3664 |
+
$packages = isset( $_POST['packages'] ) ? wp_unslash( $_POST['packages'] ) : '';
|
3665 |
+
|
3666 |
+
$return = array( 'ok' => 1 );
|
3667 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3668 |
+
|
3669 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3670 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3671 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3672 |
+
|
3673 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3674 |
+
|
3675 |
+
$response = \Ithemes_Updater_API::activate_package( $username, $password, $packages );
|
3676 |
+
|
3677 |
+
if ( is_wp_error( $response ) ) {
|
3678 |
+
$errors[] = $this->get_error_explanation( $response );
|
3679 |
+
$return['errors'] = $errors;
|
3680 |
+
return $return;
|
3681 |
+
}
|
3682 |
+
|
3683 |
+
if ( empty( $response['packages'] ) ) {
|
3684 |
+
$errors[] = __( 'An unknown server error occurred. Please try to license your products again at another time.', 'mainwp-child' );
|
3685 |
+
$return['errors'] = $errors;
|
3686 |
+
return $return;
|
3687 |
+
}
|
3688 |
+
|
3689 |
+
uksort( $response['packages'], 'strnatcasecmp' );
|
3690 |
+
|
3691 |
+
$success = array();
|
3692 |
+
$warn = array();
|
3693 |
+
$fail = array();
|
3694 |
+
|
3695 |
+
foreach ( $response['packages'] as $package => $data ) {
|
3696 |
+
if ( preg_match( '/ \|\|\| \d+$/', $package ) ) {
|
3697 |
+
continue;
|
3698 |
+
}
|
3699 |
+
|
3700 |
+
$name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3701 |
+
|
3702 |
+
if ( ! empty( $data['key'] ) ) {
|
3703 |
+
$success[] = $name;
|
3704 |
+
} elseif ( ! empty( $data['status'] ) && ( 'expired' == $data['status'] ) ) {
|
3705 |
+
$warn[ $name ] = __( 'Your product subscription has expired', 'mainwp-child' );
|
3706 |
+
} else {
|
3707 |
+
$fail[ $name ] = $data['error']['message'];
|
3708 |
+
}
|
3709 |
+
}
|
3710 |
+
|
3711 |
+
if ( ! empty( $success ) ) {
|
3712 |
+
$messages[] = wp_sprintf( __( 'Successfully licensed %l.', 'mainwp-child' ), $success );
|
3713 |
+
$return['messages'] = $messages;
|
3714 |
+
}
|
3715 |
+
|
3716 |
+
if ( ! empty( $fail ) ) {
|
3717 |
+
foreach ( $fail as $name => $reason ) {
|
3718 |
+
$errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'mainwp-child' ), $name, $reason );
|
3719 |
+
}
|
3720 |
+
$return['errors'] = $errors;
|
3721 |
+
}
|
3722 |
+
|
3723 |
+
if ( ! empty( $warn ) ) {
|
3724 |
+
foreach ( $warn as $name => $reason ) {
|
3725 |
+
$soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'mainwp-child' ), $name, $reason );
|
3726 |
+
}
|
3727 |
+
$return['soft_errors'] = $soft_errors;
|
3728 |
+
}
|
3729 |
+
}
|
3730 |
+
return $return;
|
3731 |
+
}
|
3732 |
+
|
3733 |
+
/**
|
3734 |
+
* Deactivate package.
|
3735 |
+
*
|
3736 |
+
* @param array $data Data array.
|
3737 |
+
*
|
3738 |
+
* @return array return$ Return response array.
|
3739 |
+
*
|
3740 |
+
* @uses Ithemes_Updater_API::deactivate_package()
|
3741 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3742 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_error_explanation()
|
3743 |
+
*/
|
3744 |
+
public function deactivate_package( $data ) {
|
3745 |
+
|
3746 |
+
$username = isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '';
|
3747 |
+
$password = isset( $_POST['password'] ) ? wp_unslash( $_POST['password'] ) : '';
|
3748 |
+
$packages = isset( $_POST['packages'] ) ? wp_unslash( $_POST['packages'] ) : '';
|
3749 |
+
|
3750 |
+
$return = array( 'ok' => 1 );
|
3751 |
+
|
3752 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3753 |
+
|
3754 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3755 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3756 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3757 |
+
|
3758 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3759 |
+
|
3760 |
+
$response = \Ithemes_Updater_API::deactivate_package( $username, $password, $packages );
|
3761 |
+
|
3762 |
+
if ( is_wp_error( $response ) ) {
|
3763 |
+
$errors[] = $this->get_error_explanation( $response );
|
3764 |
+
$return['errors'] = $errors;
|
3765 |
+
return $return;
|
3766 |
+
}
|
3767 |
+
|
3768 |
+
if ( empty( $response['packages'] ) ) {
|
3769 |
+
$errors[] = __( 'An unknown server error occurred. Please try to remove licenses from your products again at another time.', 'it-l10n-mainwp-backupbuddy' );
|
3770 |
+
$return['errors'] = $errors;
|
3771 |
+
return $return;
|
3772 |
+
}
|
3773 |
+
|
3774 |
+
uksort( $response['packages'], 'strnatcasecmp' );
|
3775 |
+
|
3776 |
+
$success = array();
|
3777 |
+
$fail = array();
|
3778 |
+
|
3779 |
+
foreach ( $response['packages'] as $package => $data ) {
|
3780 |
+
if ( preg_match( '/ \|\|\| \d+$/', $package ) ) {
|
3781 |
+
continue;
|
3782 |
+
}
|
3783 |
+
|
3784 |
+
$name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3785 |
+
|
3786 |
+
if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) ) {
|
3787 |
+
$success[] = $name;
|
3788 |
+
} elseif ( isset( $data['error'] ) && isset( $data['error']['message'] ) ) {
|
3789 |
+
$fail[ $name ] = $data['error']['message'];
|
3790 |
+
} else {
|
3791 |
+
$fail[ $name ] = __( 'Unknown server error.', 'it-l10n-mainwp-backupbuddy' );
|
3792 |
+
}
|
3793 |
+
}
|
3794 |
+
|
3795 |
+
if ( ! empty( $success ) ) {
|
3796 |
+
$messages[] = wp_sprintf( _n( 'Successfully removed license from %l.', 'Successfully removed licenses from %l.', count( $success ), 'it-l10n-mainwp-backupbuddy' ), $success );
|
3797 |
+
$return['messages'] = $messages;
|
3798 |
+
}
|
3799 |
+
|
3800 |
+
if ( ! empty( $fail ) ) {
|
3801 |
+
foreach ( $fail as $name => $reason ) {
|
3802 |
+
$errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-mainwp-backupbuddy' ), $name, $reason );
|
3803 |
+
}
|
3804 |
+
$return['errors'] = $errors;
|
3805 |
+
|
3806 |
+
}
|
3807 |
+
}
|
3808 |
+
return $return;
|
3809 |
+
}
|
3810 |
+
|
3811 |
+
/**
|
3812 |
+
* Get error code.
|
3813 |
+
*
|
3814 |
+
* @param $error Returned error to get code for: Bad_Login, Username_Unknown, Username_Invalid, Package_Unknown,
|
3815 |
+
* Too_Many_Sites, Generate_Failed.
|
3816 |
+
* @param string $package Ithemes package.
|
3817 |
+
*
|
3818 |
+
* @return string $message Return ERROR message to display.
|
3819 |
+
*
|
3820 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3821 |
+
*/
|
3822 |
+
private function get_error_explanation( $error, $package = '' ) {
|
3823 |
+
$code = $error->get_error_code();
|
3824 |
+
$package_name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3825 |
+
$message = '';
|
3826 |
+
|
3827 |
+
switch ( $code ) {
|
3828 |
+
case 'ITXAPI_Updater_Bad_Login':
|
3829 |
+
$message = __( 'Incorrect password. Please make sure that you are supplying your iThemes membership username and password details.', 'it-l10n-mainwp-backupbuddy' );
|
3830 |
+
break;
|
3831 |
+
case 'ITXAPI_Updater_Username_Unknown':
|
3832 |
+
case 'ITXAPI_Updater_Username_Invalid':
|
3833 |
+
$message = __( 'Invalid username. Please make sure that you are supplying your iThemes membership username and password details.', 'it-l10n-mainwp-backupbuddy' );
|
3834 |
+
break;
|
3835 |
+
case 'ITXAPI_Product_Package_Unknown':
|
3836 |
+
$message = sprintf( __( 'The licensing server reports that the %1$s (%2$s) product is unknown. Please contact support for assistance.', 'it-l10n-mainwp-backupbuddy' ), $package_name, $package );
|
3837 |
+
break;
|
3838 |
+
case 'ITXAPI_Updater_Too_Many_Sites':
|
3839 |
+
$message = sprintf( __( '%1$s could not be licensed since the membership account is out of available licenses for this product. You can unlicense the product on other sites or upgrade your membership to one with a higher number of licenses in order to increase the amount of available licenses.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3840 |
+
break;
|
3841 |
+
case 'ITXAPI_License_Key_Generate_Failed':
|
3842 |
+
$message = sprintf( __( '%1$s could not be licensed due to an internal error. Please try to license %2$s again at a later time. If this problem continues, please contact iThemes support.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3843 |
+
break;
|
3844 |
+
}
|
3845 |
+
|
3846 |
+
if ( empty( $message ) ) {
|
3847 |
+
if ( ! empty( $package ) ) {
|
3848 |
+
$message = sprintf( __( 'An unknown error relating to the %1$s product occurred. Please contact iThemes support. Error details: %2$s', 'it-l10n-mainwp-backupbuddy' ), $package_name, $error->get_error_message() . " ($code)" );
|
3849 |
+
} else {
|
3850 |
+
$message = sprintf( __( 'An unknown error occurred. Please contact iThemes support. Error details: %s', 'it-l10n-mainwp-backupbuddy' ), $error->get_error_message() . " ($code)" );
|
3851 |
+
}
|
3852 |
+
}
|
3853 |
+
|
3854 |
+
return $message;
|
3855 |
+
}
|
3856 |
+
|
3857 |
+
|
3858 |
+
|
3859 |
+
}
|
class/class-mainwp-child-back-up-wordpress.php
CHANGED
@@ -1,1430 +1,1428 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP BackUpWordPress
|
4 |
-
*
|
5 |
-
* MainWP BackUpWordPress Extension handler.
|
6 |
-
* Extension URL: https://mainwp.com/extension/backupwordpress/
|
7 |
-
*
|
8 |
-
* @package MainWP\Child
|
9 |
-
*
|
10 |
-
* Credits
|
11 |
-
*
|
12 |
-
* Plugin-Name: BackUpWordPress
|
13 |
-
* Plugin URI: http://bwp.hmn.md/
|
14 |
-
* Author: Human Made Limited
|
15 |
-
* Author URI: http://hmn.md/
|
16 |
-
* Licence: GPL-2+
|
17 |
-
*/
|
18 |
-
|
19 |
-
namespace MainWP\Child;
|
20 |
-
|
21 |
-
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- required to achieve desired results, pull request solutions appreciated.
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Class MainWP_Child_Back_Up_WordPress
|
25 |
-
*
|
26 |
-
* MainWP BackUpWordPress Extension handler.
|
27 |
-
*/
|
28 |
-
class MainWP_Child_Back_Up_WordPress {
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Public static variable to hold the single instance of the class.
|
32 |
-
*
|
33 |
-
* @var mixed Default null
|
34 |
-
*/
|
35 |
-
public static $instance = null;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Public variable to hold the infomration if the BackUpWordPress plugin is installed on the child site.
|
39 |
-
*
|
40 |
-
* @var bool If BackUpWordPress intalled, return true, if not, return false.
|
41 |
-
*/
|
42 |
-
public $is_plugin_installed = false;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Method instance()
|
46 |
-
*
|
47 |
-
* Create a public static instance.
|
48 |
-
*
|
49 |
-
* @return mixed Class instance.
|
50 |
-
*/
|
51 |
-
public static function instance() {
|
52 |
-
if ( null === self::$instance ) {
|
53 |
-
self::$instance = new self();
|
54 |
-
}
|
55 |
-
return self::$instance;
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* MainWP_Child_Back_Up_WordPress constructor.
|
60 |
-
*
|
61 |
-
* Run any time the class is called.
|
62 |
-
*
|
63 |
-
* @uses is_plugin_active() Determines whether a plugin is active.
|
64 |
-
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
|
65 |
-
*/
|
66 |
-
public function __construct() {
|
67 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
68 |
-
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
69 |
-
$this->is_plugin_installed = true;
|
70 |
-
if ( version_compare( phpversion(), '5.3', '>=' ) ) {
|
71 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
72 |
-
}
|
73 |
-
}
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Method init()
|
78 |
-
*
|
79 |
-
* Initiate action hooks.
|
80 |
-
*
|
81 |
-
* @uses get_option() Retrieves an option value based on an option name.
|
82 |
-
* @see https://developer.wordpress.org/reference/functions/get_option/
|
83 |
-
*
|
84 |
-
* @return void
|
85 |
-
*/
|
86 |
-
public function init() {
|
87 |
-
if ( version_compare( phpversion(), '5.3', '<' ) ) {
|
88 |
-
return;
|
89 |
-
}
|
90 |
-
|
91 |
-
if ( ! $this->is_plugin_installed ) {
|
92 |
-
return;
|
93 |
-
}
|
94 |
-
|
95 |
-
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
96 |
-
|
97 |
-
if ( 'hide' === get_option( 'mainwp_backupwordpress_hide_plugin' ) ) {
|
98 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
99 |
-
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
100 |
-
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
101 |
-
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
102 |
-
}
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
107 |
-
*
|
108 |
-
* @param array $slugs Array containing installed plugins slugs.
|
109 |
-
*
|
110 |
-
* @return array $slugs Array containing installed plugins slugs.
|
111 |
-
*/
|
112 |
-
public function hide_update_notice( $slugs ) {
|
113 |
-
$slugs[] = 'backupwordpress/backupwordpress.php';
|
114 |
-
return $slugs;
|
115 |
-
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
119 |
-
*
|
120 |
-
* @param object $value Object containing update information.
|
121 |
-
*
|
122 |
-
* @return object $value Object containing update information.
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
*
|
143 |
-
*
|
144 |
-
* @uses
|
145 |
-
*
|
146 |
-
* @uses MainWP_Child_Back_Up_WordPress::set_showhide() Hide or unhide the BackUpWordPress plugin.
|
147 |
-
* @uses MainWP_Child_Back_Up_WordPress::delete_schedule() Delete backup schedule.
|
148 |
-
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_request_cancel_backup() Cancel backup process.
|
149 |
-
* @uses MainWP_Child_Back_Up_WordPress::get_backup_status() Get the bacukp process status.
|
150 |
-
* @uses MainWP_Child_Back_Up_WordPress::reload_backups() Reload backups.
|
151 |
-
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_request_delete_backup() Delete backup.
|
152 |
-
* @uses MainWP_Child_Back_Up_WordPress::run_schedule() Run schedules.
|
153 |
-
* @uses MainWP_Child_Back_Up_WordPress::save_all_schedules() Save all schedules.
|
154 |
-
* @uses MainWP_Child_Back_Up_WordPress::update_schedule() Update schedule.
|
155 |
-
* @uses MainWP_Child_Back_Up_WordPress::get_excluded() Get excluded files.
|
156 |
-
* @uses MainWP_Child_Back_Up_WordPress::directory_browse() Browse directory.
|
157 |
-
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_add_exclude_rule() Add exclusion rule.
|
158 |
-
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_remove_exclude_rule() Remove exclusion rule.
|
159 |
-
* @uses MainWP_Child_Back_Up_WordPress::general_exclude_add_rule() General exclusion rules.
|
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 |
-
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
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 |
-
* @uses MainWP_Helper::
|
271 |
-
*
|
272 |
-
*
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
$schedules
|
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 |
-
* @uses
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
*
|
324 |
-
*
|
325 |
-
* @
|
326 |
-
*
|
327 |
-
* @uses
|
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 |
-
* @uses MainWP_Helper::update_option() Update database option by option name.
|
376 |
-
*
|
377 |
-
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
$
|
383 |
-
|
384 |
-
$information
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
*
|
391 |
-
*
|
392 |
-
* @
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
$information['result'] = '
|
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 |
-
$status
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
$information['scheduleStatus'] = $
|
444 |
-
}
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
$information
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
*
|
455 |
-
*
|
456 |
-
* @
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
$
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
$information
|
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 |
-
$backups_path = str_replace( \HM\BackUpWordPress\
|
575 |
-
}
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
$information['
|
580 |
-
|
581 |
-
$information
|
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 |
-
<th scope="col"><?php
|
639 |
-
<th scope="col"><?php esc_html_e( '
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
$html
|
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 |
-
$information
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
*
|
809 |
-
*
|
810 |
-
* @param
|
811 |
-
* @param object $
|
812 |
-
* @param
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
<?php
|
825 |
-
<div class="dashicons dashicons-
|
826 |
-
<?php }
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
$is_default_rule = ( in_array( $exclude, $
|
837 |
-
}
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
<?php esc_html_e( '
|
843 |
-
<?php
|
844 |
-
<?php
|
845 |
-
<?php
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
*
|
858 |
-
*
|
859 |
-
* @param
|
860 |
-
* @param
|
861 |
-
* @param string $
|
862 |
-
* @param
|
863 |
-
* @param
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
*
|
886 |
-
*
|
887 |
-
* @param
|
888 |
-
* @param string $
|
889 |
-
* @param
|
890 |
-
* @param
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
<th
|
898 |
-
<th scope="col"
|
899 |
-
|
900 |
-
<th scope="col"
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
<?php echo esc_html(
|
923 |
-
<?php }
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
$size = $
|
935 |
-
}
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
<?php
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
esc_html_e( '
|
957 |
-
}
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
*
|
969 |
-
*
|
970 |
-
* @param
|
971 |
-
* @param
|
972 |
-
* @param
|
973 |
-
* @param
|
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 |
-
<?php
|
1000 |
-
<div class="dashicons dashicons-
|
1001 |
-
<?php } elseif ( $file->
|
1002 |
-
<div class="dashicons dashicons-
|
1003 |
-
<?php }
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
<code
|
1013 |
-
<?php } elseif ( $file->
|
1014 |
-
<code title="<?php echo esc_attr( wp_normalize_path( $file->
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
<code
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
$size = $
|
1041 |
-
}
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
<?php
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
esc_html_e( '
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
<?php
|
1079 |
-
<strong
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
*
|
1101 |
-
*
|
1102 |
-
* @
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
$
|
1108 |
-
$out
|
1109 |
-
$
|
1110 |
-
|
1111 |
-
$out
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
*
|
1118 |
-
*
|
1119 |
-
* @
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
$
|
1131 |
-
|
1132 |
-
$
|
1133 |
-
|
1134 |
-
$schedule->
|
1135 |
-
|
1136 |
-
$
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
$
|
1145 |
-
|
1146 |
-
$out
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
*
|
1153 |
-
*
|
1154 |
-
* @
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
$
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
$schedule->set_excludes( array_diff( $excludes
|
1172 |
-
}
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
$
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
$
|
1185 |
-
|
1186 |
-
|
1187 |
-
$out
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
*
|
1194 |
-
*
|
1195 |
-
* @
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
$
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
$un_exclude_paths
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
$
|
1237 |
-
|
1238 |
-
$schedule->set_excludes( array_diff( $excludes
|
1239 |
-
}
|
1240 |
-
$schedule->
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
*
|
1251 |
-
*
|
1252 |
-
* @
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
'
|
1266 |
-
'
|
1267 |
-
'
|
1268 |
-
|
1269 |
-
|
1270 |
-
);
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
$out['result'] = '
|
1286 |
-
}
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
$out
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
*
|
1310 |
-
*
|
1311 |
-
* @
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
'
|
1330 |
-
'
|
1331 |
-
'
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
*
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
*
|
1381 |
-
*
|
1382 |
-
* @
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
*
|
1399 |
-
*
|
1400 |
-
*
|
1401 |
-
* @
|
1402 |
-
*
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
*
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
}
|
1430 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP BackUpWordPress
|
4 |
+
*
|
5 |
+
* MainWP BackUpWordPress Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/backupwordpress/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*
|
10 |
+
* Credits
|
11 |
+
*
|
12 |
+
* Plugin-Name: BackUpWordPress
|
13 |
+
* Plugin URI: http://bwp.hmn.md/
|
14 |
+
* Author: Human Made Limited
|
15 |
+
* Author URI: http://hmn.md/
|
16 |
+
* Licence: GPL-2+
|
17 |
+
*/
|
18 |
+
|
19 |
+
namespace MainWP\Child;
|
20 |
+
|
21 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- required to achieve desired results, pull request solutions appreciated.
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Class MainWP_Child_Back_Up_WordPress
|
25 |
+
*
|
26 |
+
* MainWP BackUpWordPress Extension handler.
|
27 |
+
*/
|
28 |
+
class MainWP_Child_Back_Up_WordPress {
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Public static variable to hold the single instance of the class.
|
32 |
+
*
|
33 |
+
* @var mixed Default null
|
34 |
+
*/
|
35 |
+
public static $instance = null;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Public variable to hold the infomration if the BackUpWordPress plugin is installed on the child site.
|
39 |
+
*
|
40 |
+
* @var bool If BackUpWordPress intalled, return true, if not, return false.
|
41 |
+
*/
|
42 |
+
public $is_plugin_installed = false;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Method instance()
|
46 |
+
*
|
47 |
+
* Create a public static instance.
|
48 |
+
*
|
49 |
+
* @return mixed Class instance.
|
50 |
+
*/
|
51 |
+
public static function instance() {
|
52 |
+
if ( null === self::$instance ) {
|
53 |
+
self::$instance = new self();
|
54 |
+
}
|
55 |
+
return self::$instance;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* MainWP_Child_Back_Up_WordPress constructor.
|
60 |
+
*
|
61 |
+
* Run any time the class is called.
|
62 |
+
*
|
63 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
64 |
+
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
|
65 |
+
*/
|
66 |
+
public function __construct() {
|
67 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
68 |
+
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
69 |
+
$this->is_plugin_installed = true;
|
70 |
+
if ( version_compare( phpversion(), '5.3', '>=' ) ) {
|
71 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Method init()
|
78 |
+
*
|
79 |
+
* Initiate action hooks.
|
80 |
+
*
|
81 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
82 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
83 |
+
*
|
84 |
+
* @return void
|
85 |
+
*/
|
86 |
+
public function init() {
|
87 |
+
if ( version_compare( phpversion(), '5.3', '<' ) ) {
|
88 |
+
return;
|
89 |
+
}
|
90 |
+
|
91 |
+
if ( ! $this->is_plugin_installed ) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
96 |
+
|
97 |
+
if ( 'hide' === get_option( 'mainwp_backupwordpress_hide_plugin' ) ) {
|
98 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
99 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
100 |
+
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
101 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
107 |
+
*
|
108 |
+
* @param array $slugs Array containing installed plugins slugs.
|
109 |
+
*
|
110 |
+
* @return array $slugs Array containing installed plugins slugs.
|
111 |
+
*/
|
112 |
+
public function hide_update_notice( $slugs ) {
|
113 |
+
$slugs[] = 'backupwordpress/backupwordpress.php';
|
114 |
+
return $slugs;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
119 |
+
*
|
120 |
+
* @param object $value Object containing update information.
|
121 |
+
*
|
122 |
+
* @return object $value Object containing update information.
|
123 |
+
*
|
124 |
+
* @uses \MainWP\Child\MainWP_Helper::is_updates_screen()
|
125 |
+
*/
|
126 |
+
public function remove_update_nag( $value ) {
|
127 |
+
if ( isset( $_POST['mainwpsignature'] ) ) {
|
128 |
+
return $value;
|
129 |
+
}
|
130 |
+
|
131 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
132 |
+
return $value;
|
133 |
+
}
|
134 |
+
if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) {
|
135 |
+
unset( $value->response['backupwordpress/backupwordpress.php'] );
|
136 |
+
}
|
137 |
+
|
138 |
+
return $value;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Fire off certain BackUpWordPress plugin actions.
|
143 |
+
*
|
144 |
+
* @uses \MainWP\Child\MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
145 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::is_activated() Check if the plugin is activated.
|
146 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::set_showhide() Hide or unhide the BackUpWordPress plugin.
|
147 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::delete_schedule() Delete backup schedule.
|
148 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::hmbkp_request_cancel_backup() Cancel backup process.
|
149 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::get_backup_status() Get the bacukp process status.
|
150 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::reload_backups() Reload backups.
|
151 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::hmbkp_request_delete_backup() Delete backup.
|
152 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::run_schedule() Run schedules.
|
153 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::save_all_schedules() Save all schedules.
|
154 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::update_schedule() Update schedule.
|
155 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::get_excluded() Get excluded files.
|
156 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::directory_browse() Browse directory.
|
157 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::hmbkp_add_exclude_rule() Add exclusion rule.
|
158 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::hmbkp_remove_exclude_rule() Remove exclusion rule.
|
159 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::general_exclude_add_rule() General exclusion rules.
|
160 |
+
*/
|
161 |
+
public function action() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
162 |
+
$information = array();
|
163 |
+
if ( ! self::is_activated() ) {
|
164 |
+
$information['error'] = 'NO_BACKUPWORDPRESS';
|
165 |
+
MainWP_Helper::write( $information );
|
166 |
+
}
|
167 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
168 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
169 |
+
switch ( $mwp_action ) {
|
170 |
+
case 'set_showhide':
|
171 |
+
$information = $this->set_showhide();
|
172 |
+
break;
|
173 |
+
case 'delete_schedule':
|
174 |
+
$information = $this->delete_schedule();
|
175 |
+
break;
|
176 |
+
case 'cancel_schedule':
|
177 |
+
$information = $this->hmbkp_request_cancel_backup();
|
178 |
+
break;
|
179 |
+
case 'get_backup_status':
|
180 |
+
$information = $this->get_backup_status();
|
181 |
+
break;
|
182 |
+
case 'reload_backupslist':
|
183 |
+
$information = $this->reload_backups();
|
184 |
+
break;
|
185 |
+
case 'delete_backup':
|
186 |
+
$information = $this->hmbkp_request_delete_backup();
|
187 |
+
break;
|
188 |
+
case 'run_schedule':
|
189 |
+
$information = $this->run_schedule();
|
190 |
+
break;
|
191 |
+
case 'save_all_schedules':
|
192 |
+
$information = $this->save_all_schedules();
|
193 |
+
break;
|
194 |
+
case 'update_schedule':
|
195 |
+
$information = $this->update_schedule();
|
196 |
+
break;
|
197 |
+
case 'get_excluded':
|
198 |
+
$information = $this->get_excluded();
|
199 |
+
break;
|
200 |
+
case 'directory_browse':
|
201 |
+
$information = $this->directory_browse();
|
202 |
+
break;
|
203 |
+
case 'exclude_add_rule':
|
204 |
+
$information = $this->hmbkp_add_exclude_rule();
|
205 |
+
break;
|
206 |
+
case 'exclude_remove_rule':
|
207 |
+
$information = $this->hmbkp_remove_exclude_rule();
|
208 |
+
break;
|
209 |
+
case 'general_exclude_add_rule':
|
210 |
+
$information = $this->general_exclude_add_rule();
|
211 |
+
break;
|
212 |
+
}
|
213 |
+
}
|
214 |
+
MainWP_Helper::write( $information );
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Check schedule and get the ID.
|
219 |
+
*
|
220 |
+
* @return int Schedule ID.
|
221 |
+
*
|
222 |
+
* @uses \MainWP\Child\MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
223 |
+
* @uses sanitize_text_field() Sanitizes a string from user input or from the database.
|
224 |
+
* @see https://developer.wordpress.org/reference/functions/sanitize_text_field/
|
225 |
+
*/
|
226 |
+
public function check_schedule() {
|
227 |
+
$schedule_id = ( isset( $_POST['schedule_id'] ) && ! empty( $_POST['schedule_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['schedule_id'] ) ) : '';
|
228 |
+
if ( empty( $schedule_id ) ) {
|
229 |
+
$information = array( 'error' => 'Empty schedule id' );
|
230 |
+
MainWP_Helper::write( $information );
|
231 |
+
} else {
|
232 |
+
$schedule_id = sanitize_text_field( rawurldecode( $schedule_id ) );
|
233 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
234 |
+
if ( ! \HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
235 |
+
$information = array( 'result' => 'NOTFOUND' );
|
236 |
+
MainWP_Helper::write( $information );
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
return $schedule_id;
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Sync the BackUpWordPress plugin settings.
|
245 |
+
*
|
246 |
+
* @param array $information Array containing the sync information.
|
247 |
+
* @param array $data Array containing the BackUpWordPress plugin data to be synced.
|
248 |
+
*
|
249 |
+
* @uses MainWP_Child_Back_Up_WordPress::get_sync_data() Get synced BackUpWordPress data.
|
250 |
+
*
|
251 |
+
* @return array $information Array containing the sync information.
|
252 |
+
*/
|
253 |
+
public function sync_others_data( $information, $data = array() ) {
|
254 |
+
if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) {
|
255 |
+
try {
|
256 |
+
$information['syncBackUpWordPress'] = $this->get_sync_data();
|
257 |
+
} catch ( \Exception $e ) {
|
258 |
+
// ok!
|
259 |
+
}
|
260 |
+
}
|
261 |
+
return $information;
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* Get synced BackUpWordPress data.
|
266 |
+
*
|
267 |
+
* @return array Return an array containing the synced data.
|
268 |
+
*
|
269 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists() Check if requested class exists.
|
270 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods() Check if requested method exists.
|
271 |
+
*
|
272 |
+
* @used-by \MainWP\Child\MainWP_Child_Back_Up_WordPress::sync_others_data() Sync the BackUpWordPress plugin settings.
|
273 |
+
*/
|
274 |
+
private function get_sync_data() {
|
275 |
+
MainWP_Helper::check_classes_exists( '\HM\BackUpWordPress\Schedules' );
|
276 |
+
MainWP_Helper::check_methods( '\HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
277 |
+
|
278 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
279 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
280 |
+
$backups_time = array();
|
281 |
+
|
282 |
+
if ( is_array( $schedules ) && count( $schedules ) ) {
|
283 |
+
foreach ( $schedules as $sche ) {
|
284 |
+
if ( true === MainWP_Helper::check_methods( $sche, array( 'get_backups' ), true ) ) {
|
285 |
+
$existing_backup = $sche->get_backups();
|
286 |
+
if ( ! empty( $existing_backup ) ) {
|
287 |
+
$backups_time = array_merge( $backups_time, array_keys( $existing_backup ) );
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
$lasttime_backup = 0;
|
294 |
+
if ( ! empty( $backups_time ) ) {
|
295 |
+
$lasttime_backup = max( $backups_time );
|
296 |
+
}
|
297 |
+
|
298 |
+
$return = array( 'lasttime_backup' => $lasttime_backup );
|
299 |
+
|
300 |
+
return $return;
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Add support for the reporting system.
|
305 |
+
*
|
306 |
+
* @uses has_action() Check if any action has been registered for a hook.
|
307 |
+
* @see https://developer.wordpress.org/reference/functions/has_action/
|
308 |
+
*
|
309 |
+
* @uses MainWP_Child_Back_Up_WordPress::do_reports_log() Add BackUpWordPress data to the reports database table.
|
310 |
+
*/
|
311 |
+
public function do_site_stats() {
|
312 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
313 |
+
do_action( 'mainwp_child_reports_log', 'backupwordpress' );
|
314 |
+
} else {
|
315 |
+
$this->do_reports_log( 'backupwordpress' );
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Add BackUpWordPress data to the reports database table.
|
321 |
+
*
|
322 |
+
* @param string $ext Current extension.
|
323 |
+
*
|
324 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists() Check if the requested class exists.
|
325 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods() Check if the requested method exists.
|
326 |
+
* @uses \MainWP\Child\MainWP_Utility::update_lasttime_backup() Get the last backup timestamp
|
327 |
+
* @uses \MainWP\Child\MainWP_Utility::update_lasttime_backup()
|
328 |
+
*
|
329 |
+
* @used-by \MainWP\Child\MainWP_Child_Back_Up_WordPress::do_site_stats() Add support for the reporting system.
|
330 |
+
*/
|
331 |
+
public function do_reports_log( $ext = '' ) {
|
332 |
+
if ( 'backupwordpress' !== $ext ) {
|
333 |
+
return;
|
334 |
+
}
|
335 |
+
if ( ! $this->is_plugin_installed ) {
|
336 |
+
return;
|
337 |
+
}
|
338 |
+
|
339 |
+
try {
|
340 |
+
MainWP_Helper::check_classes_exists( '\HM\BackUpWordPress\Schedules' );
|
341 |
+
MainWP_Helper::check_methods( '\HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
342 |
+
|
343 |
+
// Refresh the schedules from the database to make sure we have the latest changes.
|
344 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
345 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
346 |
+
if ( is_array( $schedules ) && count( $schedules ) > 0 ) {
|
347 |
+
$check = current( $schedules );
|
348 |
+
MainWP_Helper::check_methods( $check, array( 'get_backups', 'get_type' ) );
|
349 |
+
|
350 |
+
foreach ( $schedules as $schedule ) {
|
351 |
+
foreach ( $schedule->get_backups() as $file ) {
|
352 |
+
$backup_type = $schedule->get_type();
|
353 |
+
$message = 'BackupWordpres backup ' . $backup_type . ' finished';
|
354 |
+
$destination = 'N/A';
|
355 |
+
if ( file_exists( $file ) ) {
|
356 |
+
$date = filemtime( $file );
|
357 |
+
if ( ! empty( $date ) ) {
|
358 |
+
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date );
|
359 |
+
MainWP_Utility::update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature.
|
360 |
+
}
|
361 |
+
}
|
362 |
+
}
|
363 |
+
}
|
364 |
+
}
|
365 |
+
} catch ( \Exception $e ) {
|
366 |
+
// ok!
|
367 |
+
}
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Hide or unhide the BackUpWordPress plugin.
|
372 |
+
*
|
373 |
+
* @return array Action result.
|
374 |
+
*
|
375 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option() Update database option by option name.
|
376 |
+
*
|
377 |
+
* @used-by \MainWP\Child\MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
378 |
+
*/
|
379 |
+
public function set_showhide() {
|
380 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
381 |
+
MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide );
|
382 |
+
$information['result'] = 'SUCCESS';
|
383 |
+
|
384 |
+
return $information;
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Delete schedule.
|
389 |
+
*
|
390 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
391 |
+
*
|
392 |
+
* @return array Action result.
|
393 |
+
*/
|
394 |
+
public function delete_schedule() {
|
395 |
+
$schedule_id = $this->check_schedule();
|
396 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
397 |
+
|
398 |
+
if ( $schedule ) {
|
399 |
+
$schedule->cancel( true );
|
400 |
+
$information['result'] = 'SUCCESS';
|
401 |
+
} else {
|
402 |
+
$information['result'] = 'NOTFOUND';
|
403 |
+
}
|
404 |
+
|
405 |
+
return $information;
|
406 |
+
}
|
407 |
+
|
408 |
+
/**
|
409 |
+
* Cancel the backup process.
|
410 |
+
*
|
411 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
412 |
+
*
|
413 |
+
* @return array Action result.
|
414 |
+
*/
|
415 |
+
public function hmbkp_request_cancel_backup() {
|
416 |
+
$schedule_id = $this->check_schedule();
|
417 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
418 |
+
|
419 |
+
// Delete the running backup.
|
420 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
421 |
+
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
|
422 |
+
unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() );
|
423 |
+
}
|
424 |
+
if ( $schedule->get_schedule_running_path() && file_exists( $schedule->get_schedule_running_path() ) ) {
|
425 |
+
unlink( $schedule->get_schedule_running_path() );
|
426 |
+
}
|
427 |
+
} else {
|
428 |
+
$status = $schedule->get_status();
|
429 |
+
// Delete the running backup.
|
430 |
+
if ( $status->get_backup_filename() && file_exists( trailingslashit( \HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) {
|
431 |
+
unlink( trailingslashit( \HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() );
|
432 |
+
}
|
433 |
+
if ( file_exists( $status->get_status_filepath() ) ) {
|
434 |
+
unlink( $status->get_status_filepath() );
|
435 |
+
}
|
436 |
+
}
|
437 |
+
|
438 |
+
\HM\BackUpWordPress\Path::get_instance()->cleanup();
|
439 |
+
|
440 |
+
if ( null === $status ) {
|
441 |
+
$information['scheduleStatus'] = $schedule->get_status();
|
442 |
+
} else {
|
443 |
+
$information['scheduleStatus'] = $status->get_status();
|
444 |
+
}
|
445 |
+
|
446 |
+
$information['result'] = 'SUCCESS';
|
447 |
+
|
448 |
+
return $information;
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Get the backup process status.
|
453 |
+
*
|
454 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
455 |
+
*
|
456 |
+
* @return array Action result.
|
457 |
+
*/
|
458 |
+
public function get_backup_status() {
|
459 |
+
$schedule_id = $this->check_schedule();
|
460 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
461 |
+
|
462 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
463 |
+
$information['scheduleStatus'] = $schedule->get_status();
|
464 |
+
} else {
|
465 |
+
$status = $schedule->get_status();
|
466 |
+
$information['scheduleStatus'] = $status->get_status();
|
467 |
+
}
|
468 |
+
|
469 |
+
$information['result'] = 'SUCCESS';
|
470 |
+
|
471 |
+
return $information;
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Run schedule.
|
476 |
+
*
|
477 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
478 |
+
*
|
479 |
+
* @return array Action result.
|
480 |
+
*/
|
481 |
+
public function run_schedule() {
|
482 |
+
$schedule_id = $this->check_schedule();
|
483 |
+
if ( function_exists( 'hmbkp_run_schedule_async' ) ) {
|
484 |
+
hmbkp_run_schedule_async( $schedule_id );
|
485 |
+
} elseif ( function_exists( '\HM\BackUpWordPress\run_schedule_async' ) ) {
|
486 |
+
\HM\BackUpWordPress\Path::get_instance()->cleanup();
|
487 |
+
// Fixes an issue on servers which only allow a single session per client.
|
488 |
+
session_write_close();
|
489 |
+
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
|
490 |
+
$task->schedule();
|
491 |
+
} else {
|
492 |
+
return array( 'error' => __( 'Error while trying to trigger the schedule', 'mainwp-child' ) );
|
493 |
+
}
|
494 |
+
return array( 'result' => 'SUCCESS' );
|
495 |
+
}
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Reload backups.
|
499 |
+
*
|
500 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
501 |
+
*
|
502 |
+
* @return array Action result.
|
503 |
+
*/
|
504 |
+
public function reload_backups() {
|
505 |
+
|
506 |
+
$scheduleIds = isset( $_POST['schedule_ids'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['schedule_ids'] ) ) : array();
|
507 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
508 |
+
|
509 |
+
$all_schedules_ids = array();
|
510 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
511 |
+
foreach ( $schedules as $sch ) {
|
512 |
+
$all_schedules_ids[] = $sch->get_id();
|
513 |
+
}
|
514 |
+
|
515 |
+
if ( empty( $all_schedules_ids ) ) {
|
516 |
+
return array( 'error' => 'Schedules could not be found.' );
|
517 |
+
}
|
518 |
+
|
519 |
+
foreach ( $all_schedules_ids as $schedule_id ) {
|
520 |
+
if ( ! \HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
521 |
+
continue;
|
522 |
+
}
|
523 |
+
|
524 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
525 |
+
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
526 |
+
$out = array(
|
527 |
+
'b' => $this->get_backupslist_html( $schedule ),
|
528 |
+
'count' => count( $schedule->get_backups() ),
|
529 |
+
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
530 |
+
'started_ago' => human_time_diff( $started_ago ),
|
531 |
+
);
|
532 |
+
|
533 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
534 |
+
$out['scheduleStatus'] = $schedule->get_status();
|
535 |
+
} else {
|
536 |
+
$status = $schedule->get_status();
|
537 |
+
$out['scheduleStatus'] = $status->get_status();
|
538 |
+
}
|
539 |
+
|
540 |
+
$information['backups'][ $schedule_id ] = $out;
|
541 |
+
}
|
542 |
+
|
543 |
+
$send_back_schedules = array();
|
544 |
+
|
545 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
546 |
+
foreach ( $schedules as $schedule ) {
|
547 |
+
$sch_id = $schedule->get_id();
|
548 |
+
if ( ! in_array( $sch_id, $scheduleIds ) ) {
|
549 |
+
$current_option = get_option( 'hmbkp_schedule_' . $sch_id );
|
550 |
+
if ( is_array( $current_option ) ) {
|
551 |
+
unset( $current_option['excludes'] );
|
552 |
+
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
553 |
+
$send_back_schedules[ $sch_id ] = array(
|
554 |
+
'options' => $current_option,
|
555 |
+
'b' => $this->get_backupslist_html( $schedule ),
|
556 |
+
'count' => count( $schedule->get_backups() ),
|
557 |
+
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
558 |
+
'scheduleStatus' => $schedule->get_status(),
|
559 |
+
'started_ago' => human_time_diff( $started_ago ),
|
560 |
+
);
|
561 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
562 |
+
$send_back_schedules['scheduleStatus'] = $schedule->get_status();
|
563 |
+
} else {
|
564 |
+
$status = $schedule->get_status();
|
565 |
+
$send_back_schedules['scheduleStatus'] = $status->get_status();
|
566 |
+
}
|
567 |
+
}
|
568 |
+
}
|
569 |
+
}
|
570 |
+
|
571 |
+
if ( function_exists( '\HM\BackUpWordPress\Backup::get_home_path' ) ) {
|
572 |
+
$backups_path = str_replace( \HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
|
573 |
+
} else {
|
574 |
+
$backups_path = str_replace( \HM\BackUpWordPress\Path::get_home_path(), '', \HM\BackUpWordPress\Path::get_path() );
|
575 |
+
}
|
576 |
+
|
577 |
+
$information['backups_path'] = $backups_path;
|
578 |
+
$information['send_back_schedules'] = $send_back_schedules;
|
579 |
+
$information['result'] = 'SUCCESS';
|
580 |
+
|
581 |
+
return $information;
|
582 |
+
}
|
583 |
+
|
584 |
+
/**
|
585 |
+
* Delete backup.
|
586 |
+
*
|
587 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
588 |
+
*
|
589 |
+
* @return array Action result.
|
590 |
+
*/
|
591 |
+
public function hmbkp_request_delete_backup() {
|
592 |
+
if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) {
|
593 |
+
return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) );
|
594 |
+
}
|
595 |
+
|
596 |
+
$schedule_id = $this->check_schedule();
|
597 |
+
|
598 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
599 |
+
|
600 |
+
$deleted = isset( $_POST['hmbkp_backuparchive'] ) ? $schedule->delete_backup( base64_decode( rawurldecode( wp_unslash( $_POST['hmbkp_backuparchive'] ) ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
601 |
+
|
602 |
+
if ( is_wp_error( $deleted ) ) {
|
603 |
+
return array( 'error' => $deleted->get_error_message() );
|
604 |
+
}
|
605 |
+
|
606 |
+
$ret = array(
|
607 |
+
'result' => 'SUCCESS',
|
608 |
+
'b' => $this->get_backupslist_html( $schedule ),
|
609 |
+
'count' => count( $schedule->get_backups() ),
|
610 |
+
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
611 |
+
);
|
612 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
613 |
+
$ret['scheduleStatus'] = $schedule->get_status();
|
614 |
+
} else {
|
615 |
+
$status = $schedule->get_status();
|
616 |
+
$ret['scheduleStatus'] = $status->get_status();
|
617 |
+
}
|
618 |
+
return $ret;
|
619 |
+
}
|
620 |
+
|
621 |
+
/**
|
622 |
+
* Get backups list HTML.
|
623 |
+
*
|
624 |
+
* @param object $schedule Object containing the schedule data.
|
625 |
+
*
|
626 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
627 |
+
*
|
628 |
+
* @return array Action result.
|
629 |
+
*/
|
630 |
+
public function get_backupslist_html( $schedule ) {
|
631 |
+
ob_start();
|
632 |
+
?>
|
633 |
+
<table class="widefat">
|
634 |
+
<thead>
|
635 |
+
<tr>
|
636 |
+
<th scope="col"><?php function_exists( 'hmbkp_backups_number' ) ? hmbkp_backups_number( $schedule ) : ( function_exists( 'backups_number' ) ? backups_number( $schedule ) : '' ); ?></th>
|
637 |
+
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
638 |
+
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
639 |
+
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-child' ); ?></th>
|
640 |
+
</tr>
|
641 |
+
</thead>
|
642 |
+
<tbody>
|
643 |
+
<?php
|
644 |
+
if ( $schedule->get_backups() ) {
|
645 |
+
$schedule->delete_old_backups();
|
646 |
+
foreach ( $schedule->get_backups() as $file ) {
|
647 |
+
if ( ! file_exists( $file ) ) {
|
648 |
+
continue;
|
649 |
+
}
|
650 |
+
$this->hmbkp_get_backup_row( $file, $schedule );
|
651 |
+
}
|
652 |
+
} else {
|
653 |
+
?>
|
654 |
+
<tr>
|
655 |
+
<td class="hmbkp-no-backups" colspan="4"><?php esc_html_e( 'This is where your backups will appear once you have some.', 'mainwp-child' ); ?></td>
|
656 |
+
</tr>
|
657 |
+
<?php } ?>
|
658 |
+
</tbody>
|
659 |
+
</table>
|
660 |
+
<?php
|
661 |
+
$html = ob_get_clean();
|
662 |
+
|
663 |
+
return $html;
|
664 |
+
}
|
665 |
+
|
666 |
+
/**
|
667 |
+
* Get the site size text.
|
668 |
+
*
|
669 |
+
* @param \HM\BackUpWordPress\Scheduled_Backup $schedule Object containing the schedule data.
|
670 |
+
*
|
671 |
+
* @return string Site size text.
|
672 |
+
*/
|
673 |
+
public function hmbkp_get_site_size_text( \HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
674 |
+
if ( method_exists( $schedule, 'is_site_size_cached' ) ) {
|
675 |
+
if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
|
676 |
+
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) );
|
677 |
+
}
|
678 |
+
} else {
|
679 |
+
$site_size = new \HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
|
680 |
+
if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
|
681 |
+
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $site_size->get_formatted_site_size() ) );
|
682 |
+
}
|
683 |
+
}
|
684 |
+
|
685 |
+
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long…', 'mainwp-child' ) . '">' . __( 'calculating the size of your backup…', 'mainwp-child' ) . '</code>)' );
|
686 |
+
}
|
687 |
+
|
688 |
+
/**
|
689 |
+
* Get the backup table row HTML.
|
690 |
+
*
|
691 |
+
* @param resource $file Backup file.
|
692 |
+
* @param \HM\BackUpWordPress\Scheduled_Backup $schedule Object containing the schedule data.
|
693 |
+
*/
|
694 |
+
public function hmbkp_get_backup_row( $file, \HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
695 |
+
$encoded_file = rawurlencode( base64_encode( $file ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
696 |
+
$offset = get_option( 'gmt_offset' ) * 3600;
|
697 |
+
?>
|
698 |
+
<tr class="hmbkp_manage_backups_row">
|
699 |
+
<th scope="row">
|
700 |
+
<?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ), filemtime( $file ) + $offset ) ); ?>
|
701 |
+
</th>
|
702 |
+
<td class="code">
|
703 |
+
<?php echo esc_html( size_format( filesize( $file ) ) ); ?>
|
704 |
+
</td>
|
705 |
+
<td><?php echo function_exists( 'hmbkp_human_get_type' ) ? esc_html( hmbkp_human_get_type( $file, $schedule ) ) : esc_html( \HM\BackUpWordPress\human_get_type( $file, $schedule ) ); ?></td>
|
706 |
+
<td>
|
707 |
+
<?php
|
708 |
+
if ( function_exists( 'hmbkp_is_path_accessible' ) ) {
|
709 |
+
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
|
710 |
+
?>
|
711 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="download-action"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> |
|
712 |
+
<?php
|
713 |
+
};
|
714 |
+
} elseif ( function_exists( '\HM\BackUpWordPress\is_path_accessible' ) ) {
|
715 |
+
if ( \HM\BackUpWordPress\is_path_accessible( \HM\BackUpWordPress\Path::get_path() ) ) {
|
716 |
+
?>
|
717 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="download-action"><?php esc_html_e( 'Download', 'maiwnp-child' ); ?></a> |
|
718 |
+
<?php
|
719 |
+
};
|
720 |
+
}
|
721 |
+
?>
|
722 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_delete_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="delete-action"><?php esc_html_e( 'Delete', 'mainwp-child' ); ?></a>
|
723 |
+
</td>
|
724 |
+
</tr>
|
725 |
+
<?php
|
726 |
+
}
|
727 |
+
|
728 |
+
/**
|
729 |
+
* Get excluded files.
|
730 |
+
*
|
731 |
+
* @param string $browse_dir Browse directory path.
|
732 |
+
*
|
733 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
734 |
+
*
|
735 |
+
* @return array Action result.
|
736 |
+
*/
|
737 |
+
public function get_excluded( $browse_dir = null ) {
|
738 |
+
|
739 |
+
$schedule_id = $this->check_schedule();
|
740 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
741 |
+
|
742 |
+
$new_version = true;
|
743 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
744 |
+
$new_version = false;
|
745 |
+
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
|
746 |
+
$root_dir = $schedule->backup->get_root();
|
747 |
+
$is_size_calculated = $schedule->is_site_size_being_calculated();
|
748 |
+
} else {
|
749 |
+
$excludes = $schedule->get_excludes();
|
750 |
+
$user_excludes = $excludes->get_user_excludes();
|
751 |
+
$root_dir = \HM\BackUpWordPress\Path::get_root();
|
752 |
+
$is_size_calculated = \HM\BackUpWordPress\Site_Size::is_site_size_being_calculated();
|
753 |
+
}
|
754 |
+
|
755 |
+
ob_start();
|
756 |
+
|
757 |
+
?>
|
758 |
+
<div class="hmbkp-exclude-settings">
|
759 |
+
<h3><?php esc_html_e( 'Currently Excluded', 'mainwp-child' ); ?></h3>
|
760 |
+
<p><?php esc_html_e( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'mainwp-child' ); ?></p>
|
761 |
+
<?php
|
762 |
+
$this->render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version )
|
763 |
+
?>
|
764 |
+
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'mainwp-child' ); ?></h3>
|
765 |
+
<p><?php esc_html_e( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'mainwp-child' ); ?></p>
|
766 |
+
<?php
|
767 |
+
$directory = $root_dir;
|
768 |
+
|
769 |
+
if ( isset( $browse_dir ) ) {
|
770 |
+
|
771 |
+
$untrusted_directory = rawurldecode( $browse_dir );
|
772 |
+
|
773 |
+
// Only allow real sub directories of the site root to be browsed.
|
774 |
+
if ( false !== strpos( $untrusted_directory, $root_dir ) && is_dir( $untrusted_directory ) ) {
|
775 |
+
$directory = $untrusted_directory;
|
776 |
+
}
|
777 |
+
}
|
778 |
+
|
779 |
+
// Kick off a recursive filesize scan.
|
780 |
+
if ( $new_version ) {
|
781 |
+
$site_size = new \HM\BackUpWordPress\Site_Size();
|
782 |
+
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
|
783 |
+
if ( function_exists( '\HM\BackUpWordPress\list_directory_by_total_filesize' ) ) {
|
784 |
+
$files = \HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
|
785 |
+
}
|
786 |
+
} else {
|
787 |
+
$files = $schedule->list_directory_by_total_filesize( $directory );
|
788 |
+
$exclude_string = $schedule->backup->exclude_string( 'regex' );
|
789 |
+
}
|
790 |
+
if ( $files ) {
|
791 |
+
$this->render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated );
|
792 |
+
}
|
793 |
+
?>
|
794 |
+
<p class="submit">
|
795 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()" class="button-primary"><?php esc_html_e( 'Done', 'mainwp-child' ); ?></a>
|
796 |
+
</p>
|
797 |
+
</div>
|
798 |
+
<?php
|
799 |
+
$output = ob_get_clean();
|
800 |
+
$information['e'] = $output;
|
801 |
+
|
802 |
+
return $information;
|
803 |
+
}
|
804 |
+
|
805 |
+
/**
|
806 |
+
* Render table of the excluded items.
|
807 |
+
*
|
808 |
+
* @param string $root_dir Root directory.
|
809 |
+
* @param object $schedule Object containng the schedule data.
|
810 |
+
* @param object $excludes Files to exclude.
|
811 |
+
* @param object $user_excludes Excluded by user.
|
812 |
+
* @param string $new_version New version.
|
813 |
+
*/
|
814 |
+
private function render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version ) {
|
815 |
+
?>
|
816 |
+
<table class="widefat">
|
817 |
+
<tbody>
|
818 |
+
<?php foreach ( $user_excludes as $key => $exclude ) : ?>
|
819 |
+
<?php $exclude_path = new \SplFileInfo( trailingslashit( $root_dir ) . ltrim( str_ireplace( $root_dir, '', $exclude ), '/' ) ); ?>
|
820 |
+
<tr>
|
821 |
+
<th scope="row">
|
822 |
+
<?php if ( $exclude_path->isFile() ) { ?>
|
823 |
+
<div class="dashicons dashicons-media-default"></div>
|
824 |
+
<?php } elseif ( $exclude_path->isDir() ) { ?>
|
825 |
+
<div class="dashicons dashicons-portfolio"></div>
|
826 |
+
<?php } ?>
|
827 |
+
</th>
|
828 |
+
<td>
|
829 |
+
<code><?php echo esc_html( str_ireplace( $root_dir, '', $exclude ) ); ?></code>
|
830 |
+
</td>
|
831 |
+
<td>
|
832 |
+
<?php
|
833 |
+
if ( $new_version ) {
|
834 |
+
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( \HM\BackUpWordPress\Path::get_path() === trailingslashit( \HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
|
835 |
+
} else {
|
836 |
+
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) );
|
837 |
+
}
|
838 |
+
if ( $is_default_rule ) :
|
839 |
+
?>
|
840 |
+
<?php esc_html_e( 'Default rule', 'mainwp-child' ); ?>
|
841 |
+
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
|
842 |
+
<?php esc_html_e( 'Defined in wp-config.php', 'mainwp-child' ); ?>
|
843 |
+
<?php else : ?>
|
844 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this);" class="delete-action"><?php esc_html_e( 'Stop excluding', 'mainwp-child' ); ?></a>
|
845 |
+
<?php endif; ?>
|
846 |
+
</td>
|
847 |
+
</tr>
|
848 |
+
<?php endforeach; ?>
|
849 |
+
</tbody>
|
850 |
+
</table>
|
851 |
+
<?php
|
852 |
+
}
|
853 |
+
|
854 |
+
/**
|
855 |
+
* Render the files table.
|
856 |
+
*
|
857 |
+
* @param object $files Backup files.
|
858 |
+
* @param object $schedule Object containng the schedule data.
|
859 |
+
* @param string $directory Backups directory.
|
860 |
+
* @param string $root_dir Site root directory.
|
861 |
+
* @param string $new_version New version.
|
862 |
+
* @param int $site_size Site size.
|
863 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
864 |
+
*/
|
865 |
+
private function render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated ) {
|
866 |
+
?>
|
867 |
+
<table class="widefat">
|
868 |
+
<thead>
|
869 |
+
<?php
|
870 |
+
$this->render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated );
|
871 |
+
?>
|
872 |
+
</thead>
|
873 |
+
<tbody>
|
874 |
+
<?php
|
875 |
+
$this->render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated );
|
876 |
+
?>
|
877 |
+
</tbody>
|
878 |
+
</table>
|
879 |
+
<?php
|
880 |
+
}
|
881 |
+
|
882 |
+
/**
|
883 |
+
* Render the backup table header.
|
884 |
+
*
|
885 |
+
* @param string $root_dir Site root directory.
|
886 |
+
* @param string $directory Backups directory.
|
887 |
+
* @param object $schedule Object containng the schedule data.
|
888 |
+
* @param string $new_version New version.
|
889 |
+
* @param int $site_size Site size.
|
890 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
891 |
+
*/
|
892 |
+
private function render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated ) {
|
893 |
+
?>
|
894 |
+
<tr>
|
895 |
+
<th></th>
|
896 |
+
<th scope="col"><?php esc_html_e( 'Name', 'mainwp-child' ); ?></th>
|
897 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
898 |
+
<th scope="col"
|
899 |
+
class="column-format"><?php esc_html_e( 'Permissions', 'mainwp-child' ); ?></th>
|
900 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
901 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
902 |
+
</tr>
|
903 |
+
<tr>
|
904 |
+
<th scope="row">
|
905 |
+
<div class="dashicons dashicons-admin-home"></div>
|
906 |
+
</th>
|
907 |
+
<th scope="col">
|
908 |
+
<?php
|
909 |
+
if ( $root_dir !== $directory ) {
|
910 |
+
?>
|
911 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse( '', this )"><?php echo esc_html( $root_dir ); ?></a>
|
912 |
+
<code>/</code>
|
913 |
+
<?php
|
914 |
+
$parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
|
915 |
+
foreach ( $parents as $directory_basename ) {
|
916 |
+
?>
|
917 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
|
918 |
+
<code>/</code>
|
919 |
+
<?php } ?>
|
920 |
+
<?php echo esc_html( basename( $directory ) ); ?>
|
921 |
+
<?php } else { ?>
|
922 |
+
<?php echo esc_html( $root_dir ); ?>
|
923 |
+
<?php } ?>
|
924 |
+
</th>
|
925 |
+
<td class="column-filesize">
|
926 |
+
<?php if ( $is_size_calculated ) : ?>
|
927 |
+
<span class="spinner"></span>
|
928 |
+
<?php
|
929 |
+
else :
|
930 |
+
$root = new \SplFileInfo( $root_dir );
|
931 |
+
if ( $new_version ) {
|
932 |
+
$size = $site_size->filesize( $root );
|
933 |
+
} else {
|
934 |
+
$size = $schedule->filesize( $root, true );
|
935 |
+
}
|
936 |
+
if ( false !== $size ) {
|
937 |
+
$size = size_format( $size );
|
938 |
+
if ( ! $size ) {
|
939 |
+
$size = '0 B';
|
940 |
+
}
|
941 |
+
?>
|
942 |
+
<code>
|
943 |
+
<?php echo esc_html( $size ); ?>
|
944 |
+
<a class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
945 |
+
</code>
|
946 |
+
<?php } ?>
|
947 |
+
<?php endif; ?>
|
948 |
+
<td>
|
949 |
+
<?php echo esc_html( substr( sprintf( '%o', fileperms( $root_dir ) ), - 4 ) ); ?>
|
950 |
+
</td>
|
951 |
+
<td>
|
952 |
+
<?php
|
953 |
+
if ( is_link( $root_dir ) ) {
|
954 |
+
esc_html_e( 'Symlink', 'mainwp-child' );
|
955 |
+
} elseif ( is_dir( $root_dir ) ) {
|
956 |
+
esc_html_e( 'Folder', 'mainwp-child' );
|
957 |
+
}
|
958 |
+
?>
|
959 |
+
</td>
|
960 |
+
<td></td>
|
961 |
+
</tr>
|
962 |
+
<?php
|
963 |
+
}
|
964 |
+
|
965 |
+
/**
|
966 |
+
* Render the backup table body.
|
967 |
+
*
|
968 |
+
* @param object $files Backup files.
|
969 |
+
* @param object $schedule Object containng the schedule data.
|
970 |
+
* @param string $root_dir Site root directory.
|
971 |
+
* @param string $new_version New version.
|
972 |
+
* @param int $site_size Site size.
|
973 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
974 |
+
*/
|
975 |
+
private function render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
976 |
+
|
977 |
+
foreach ( $files as $size => $file ) {
|
978 |
+
$is_excluded = false;
|
979 |
+
$is_unreadable = false;
|
980 |
+
// Check if the file is excluded.
|
981 |
+
if ( $new_version ) {
|
982 |
+
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) {
|
983 |
+
$is_excluded = true;
|
984 |
+
}
|
985 |
+
} else {
|
986 |
+
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', \HM\BackUpWordPress\Backup::conform_dir( $file->getPathname() ) ) ) ) {
|
987 |
+
$is_excluded = true;
|
988 |
+
}
|
989 |
+
}
|
990 |
+
// Skip unreadable files.
|
991 |
+
if ( ! realpath( $file->getPathname() ) || ! $file->isReadable() ) {
|
992 |
+
$is_unreadable = true;
|
993 |
+
}
|
994 |
+
?>
|
995 |
+
<tr>
|
996 |
+
<td>
|
997 |
+
<?php if ( $is_unreadable ) { ?>
|
998 |
+
<div class="dashicons dashicons-dismiss"></div>
|
999 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1000 |
+
<div class="dashicons dashicons-media-default"></div>
|
1001 |
+
<?php } elseif ( $file->isDir() ) { ?>
|
1002 |
+
<div class="dashicons dashicons-portfolio"></div>
|
1003 |
+
<?php } ?>
|
1004 |
+
</td>
|
1005 |
+
<td>
|
1006 |
+
<?php
|
1007 |
+
if ( $new_version ) {
|
1008 |
+
if ( $is_unreadable ) {
|
1009 |
+
?>
|
1010 |
+
<code class="strikethrough" title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1011 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1012 |
+
<code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1013 |
+
<?php } elseif ( $file->isDir() ) { ?>
|
1014 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( wp_normalize_path( $file->getPathname() ) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
1015 |
+
<?php
|
1016 |
+
}
|
1017 |
+
} else {
|
1018 |
+
if ( $is_unreadable ) {
|
1019 |
+
?>
|
1020 |
+
<code class="strikethrough" title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1021 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1022 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1023 |
+
<?php
|
1024 |
+
} elseif ( $file->isDir() ) {
|
1025 |
+
?>
|
1026 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
1027 |
+
<?php
|
1028 |
+
}
|
1029 |
+
}
|
1030 |
+
?>
|
1031 |
+
</td>
|
1032 |
+
<td class="column-format column-filesize">
|
1033 |
+
<?php if ( $file->isDir() && $is_size_calculated ) : ?>
|
1034 |
+
<span class="spinner"></span>
|
1035 |
+
<?php
|
1036 |
+
else :
|
1037 |
+
if ( $new_version ) {
|
1038 |
+
$size = $site_size->filesize( $file );
|
1039 |
+
} else {
|
1040 |
+
$size = $schedule->filesize( $file );
|
1041 |
+
}
|
1042 |
+
if ( false !== $size ) {
|
1043 |
+
$size = size_format( $size );
|
1044 |
+
if ( ! $size ) {
|
1045 |
+
$size = '0 B';
|
1046 |
+
}
|
1047 |
+
?>
|
1048 |
+
<code>
|
1049 |
+
<?php echo esc_html( $size ); ?>
|
1050 |
+
<?php if ( $file->isDir() ) { ?>
|
1051 |
+
<a title="<?php esc_attr_e( 'Recalculate the size of this directory', 'maiwnp-child' ); ?>" class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
1052 |
+
<?php } ?>
|
1053 |
+
</code>
|
1054 |
+
<?php } else { ?>
|
1055 |
+
<code>--</code>
|
1056 |
+
<?php
|
1057 |
+
}
|
1058 |
+
endif;
|
1059 |
+
?>
|
1060 |
+
</td>
|
1061 |
+
<td>
|
1062 |
+
<?php echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) ); ?>
|
1063 |
+
</td>
|
1064 |
+
<td>
|
1065 |
+
<?php if ( $file->isLink() ) : ?>
|
1066 |
+
<span title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'mainwp-child' ); ?></span>
|
1067 |
+
<?php
|
1068 |
+
elseif ( $file->isDir() ) :
|
1069 |
+
esc_html_e( 'Folder', 'mainwp-child' );
|
1070 |
+
else :
|
1071 |
+
esc_html_e( 'File', 'mainwp-child' );
|
1072 |
+
endif;
|
1073 |
+
?>
|
1074 |
+
</td>
|
1075 |
+
<td class="column-format">
|
1076 |
+
<?php if ( $is_unreadable ) : ?>
|
1077 |
+
<strong title="<?php esc_attr_e( 'Unreadable files won\'t be backed up.', 'mainwp-child' ); ?>"><?php esc_html_e( 'Unreadable', 'mainwp-child' ); ?></strong>
|
1078 |
+
<?php elseif ( $is_excluded ) : ?>
|
1079 |
+
<strong><?php esc_html_e( 'Excluded', 'mainwp-child' ); ?></strong>
|
1080 |
+
<?php
|
1081 |
+
else :
|
1082 |
+
$exclude_path = $file->getPathname();
|
1083 |
+
|
1084 |
+
// Excluded directories need to be trailingslashed.
|
1085 |
+
if ( $file->isDir() ) {
|
1086 |
+
$exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) );
|
1087 |
+
}
|
1088 |
+
?>
|
1089 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo rawurlencode( $exclude_path ); ?>', this)" class="button-secondary"><?php esc_html_e( 'Exclude →', 'mainwp-child' ); ?></a>
|
1090 |
+
<?php endif; ?>
|
1091 |
+
</td>
|
1092 |
+
</tr>
|
1093 |
+
<?php
|
1094 |
+
}
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
/**
|
1098 |
+
* Browse the directory.
|
1099 |
+
*
|
1100 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1101 |
+
*
|
1102 |
+
* @return array Action result.
|
1103 |
+
*/
|
1104 |
+
public function directory_browse() {
|
1105 |
+
$browse_dir = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1106 |
+
$out = array();
|
1107 |
+
$return = $this->get_excluded( $browse_dir );
|
1108 |
+
$out['e'] = $return['e'];
|
1109 |
+
$out['current_browse_dir'] = $browse_dir;
|
1110 |
+
|
1111 |
+
return $out;
|
1112 |
+
}
|
1113 |
+
|
1114 |
+
/**
|
1115 |
+
* Add exclusion rule.
|
1116 |
+
*
|
1117 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1118 |
+
*
|
1119 |
+
* @return array Action result.
|
1120 |
+
*/
|
1121 |
+
public function hmbkp_add_exclude_rule() {
|
1122 |
+
|
1123 |
+
if ( ! isset( $_POST['exclude_pathname'] ) || empty( $_POST['exclude_pathname'] ) ) {
|
1124 |
+
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
$schedule_id = $this->check_schedule();
|
1128 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1129 |
+
|
1130 |
+
$exclude_rule = isset( $_POST['exclude_pathname'] ) ? rawurldecode( wp_unslash( $_POST['exclude_pathname'] ) ) : '';
|
1131 |
+
|
1132 |
+
$schedule->set_excludes( $exclude_rule, true );
|
1133 |
+
|
1134 |
+
$schedule->save();
|
1135 |
+
|
1136 |
+
$current_path = isset( $_POST['browse_dir'] ) ? rawurldecode( wp_unslash( $_POST['browse_dir'] ) ) : '';
|
1137 |
+
|
1138 |
+
if ( empty( $current_path ) ) {
|
1139 |
+
$current_path = null;
|
1140 |
+
}
|
1141 |
+
|
1142 |
+
$return = $this->get_excluded( $current_path );
|
1143 |
+
$out['e'] = $return['e'];
|
1144 |
+
$out['current_browse_dir'] = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1145 |
+
|
1146 |
+
return $out;
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
/**
|
1150 |
+
* Remove exclusion rule.
|
1151 |
+
*
|
1152 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1153 |
+
*
|
1154 |
+
* @return array Action result.
|
1155 |
+
*/
|
1156 |
+
public function hmbkp_remove_exclude_rule() {
|
1157 |
+
|
1158 |
+
if ( ! isset( $_POST['remove_rule'] ) || empty( $_POST['remove_rule'] ) ) {
|
1159 |
+
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
$schedule_id = $this->check_schedule();
|
1163 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1164 |
+
|
1165 |
+
$excludes = $schedule->get_excludes();
|
1166 |
+
$exclude_rule_to_remove = stripslashes( sanitize_text_field( wp_unslash( $_POST['remove_rule'] ) ) );
|
1167 |
+
|
1168 |
+
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
1169 |
+
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
1170 |
+
} else {
|
1171 |
+
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
1172 |
+
}
|
1173 |
+
|
1174 |
+
$schedule->save();
|
1175 |
+
|
1176 |
+
$current_path = isset( $_POST['browse_dir'] ) ? rawurldecode( wp_unslash( $_POST['browse_dir'] ) ) : '';
|
1177 |
+
|
1178 |
+
if ( empty( $current_path ) ) {
|
1179 |
+
$current_path = null;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
$return = $this->get_excluded( $current_path );
|
1183 |
+
|
1184 |
+
$out['e'] = $return['e'];
|
1185 |
+
$out['current_browse_dir'] = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1186 |
+
|
1187 |
+
return $out;
|
1188 |
+
}
|
1189 |
+
|
1190 |
+
/**
|
1191 |
+
* General exclusion rules.
|
1192 |
+
*
|
1193 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1194 |
+
*
|
1195 |
+
* @return array Action result.
|
1196 |
+
*/
|
1197 |
+
public function general_exclude_add_rule() {
|
1198 |
+
|
1199 |
+
$sch_id = $this->check_schedule();
|
1200 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1201 |
+
|
1202 |
+
$exclude_paths = isset( $_POST['exclude_paths'] ) ? rawurldecode( wp_unslash( $_POST['exclude_paths'] ) ) : '';
|
1203 |
+
$exclude_paths = explode( "\n", $exclude_paths );
|
1204 |
+
if ( is_array( $exclude_paths ) && count( $exclude_paths ) > 0 ) {
|
1205 |
+
foreach ( $exclude_paths as $excl_rule ) {
|
1206 |
+
$excl_rule = trim( $excl_rule );
|
1207 |
+
$excl_rule = trim( $excl_rule, '/' );
|
1208 |
+
|
1209 |
+
if ( empty( $excl_rule ) ) {
|
1210 |
+
continue;
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
$exclude_rule = ABSPATH . $excl_rule;
|
1214 |
+
$path = realpath( $exclude_rule );
|
1215 |
+
if ( false !== $path ) {
|
1216 |
+
$schedule->set_excludes( $exclude_rule, true );
|
1217 |
+
$schedule->save();
|
1218 |
+
}
|
1219 |
+
}
|
1220 |
+
}
|
1221 |
+
|
1222 |
+
$un_exclude_paths = isset( $_POST['un_exclude_paths'] ) ? rawurldecode( wp_unslash( $_POST['un_exclude_paths'] ) ) : '';
|
1223 |
+
$un_exclude_paths = explode( "\n", $un_exclude_paths );
|
1224 |
+
|
1225 |
+
if ( is_array( $un_exclude_paths ) && count( get_user_excludes ) > 0 ) {
|
1226 |
+
foreach ( $un_exclude_paths as $exclude_rule_to_remove ) {
|
1227 |
+
$exclude_rule_to_remove = trim( $exclude_rule_to_remove );
|
1228 |
+
$exclude_rule_to_remove = trim( $exclude_rule_to_remove, '/' );
|
1229 |
+
|
1230 |
+
if ( empty( $exclude_rule_to_remove ) ) {
|
1231 |
+
continue;
|
1232 |
+
}
|
1233 |
+
|
1234 |
+
$excludes = $schedule->get_excludes();
|
1235 |
+
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
1236 |
+
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
1237 |
+
} else {
|
1238 |
+
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
1239 |
+
}
|
1240 |
+
$schedule->save();
|
1241 |
+
}
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
return array( 'result' => 'SUCCESS' );
|
1245 |
+
}
|
1246 |
+
|
1247 |
+
/**
|
1248 |
+
* Update backup schedule.
|
1249 |
+
*
|
1250 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1251 |
+
*
|
1252 |
+
* @return array Action result.
|
1253 |
+
*/
|
1254 |
+
public function update_schedule() {
|
1255 |
+
$sch_id = isset( $_POST['schedule_id'] ) ? sanitize_text_field( rawurldecode( wp_unslash( $_POST['schedule_id'] ) ) ) : 0;
|
1256 |
+
$options = isset( $_POST['options'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['options'] ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1257 |
+
|
1258 |
+
if ( ! is_array( $options ) || empty( $options ) || empty( $sch_id ) ) {
|
1259 |
+
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
1260 |
+
}
|
1261 |
+
|
1262 |
+
$filter_opts = array(
|
1263 |
+
'type',
|
1264 |
+
'email',
|
1265 |
+
'reoccurrence',
|
1266 |
+
'max_backups',
|
1267 |
+
'schedule_start_time',
|
1268 |
+
);
|
1269 |
+
|
1270 |
+
$out = array();
|
1271 |
+
if ( is_array( $options ) ) {
|
1272 |
+
$old_options = get_option( 'hmbkp_schedule_' . $sch_id );
|
1273 |
+
if ( is_array( $old_options ) ) {
|
1274 |
+
foreach ( $old_options as $key => $val ) {
|
1275 |
+
if ( ! in_array( $key, $filter_opts ) ) {
|
1276 |
+
$options[ $key ] = $old_options[ $key ];
|
1277 |
+
}
|
1278 |
+
}
|
1279 |
+
}
|
1280 |
+
|
1281 |
+
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1282 |
+
delete_transient( 'hmbkp_schedules' );
|
1283 |
+
$out['result'] = 'SUCCESS';
|
1284 |
+
} else {
|
1285 |
+
$out['result'] = 'NOTCHANGE';
|
1286 |
+
}
|
1287 |
+
|
1288 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1289 |
+
|
1290 |
+
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1291 |
+
// Calculate the start time depending on the recurrence.
|
1292 |
+
$start_time = $options['schedule_start_time'];
|
1293 |
+
if ( $start_time ) {
|
1294 |
+
$schedule->set_schedule_start_time( $start_time );
|
1295 |
+
}
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
if ( ! empty( $options['reoccurrence'] ) ) {
|
1299 |
+
$schedule->set_reoccurrence( $options['reoccurrence'] );
|
1300 |
+
}
|
1301 |
+
$out['next_occurrence'] = $schedule->get_next_occurrence( false );
|
1302 |
+
|
1303 |
+
return $out;
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
/**
|
1307 |
+
* Save all backup schedules.
|
1308 |
+
*
|
1309 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1310 |
+
*
|
1311 |
+
* @return array Action result.
|
1312 |
+
*/
|
1313 |
+
public function save_all_schedules() {
|
1314 |
+
$schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['all_schedules'] ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1315 |
+
|
1316 |
+
if ( ! is_array( $schedules ) || empty( $schedules ) ) {
|
1317 |
+
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
$out = array();
|
1321 |
+
foreach ( $schedules as $sch_id => $sch ) {
|
1322 |
+
if ( empty( $sch_id ) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) {
|
1323 |
+
continue;
|
1324 |
+
}
|
1325 |
+
$options = $sch['options'];
|
1326 |
+
$filter_opts = array(
|
1327 |
+
'type',
|
1328 |
+
'email',
|
1329 |
+
'reoccurrence',
|
1330 |
+
'max_backups',
|
1331 |
+
'schedule_start_time',
|
1332 |
+
);
|
1333 |
+
if ( is_array( $options ) ) {
|
1334 |
+
$old_options = get_option( 'hmbkp_schedule_' . $sch_id );
|
1335 |
+
if ( is_array( $old_options ) ) {
|
1336 |
+
foreach ( $old_options as $key => $val ) {
|
1337 |
+
if ( ! in_array( $key, $filter_opts ) ) {
|
1338 |
+
$options[ $key ] = $old_options[ $key ];
|
1339 |
+
}
|
1340 |
+
}
|
1341 |
+
}
|
1342 |
+
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1343 |
+
}
|
1344 |
+
|
1345 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1346 |
+
|
1347 |
+
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1348 |
+
// Calculate the start time depending on the recurrence.
|
1349 |
+
$start_time = $options['schedule_start_time'];
|
1350 |
+
if ( $start_time ) {
|
1351 |
+
$schedule->set_schedule_start_time( $start_time );
|
1352 |
+
}
|
1353 |
+
}
|
1354 |
+
|
1355 |
+
if ( ! empty( $options['reoccurrence'] ) ) {
|
1356 |
+
$schedule->set_reoccurrence( $options['reoccurrence'] );
|
1357 |
+
}
|
1358 |
+
$out['result'] = 'SUCCESS';
|
1359 |
+
}
|
1360 |
+
delete_transient( 'hmbkp_schedules' );
|
1361 |
+
return $out;
|
1362 |
+
}
|
1363 |
+
|
1364 |
+
/**
|
1365 |
+
* Check if the BacupWordPress plugin is activated.
|
1366 |
+
*
|
1367 |
+
* @return bool Return true if the plugin is activated, false if not.
|
1368 |
+
*/
|
1369 |
+
public static function is_activated() {
|
1370 |
+
if ( ! defined( 'HMBKP_PLUGIN_PATH' ) || ! class_exists( '\HM\BackUpWordPress\Plugin' ) ) {
|
1371 |
+
return false;
|
1372 |
+
}
|
1373 |
+
|
1374 |
+
return true;
|
1375 |
+
}
|
1376 |
+
|
1377 |
+
/**
|
1378 |
+
* Remove the BackupWordPress plugin from the list of all plugins when the plugin is hidden.
|
1379 |
+
*
|
1380 |
+
* @param array $plugins Array containing all installed plugins.
|
1381 |
+
*
|
1382 |
+
* @return array $plugins Array containing all installed plugins without the BackupWordPress.
|
1383 |
+
*/
|
1384 |
+
public function all_plugins( $plugins ) {
|
1385 |
+
foreach ( $plugins as $key => $value ) {
|
1386 |
+
$plugin_slug = basename( $key, '.php' );
|
1387 |
+
if ( 'backupwordpress' === $plugin_slug ) {
|
1388 |
+
unset( $plugins[ $key ] );
|
1389 |
+
}
|
1390 |
+
}
|
1391 |
+
|
1392 |
+
return $plugins;
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
/**
|
1396 |
+
* Remove the BackupWordPress menu item when the plugin is hidden.
|
1397 |
+
*
|
1398 |
+
* @uses wp_safe_redirect() Performs a safe (local) redirect, using wp_redirect().
|
1399 |
+
* @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
|
1400 |
+
*
|
1401 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
1402 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
1403 |
+
*/
|
1404 |
+
public function remove_menu() {
|
1405 |
+
|
1406 |
+
/**
|
1407 |
+
* Submenu array.
|
1408 |
+
*
|
1409 |
+
* @global object
|
1410 |
+
*/
|
1411 |
+
global $submenu;
|
1412 |
+
|
1413 |
+
if ( isset( $submenu['tools.php'] ) ) {
|
1414 |
+
foreach ( $submenu['tools.php'] as $index => $item ) {
|
1415 |
+
if ( 'backupwordpress' === $item[2] ) {
|
1416 |
+
unset( $submenu['tools.php'][ $index ] );
|
1417 |
+
break;
|
1418 |
+
}
|
1419 |
+
}
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
$pos = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'tools.php?page=backupwordpress' ) : false;
|
1423 |
+
if ( false !== $pos ) {
|
1424 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
1425 |
+
exit();
|
1426 |
+
}
|
1427 |
+
}
|
1428 |
+
}
|
|
|
|
class/class-mainwp-child-back-wp-up.php
CHANGED
@@ -1,1974 +1,1954 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child BackWP UP
|
4 |
-
*
|
5 |
-
* This file handles specific action for the MainWP BackWPup Extension.
|
6 |
-
*
|
7 |
-
* Credits
|
8 |
-
*
|
9 |
-
* Plugin-Name: BackWPup
|
10 |
-
* Plugin-URI: http://backwpup.com
|
11 |
-
* Author: Inpsyde GmbH
|
12 |
-
* Author URI: http://inpsyde.com
|
13 |
-
* License: GPLv3
|
14 |
-
* License URI: http://www.gnu.org/licenses/gpl-3.0
|
15 |
-
*
|
16 |
-
* The code is used for the MainWP BackWPup Extension
|
17 |
-
* Extension URL: https://mainwp.com/extension/backwpup/
|
18 |
-
*
|
19 |
-
* @package MainWP\Child
|
20 |
-
*/
|
21 |
-
|
22 |
-
// phpcs:disable -- third party credit.
|
23 |
-
|
24 |
-
namespace MainWP\Child;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Class MainWP_Child_Back_WP_Up
|
28 |
-
*/
|
29 |
-
class MainWP_Child_Back_WP_Up {
|
30 |
-
|
31 |
-
/**
|
32 |
-
* @var bool Whether or not BackWPup plugin is installed. Default: false.
|
33 |
-
*/
|
34 |
-
public $is_backwpup_installed = false;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* @var bool Whether or not BackWPup is Pro version. Default: false.
|
38 |
-
*/
|
39 |
-
public $is_backwpup_pro = false;
|
40 |
-
|
41 |
-
/**
|
42 |
-
* @var string Plugin slug translation string.
|
43 |
-
*/
|
44 |
-
public $plugin_translate = 'mainwp-backwpup-extension';
|
45 |
-
|
46 |
-
/**
|
47 |
-
* @static
|
48 |
-
* @var null Holds the Public static instance of MainWP_Child_Back_WP_Up
|
49 |
-
*/
|
50 |
-
public static $instance = null;
|
51 |
-
|
52 |
-
/** @var string Software version. */
|
53 |
-
protected $software_version = '0.1';
|
54 |
-
|
55 |
-
/** @var array Returned response array for MainWP BackWPup Extension actions. */
|
56 |
-
public static $information = array();
|
57 |
-
|
58 |
-
/** @var string[][] backwpup_cfg variables. */
|
59 |
-
protected $exclusions = array(
|
60 |
-
'cron' => array(
|
61 |
-
'cronminutes',
|
62 |
-
'cronhours',
|
63 |
-
'cronmday',
|
64 |
-
'cronmon',
|
65 |
-
'cronwday',
|
66 |
-
'moncronminutes',
|
67 |
-
'moncronhours',
|
68 |
-
'moncronmday',
|
69 |
-
'weekcronminutes',
|
70 |
-
'weekcronhours',
|
71 |
-
'weekcronwday',
|
72 |
-
'daycronminutes',
|
73 |
-
'daycronhours',
|
74 |
-
'hourcronminutes',
|
75 |
-
'cronbtype',
|
76 |
-
),
|
77 |
-
'dest-EMAIL' => array( 'emailpass' ),
|
78 |
-
'dest-DBDUMP' => array( 'dbdumpspecialsetalltables' ),
|
79 |
-
'dest-FTP' => array( 'ftppass' ),
|
80 |
-
'dest-S3' => array( 's3secretkey' ),
|
81 |
-
'dest-MSAZURE' => array( 'msazurekey' ),
|
82 |
-
'dest-SUGARSYNC' => array( 'sugaremail', 'sugarpass', 'sugarrefreshtoken' ),
|
83 |
-
'dest-GDRIVE' => array( 'gdriverefreshtoken' ),
|
84 |
-
'dest-RSC' => array( 'rscapikey' ),
|
85 |
-
'dest-GLACIER' => array( 'glaciersecretkey' ),
|
86 |
-
);
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Create a public static instance of MainWP_Child_Back_WP_Up.
|
90 |
-
*
|
91 |
-
* @return MainWP_Child_Back_WP_Up|null
|
92 |
-
*/
|
93 |
-
public static function instance() {
|
94 |
-
if ( null == self::$instance ) {
|
95 |
-
self::$instance = new self();
|
96 |
-
}
|
97 |
-
|
98 |
-
return self::$instance;
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* MainWP_Child_Back_WP_Up constructor.
|
103 |
-
*
|
104 |
-
* Run any time the class is called.
|
105 |
-
*
|
106 |
-
* @uses MainWP_Helper::check_files_exists()
|
107 |
-
* @uses MainWP_Helper::check_classes_exists()
|
108 |
-
* @uses MainWP_Helper::check_methods()
|
109 |
-
* @uses \BackWPup::get_instance()
|
110 |
-
* @uses \Exception
|
111 |
-
*/
|
112 |
-
public function __construct() {
|
113 |
-
|
114 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
115 |
-
|
116 |
-
try {
|
117 |
-
|
118 |
-
if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
|
119 |
-
$file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php';
|
120 |
-
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php';
|
121 |
-
|
122 |
-
if ( ! file_exists( $file_path2 ) ) {
|
123 |
-
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php';
|
124 |
-
}
|
125 |
-
|
126 |
-
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
127 |
-
require_once $file_path1;
|
128 |
-
require_once $file_path2;
|
129 |
-
$this->is_backwpup_installed = true;
|
130 |
-
$this->is_backwpup_pro = true;
|
131 |
-
} elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
|
132 |
-
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
|
133 |
-
MainWP_Helper::check_files_exists( array( $file_path ) );
|
134 |
-
require_once $file_path;
|
135 |
-
$this->is_backwpup_installed = true;
|
136 |
-
}
|
137 |
-
|
138 |
-
if ( $this->is_backwpup_installed ) {
|
139 |
-
MainWP_Helper::check_classes_exists( '\BackWPup' );
|
140 |
-
MainWP_Helper::check_methods( 'get_instance' );
|
141 |
-
\BackWPup::get_instance();
|
142 |
-
|
143 |
-
add_action( 'admin_init', array( $this, 'init_download_backup' ) );
|
144 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
145 |
-
}
|
146 |
-
} catch ( \Exception $e ) {
|
147 |
-
$this->is_backwpup_installed = false;
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* MainWP BackWPup fatal error handler.
|
153 |
-
*
|
154 |
-
* @uses MainWP_Child_Back_WP_Up::$information
|
155 |
-
* @uses MainWP_Helper::write()
|
156 |
-
*/
|
157 |
-
public static function mainwp_backwpup_handle_fatal_error() {
|
158 |
-
|
159 |
-
$error = error_get_last();
|
160 |
-
$info = self::$information;
|
161 |
-
|
162 |
-
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
|
163 |
-
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
164 |
-
} elseif ( ! empty( $info ) ) {
|
165 |
-
MainWP_Helper::write( self::$information );
|
166 |
-
} else {
|
167 |
-
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* MainWP BackWPup Extension actions.
|
173 |
-
*
|
174 |
-
* @uses MainWP_Child_Back_WP_Up::update_settings()
|
175 |
-
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs()
|
176 |
-
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs_global()
|
177 |
-
* @uses MainWP_Child_Back_WP_Up::get_child_tables()
|
178 |
-
* @uses MainWP_Child_Back_WP_Up::get_job_files()
|
179 |
-
* @uses MainWP_Child_Back_WP_Up::destination_email_check_email()
|
180 |
-
* @uses MainWP_Child_Back_WP_Up::backup_now()
|
181 |
-
* @uses MainWP_Child_Back_WP_Up::ajax_working()
|
182 |
-
* @uses MainWP_Child_Back_WP_Up::backup_abort()
|
183 |
-
* @uses MainWP_Child_Back_WP_Up::tables()
|
184 |
-
* @uses MainWP_Child_Back_WP_Up::view_log()
|
185 |
-
* @uses MainWP_Child_Back_WP_Up::delete_log()
|
186 |
-
* @uses MainWP_Child_Back_WP_Up::delete_job()
|
187 |
-
* @uses MainWP_Child_Back_WP_Up::delete_backup()
|
188 |
-
* @uses MainWP_Child_Back_WP_Up::wizard_system_scan()
|
189 |
-
* @uses MainWP_Child_Back_WP_Up::is_backwpup_pro()
|
190 |
-
* @uses MainWP_Child_Back_WP_Up::show_hide()
|
191 |
-
* @uses MainWP_Child_Back_WP_Up::$information
|
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 |
-
* @uses \MainWP\Child\
|
326 |
-
* @uses \MainWP\Child\
|
327 |
-
* @uses \
|
328 |
-
* @uses \
|
329 |
-
* @uses \
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
if (
|
336 |
-
return;
|
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 |
-
* @uses \
|
453 |
-
* @uses \
|
454 |
-
*
|
455 |
-
* @
|
456 |
-
* @
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
if ( $
|
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 |
-
// Remove the WordPress Admin
|
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 |
-
echo '<tr title=""><td>' . __( '
|
626 |
-
echo '<tr title="
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
if ( defined( '
|
633 |
-
echo '<tr title="
|
634 |
-
} else {
|
635 |
-
echo '<tr title="
|
636 |
-
}
|
637 |
-
if ( defined( '
|
638 |
-
echo '<tr title="
|
639 |
-
} else {
|
640 |
-
echo '<tr title="
|
641 |
-
}
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
echo '<tr title="
|
650 |
-
echo
|
651 |
-
echo '</td></tr>';
|
652 |
-
echo '<tr title="
|
653 |
-
echo '<tr title="
|
654 |
-
echo '<tr title="
|
655 |
-
echo
|
656 |
-
echo '
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
echo '</
|
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 |
-
* @uses
|
832 |
-
* @uses \
|
833 |
-
* @uses \
|
834 |
-
* @uses \
|
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 |
-
$output
|
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 |
-
break;
|
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 |
-
$temp_array['lastrun'] = __( '
|
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 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
if ( !
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
$dest_class
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
$
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
*
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
$expected = substr( wp_hash(
|
1091 |
-
if ( hash_equals( $expected, $nonce ) ) {
|
1092 |
-
return
|
1093 |
-
}
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
*
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
$
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
);
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
*
|
1163 |
-
*
|
1164 |
-
* @
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
$
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
'
|
1201 |
-
'
|
1202 |
-
);
|
1203 |
-
}
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
*
|
1214 |
-
*
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
$
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
);
|
1237 |
-
}
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
$
|
1360 |
-
$
|
1361 |
-
$
|
1362 |
-
$
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
'
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
'
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
$
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
$
|
1611 |
-
}
|
1612 |
-
|
1613 |
-
$
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
$
|
1664 |
-
$
|
1665 |
-
|
1666 |
-
$
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
'
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
'
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
)
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
-
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
$
|
1783 |
-
|
1784 |
-
|
1785 |
-
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
}
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
|
1839 |
-
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
|
1848 |
-
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
'
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
$
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
if (
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
}
|
1912 |
-
|
1913 |
-
|
1914 |
-
'
|
1915 |
-
'
|
1916 |
-
'
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
|
1931 |
-
}
|
1932 |
-
|
1933 |
-
|
1934 |
-
'
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
*
|
1943 |
-
*
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
}
|
1956 |
-
}
|
1957 |
-
}
|
1958 |
-
|
1959 |
-
// phpcs:disable Generic.Files.OneObjectStructurePerFile -- fake class
|
1960 |
-
if ( ! class_exists( '\MainWP\Child\MainWP_Fake_Wp_Screen' ) ) {
|
1961 |
-
/**
|
1962 |
-
* Class MainWP_Fake_Wp_Screen
|
1963 |
-
*
|
1964 |
-
* @used-by MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1965 |
-
*/
|
1966 |
-
class MainWP_Fake_Wp_Screen {
|
1967 |
-
/** @var string Action. */
|
1968 |
-
public $action;
|
1969 |
-
/** @var string Base url. */
|
1970 |
-
public $base;
|
1971 |
-
/** @var int ID*/
|
1972 |
-
public $id;
|
1973 |
-
}
|
1974 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child BackWP UP
|
4 |
+
*
|
5 |
+
* This file handles specific action for the MainWP BackWPup Extension.
|
6 |
+
*
|
7 |
+
* Credits
|
8 |
+
*
|
9 |
+
* Plugin-Name: BackWPup
|
10 |
+
* Plugin-URI: http://backwpup.com
|
11 |
+
* Author: Inpsyde GmbH
|
12 |
+
* Author URI: http://inpsyde.com
|
13 |
+
* License: GPLv3
|
14 |
+
* License URI: http://www.gnu.org/licenses/gpl-3.0
|
15 |
+
*
|
16 |
+
* The code is used for the MainWP BackWPup Extension
|
17 |
+
* Extension URL: https://mainwp.com/extension/backwpup/
|
18 |
+
*
|
19 |
+
* @package MainWP\Child
|
20 |
+
*/
|
21 |
+
|
22 |
+
// phpcs:disable -- third party credit.
|
23 |
+
|
24 |
+
namespace MainWP\Child;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Class MainWP_Child_Back_WP_Up
|
28 |
+
*/
|
29 |
+
class MainWP_Child_Back_WP_Up {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @var bool Whether or not BackWPup plugin is installed. Default: false.
|
33 |
+
*/
|
34 |
+
public $is_backwpup_installed = false;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @var bool Whether or not BackWPup is Pro version. Default: false.
|
38 |
+
*/
|
39 |
+
public $is_backwpup_pro = false;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @var string Plugin slug translation string.
|
43 |
+
*/
|
44 |
+
public $plugin_translate = 'mainwp-backwpup-extension';
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @static
|
48 |
+
* @var null Holds the Public static instance of MainWP_Child_Back_WP_Up
|
49 |
+
*/
|
50 |
+
public static $instance = null;
|
51 |
+
|
52 |
+
/** @var string Software version. */
|
53 |
+
protected $software_version = '0.1';
|
54 |
+
|
55 |
+
/** @var array Returned response array for MainWP BackWPup Extension actions. */
|
56 |
+
public static $information = array();
|
57 |
+
|
58 |
+
/** @var string[][] backwpup_cfg variables. */
|
59 |
+
protected $exclusions = array(
|
60 |
+
'cron' => array(
|
61 |
+
'cronminutes',
|
62 |
+
'cronhours',
|
63 |
+
'cronmday',
|
64 |
+
'cronmon',
|
65 |
+
'cronwday',
|
66 |
+
'moncronminutes',
|
67 |
+
'moncronhours',
|
68 |
+
'moncronmday',
|
69 |
+
'weekcronminutes',
|
70 |
+
'weekcronhours',
|
71 |
+
'weekcronwday',
|
72 |
+
'daycronminutes',
|
73 |
+
'daycronhours',
|
74 |
+
'hourcronminutes',
|
75 |
+
'cronbtype',
|
76 |
+
),
|
77 |
+
'dest-EMAIL' => array( 'emailpass' ),
|
78 |
+
'dest-DBDUMP' => array( 'dbdumpspecialsetalltables' ),
|
79 |
+
'dest-FTP' => array( 'ftppass' ),
|
80 |
+
'dest-S3' => array( 's3secretkey' ),
|
81 |
+
'dest-MSAZURE' => array( 'msazurekey' ),
|
82 |
+
'dest-SUGARSYNC' => array( 'sugaremail', 'sugarpass', 'sugarrefreshtoken' ),
|
83 |
+
'dest-GDRIVE' => array( 'gdriverefreshtoken' ),
|
84 |
+
'dest-RSC' => array( 'rscapikey' ),
|
85 |
+
'dest-GLACIER' => array( 'glaciersecretkey' ),
|
86 |
+
);
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Create a public static instance of MainWP_Child_Back_WP_Up.
|
90 |
+
*
|
91 |
+
* @return MainWP_Child_Back_WP_Up|null
|
92 |
+
*/
|
93 |
+
public static function instance() {
|
94 |
+
if ( null == self::$instance ) {
|
95 |
+
self::$instance = new self();
|
96 |
+
}
|
97 |
+
|
98 |
+
return self::$instance;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* MainWP_Child_Back_WP_Up constructor.
|
103 |
+
*
|
104 |
+
* Run any time the class is called.
|
105 |
+
*
|
106 |
+
* @uses \MainWP\Child\MainWP_Helper::check_files_exists()
|
107 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
108 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
109 |
+
* @uses \BackWPup::get_instance()
|
110 |
+
* @uses \Exception
|
111 |
+
*/
|
112 |
+
public function __construct() {
|
113 |
+
|
114 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
115 |
+
|
116 |
+
try {
|
117 |
+
|
118 |
+
if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
|
119 |
+
$file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php';
|
120 |
+
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php';
|
121 |
+
|
122 |
+
if ( ! file_exists( $file_path2 ) ) {
|
123 |
+
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php';
|
124 |
+
}
|
125 |
+
|
126 |
+
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
127 |
+
require_once $file_path1;
|
128 |
+
require_once $file_path2;
|
129 |
+
$this->is_backwpup_installed = true;
|
130 |
+
$this->is_backwpup_pro = true;
|
131 |
+
} elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
|
132 |
+
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
|
133 |
+
MainWP_Helper::check_files_exists( array( $file_path ) );
|
134 |
+
require_once $file_path;
|
135 |
+
$this->is_backwpup_installed = true;
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( $this->is_backwpup_installed ) {
|
139 |
+
MainWP_Helper::check_classes_exists( '\BackWPup' );
|
140 |
+
MainWP_Helper::check_methods( 'get_instance' );
|
141 |
+
\BackWPup::get_instance();
|
142 |
+
|
143 |
+
add_action( 'admin_init', array( $this, 'init_download_backup' ) );
|
144 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
145 |
+
}
|
146 |
+
} catch ( \Exception $e ) {
|
147 |
+
$this->is_backwpup_installed = false;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* MainWP BackWPup fatal error handler.
|
153 |
+
*
|
154 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::$information
|
155 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
156 |
+
*/
|
157 |
+
public static function mainwp_backwpup_handle_fatal_error() {
|
158 |
+
|
159 |
+
$error = error_get_last();
|
160 |
+
$info = self::$information;
|
161 |
+
|
162 |
+
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
|
163 |
+
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
164 |
+
} elseif ( ! empty( $info ) ) {
|
165 |
+
MainWP_Helper::write( self::$information );
|
166 |
+
} else {
|
167 |
+
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* MainWP BackWPup Extension actions.
|
173 |
+
*
|
174 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::update_settings()
|
175 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::insert_or_update_jobs()
|
176 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::insert_or_update_jobs_global()
|
177 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::get_child_tables()
|
178 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::get_job_files()
|
179 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::destination_email_check_email()
|
180 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::backup_now()
|
181 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::ajax_working()
|
182 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::backup_abort()
|
183 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::tables()
|
184 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::view_log()
|
185 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::delete_log()
|
186 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::delete_job()
|
187 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::delete_backup()
|
188 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::wizard_system_scan()
|
189 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::is_backwpup_pro()
|
190 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::show_hide()
|
191 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::$information
|
192 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::mainwp_backwpup_handle_fatal_error()
|
193 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
194 |
+
*/
|
195 |
+
public function action() {
|
196 |
+
if ( ! $this->is_backwpup_installed ) {
|
197 |
+
MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) );
|
198 |
+
return;
|
199 |
+
}
|
200 |
+
register_shutdown_function( '\MainWP\Child\MainWP_Child_Back_WP_Up::mainwp_backwpup_handle_fatal_error' );
|
201 |
+
|
202 |
+
$information = array();
|
203 |
+
|
204 |
+
if ( ! isset( $_POST['action'] ) ) {
|
205 |
+
$information = array( 'error' => __( 'Missing action.', 'mainwp-child' ) );
|
206 |
+
} else {
|
207 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
208 |
+
switch ( $mwp_action ) {
|
209 |
+
case 'backwpup_update_settings':
|
210 |
+
$information = $this->update_settings();
|
211 |
+
break;
|
212 |
+
|
213 |
+
case 'backwpup_insert_or_update_jobs':
|
214 |
+
$information = $this->insert_or_update_jobs();
|
215 |
+
break;
|
216 |
+
|
217 |
+
case 'backwpup_insert_or_update_jobs_global':
|
218 |
+
$information = $this->insert_or_update_jobs_global();
|
219 |
+
break;
|
220 |
+
|
221 |
+
case 'backwpup_get_child_tables':
|
222 |
+
$information = $this->get_child_tables();
|
223 |
+
break;
|
224 |
+
|
225 |
+
case 'backwpup_get_job_files':
|
226 |
+
$information = $this->get_job_files();
|
227 |
+
break;
|
228 |
+
|
229 |
+
case 'backwpup_destination_email_check_email':
|
230 |
+
$information = $this->destination_email_check_email();
|
231 |
+
break;
|
232 |
+
|
233 |
+
case 'backwpup_backup_now':
|
234 |
+
$information = $this->backup_now();
|
235 |
+
break;
|
236 |
+
|
237 |
+
case 'backwpup_ajax_working':
|
238 |
+
$information = $this->ajax_working();
|
239 |
+
break;
|
240 |
+
|
241 |
+
case 'backwpup_backup_abort':
|
242 |
+
$information = $this->backup_abort();
|
243 |
+
break;
|
244 |
+
|
245 |
+
case 'backwpup_tables':
|
246 |
+
$information = $this->tables();
|
247 |
+
break;
|
248 |
+
|
249 |
+
case 'backwpup_view_log':
|
250 |
+
$information = $this->view_log();
|
251 |
+
break;
|
252 |
+
|
253 |
+
case 'backwpup_delete_log':
|
254 |
+
$information = $this->delete_log();
|
255 |
+
break;
|
256 |
+
|
257 |
+
case 'backwpup_delete_job':
|
258 |
+
$information = $this->delete_job();
|
259 |
+
break;
|
260 |
+
|
261 |
+
case 'backwpup_delete_backup':
|
262 |
+
$information = $this->delete_backup();
|
263 |
+
break;
|
264 |
+
|
265 |
+
case 'backwpup_information':
|
266 |
+
$information = $this->information();
|
267 |
+
break;
|
268 |
+
|
269 |
+
case 'backwpup_wizard_system_scan':
|
270 |
+
$information = $this->wizard_system_scan();
|
271 |
+
break;
|
272 |
+
|
273 |
+
case 'backwpup_is_pro':
|
274 |
+
$information = array( 'is_pro' => $this->is_backwpup_pro );
|
275 |
+
break;
|
276 |
+
|
277 |
+
case 'backwpup_show_hide':
|
278 |
+
$information = $this->show_hide();
|
279 |
+
break;
|
280 |
+
|
281 |
+
default:
|
282 |
+
$information = array( 'error' => __( 'Wrong action.', 'mainwp-child' ) );
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
self::$information = $information;
|
287 |
+
exit();
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* MainWP BackWPup Extension initiation.
|
292 |
+
*/
|
293 |
+
public function init() {
|
294 |
+
|
295 |
+
if ( ! $this->is_backwpup_installed ) {
|
296 |
+
return;
|
297 |
+
}
|
298 |
+
|
299 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
300 |
+
|
301 |
+
if ( get_option( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) {
|
302 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
303 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Record BackWPup MainWP Child Reports log.
|
309 |
+
*
|
310 |
+
* @uses MainWP_Child_Back_WP_Up::do_reports_log()
|
311 |
+
*/
|
312 |
+
public function do_site_stats() {
|
313 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
314 |
+
do_action( 'mainwp_child_reports_log', 'backwpup' );
|
315 |
+
} else {
|
316 |
+
$this->do_reports_log( 'backwpup' );
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Create BackWPup MainWP Client Reports log.
|
322 |
+
*
|
323 |
+
* @param string $ext Extension to create log for.
|
324 |
+
*
|
325 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::is_backwpup_installed()
|
326 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
327 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
328 |
+
* @uses \MainWP\Child\MainWP_Utility::get_lasttime_backup()
|
329 |
+
* @uses \MainWP\Child\MainWP_Utility::update_lasttime_backup()
|
330 |
+
* @uses \BackWPup_File::get_absolute_path()
|
331 |
+
* @uses \BackWPup_Job::read_logheader()
|
332 |
+
* @uses \Exception
|
333 |
+
*/
|
334 |
+
public function do_reports_log($ext = '' ) {
|
335 |
+
if ( 'backwpup' !== $ext ) {
|
336 |
+
return;
|
337 |
+
}
|
338 |
+
if ( ! $this->is_backwpup_installed ) {
|
339 |
+
return;
|
340 |
+
}
|
341 |
+
|
342 |
+
try {
|
343 |
+
|
344 |
+
MainWP_Helper::check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) );
|
345 |
+
MainWP_Helper::check_methods( '\BackWPup_File', array( 'get_absolute_path' ) );
|
346 |
+
MainWP_Helper::check_methods( '\BackWPup_Job', array( 'read_logheader' ) );
|
347 |
+
$lasttime_logged = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
348 |
+
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
349 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
350 |
+
$log_folder = untrailingslashit( $log_folder );
|
351 |
+
|
352 |
+
$logfiles = array();
|
353 |
+
$dir = opendir( $log_folder );
|
354 |
+
if ( is_readable( $log_folder ) && $dir ) {
|
355 |
+
while ( ( $file = readdir( $dir ) ) !== false ) {
|
356 |
+
$log_file = $log_folder . '/' . $file;
|
357 |
+
if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) {
|
358 |
+
$logfiles[] = $file;
|
359 |
+
}
|
360 |
+
}
|
361 |
+
closedir( $dir );
|
362 |
+
}
|
363 |
+
|
364 |
+
$log_items = array();
|
365 |
+
foreach ( $logfiles as $mtime => $logfile ) {
|
366 |
+
$meta = \BackWPup_Job::read_logheader( $log_folder . '/' . $logfile );
|
367 |
+
if ( ! isset( $meta['logtime'] ) || $meta['logtime'] < $lasttime_logged ) {
|
368 |
+
continue;
|
369 |
+
}
|
370 |
+
|
371 |
+
if ( isset( $meta['errors'] ) && ! empty( $meta['errors'] ) ) {
|
372 |
+
continue;
|
373 |
+
}
|
374 |
+
|
375 |
+
$log_items[ $mtime ] = $meta;
|
376 |
+
$log_items[ $mtime ]['file'] = $logfile;
|
377 |
+
}
|
378 |
+
|
379 |
+
if ( ! empty( $log_items ) ) {
|
380 |
+
$job_types = array(
|
381 |
+
'DBDUMP' => __( 'Database backup', 'mainwp-child' ),
|
382 |
+
'FILE' => __( 'File backup', 'mainwp-child' ),
|
383 |
+
'WPEXP' => __( 'WordPress XML export', 'mainwp-child' ),
|
384 |
+
'WPPLUGIN' => __( 'Installed plugins list', 'mainwp-child' ),
|
385 |
+
'DBCHECK' => __( 'Check database tables', 'mainwp-child' ),
|
386 |
+
);
|
387 |
+
|
388 |
+
$new_lasttime_logged = $lasttime_logged;
|
389 |
+
|
390 |
+
foreach ( $log_items as $log ) {
|
391 |
+
$backup_time = $log['logtime'];
|
392 |
+
if ( $backup_time < $lasttime_logged ) {
|
393 |
+
continue;
|
394 |
+
}
|
395 |
+
$job_job_types = explode( '+', $log['type'] );
|
396 |
+
$backup_type = '';
|
397 |
+
foreach ( $job_job_types as $typeid ) {
|
398 |
+
if ( isset( $job_types[ $typeid ] ) ) {
|
399 |
+
$backup_type .= ' + ' . $job_types[ $typeid ];
|
400 |
+
}
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( empty( $backup_type ) ) {
|
404 |
+
continue;
|
405 |
+
} else {
|
406 |
+
$backup_type = ltrim( $backup_type, ' + ' );
|
407 |
+
}
|
408 |
+
$message = 'BackWPup backup finished (' . $backup_type . ')';
|
409 |
+
do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
|
410 |
+
|
411 |
+
if ( $new_lasttime_logged < $backup_time ) {
|
412 |
+
$new_lasttime_logged = $backup_time;
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
if ( $new_lasttime_logged > $lasttime_logged ) {
|
417 |
+
MainWP_Utility::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature.
|
418 |
+
}
|
419 |
+
}
|
420 |
+
} catch ( \Exception $ex ) {
|
421 |
+
// ok!
|
422 |
+
}
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Sync other data from $data[] and merge with $information[]
|
427 |
+
*
|
428 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
429 |
+
* @param array $data Other data to sync to $information array.
|
430 |
+
*
|
431 |
+
* @return array $information Returned information array with both sets of data.
|
432 |
+
*
|
433 |
+
* @uses \MainWP\Child\MainWP_Utility::get_lasttime_backup()
|
434 |
+
*/
|
435 |
+
public function sync_others_data($information, $data = array() ) {
|
436 |
+
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
|
437 |
+
try {
|
438 |
+
$lastbackup = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
439 |
+
$information['syncBackwpupData'] = array(
|
440 |
+
'lastbackup' => $lastbackup,
|
441 |
+
);
|
442 |
+
} catch ( \Exception $e ) {
|
443 |
+
// ok!
|
444 |
+
}
|
445 |
+
}
|
446 |
+
return $information;
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Get backup destinations list.
|
451 |
+
*
|
452 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
453 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
454 |
+
* @uses \BackWPup_Option::get_job_ids()
|
455 |
+
* @uses \BackWPup::get_registered_destinations()
|
456 |
+
* @uses \BackWPup_Option::get()
|
457 |
+
* @uses \BackWPup::get_destination()
|
458 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
459 |
+
*
|
460 |
+
* @return array $jobdest Backup destination list.
|
461 |
+
* @throws Exception Error Message.
|
462 |
+
*/
|
463 |
+
public function get_destinations_list() {
|
464 |
+
MainWP_Helper::check_classes_exists( array( '\BackWPup', '\BackWPup_Option' ) );
|
465 |
+
MainWP_Helper::check_methods( '\BackWPup', array( 'get_registered_destinations', 'get_destination' ) );
|
466 |
+
MainWP_Helper::check_methods( '\BackWPup_Option', array( 'get_job_ids', 'get' ) );
|
467 |
+
|
468 |
+
$jobdest = array();
|
469 |
+
$jobids = \BackWPup_Option::get_job_ids();
|
470 |
+
$destinations = \BackWPup::get_registered_destinations();
|
471 |
+
foreach ( $jobids as $jobid ) {
|
472 |
+
if ( \BackWPup_Option::get( $jobid, 'backuptype' ) === 'sync' ) {
|
473 |
+
continue;
|
474 |
+
}
|
475 |
+
$dests = \BackWPup_Option::get( $jobid, 'destinations' );
|
476 |
+
foreach ( $dests as $dest ) {
|
477 |
+
if ( ! $destinations[ $dest ]['class'] ) {
|
478 |
+
continue;
|
479 |
+
}
|
480 |
+
|
481 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
482 |
+
if ( $dest_class && method_exists( $dest_class, 'file_get_list' ) ) {
|
483 |
+
$can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest );
|
484 |
+
if ( ! empty( $can_do_dest ) ) {
|
485 |
+
$jobdest[] = $jobid . '_' . $dest;
|
486 |
+
}
|
487 |
+
}
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
return $jobdest;
|
492 |
+
}
|
493 |
+
|
494 |
+
/**
|
495 |
+
* Hide BackWPup Plugin from the WordPress Installed plugin list.
|
496 |
+
*
|
497 |
+
* @param array $plugins Installed plugins.
|
498 |
+
* @return array $plugins Installed plugins without BackWPup Plugin on the list.
|
499 |
+
*/
|
500 |
+
public function all_plugins( $plugins ) {
|
501 |
+
foreach ( $plugins as $key => $value ) {
|
502 |
+
$plugin_slug = basename( $key, '.php' );
|
503 |
+
if ( 'backwpup' === $plugin_slug ) {
|
504 |
+
unset( $plugins[ $key ] );
|
505 |
+
}
|
506 |
+
}
|
507 |
+
|
508 |
+
return $plugins;
|
509 |
+
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Remove BackWPup Plugin from the WordPress Admin.
|
513 |
+
*/
|
514 |
+
public function remove_menu() {
|
515 |
+
|
516 |
+
/** @global object $submenu WordPress Submenu array. */
|
517 |
+
global $submenu;
|
518 |
+
|
519 |
+
// Remove the WordPress Admin SubMenu.
|
520 |
+
if ( isset( $submenu['backwpup'] ) ) {
|
521 |
+
unset( $submenu['backwpup'] );
|
522 |
+
}
|
523 |
+
|
524 |
+
// Remove the WordPress Admin Page.
|
525 |
+
remove_menu_page( 'backwpup' );
|
526 |
+
|
527 |
+
// Create a WP Safe Redirect for the page URL.
|
528 |
+
$pos = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=backwpup' ) : false;
|
529 |
+
if ( false !== $pos ) {
|
530 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
531 |
+
exit();
|
532 |
+
}
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Show/Hide BackWPup Plugin.
|
537 |
+
*
|
538 |
+
* @return int[]|string Return 1 on HIDE, Empty string on SHOW.
|
539 |
+
*
|
540 |
+
* @uses MainWP_Helper::instance()::update_option()
|
541 |
+
*/
|
542 |
+
protected function show_hide() {
|
543 |
+
|
544 |
+
$hide = isset( $_POST['show_hide'] ) && ( '1' === $_POST['show_hide'] ) ? 'hide' : '';
|
545 |
+
|
546 |
+
MainWP_Helper::instance()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' );
|
547 |
+
|
548 |
+
return array( 'success' => 1 );
|
549 |
+
}
|
550 |
+
|
551 |
+
/**
|
552 |
+
* Build the MainWP BackWPup Page Settings.
|
553 |
+
* @return array $output Returned information array.
|
554 |
+
*/
|
555 |
+
protected function information() {
|
556 |
+
|
557 |
+
/** @global $wpdb wpdb */
|
558 |
+
global $wpdb;
|
559 |
+
|
560 |
+
// Copied from BackWPup_Page_Settings.
|
561 |
+
ob_start();
|
562 |
+
echo '<table class="wp-list-table widefat fixed" cellspacing="0" style="width: 85%;margin-left:auto;;margin-right:auto;">';
|
563 |
+
echo '<thead><tr><th width="35%">' . __( 'Setting', 'mainwp-child' ) . '</th><th>' . __( 'Value', 'mainwp-child' ) . '</th></tr></thead>';
|
564 |
+
echo '<tfoot><tr><th>' . __( 'Setting', 'mainwp-child' ) . '</th><th>' . __( 'Value', 'mainwp-child' ) . '</th></tr></tfoot>';
|
565 |
+
echo '<tr title=">=3.2"><td>' . __( 'WordPress version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'wp_version' ) ) . '</td></tr>';
|
566 |
+
if ( ! class_exists( '\BackWPup_Pro', false ) ) {
|
567 |
+
echo '<tr title=""><td>' . __( 'BackWPup version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . ' <a href="' . esc_url( translate( \BackWPup::get_plugin_data( 'pluginuri' ), 'backwpup' ) ) . '">' . __( 'Get pro.', 'mainwp-child' ) . '</a></td></tr>';
|
568 |
+
} else {
|
569 |
+
echo '<tr title=""><td>' . __( 'BackWPup Pro version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . '</td></tr>';
|
570 |
+
}
|
571 |
+
|
572 |
+
echo '<tr title=">=5.3.3"><td>' . __( 'PHP version', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_VERSION ) . '</td></tr>';
|
573 |
+
echo '<tr title=">=5.0.7"><td>' . __( 'MySQL version', 'mainwp-child' ) . '</td><td>' . esc_html( $wpdb->get_var( 'SELECT VERSION() AS version' ) ) . '</td></tr>';
|
574 |
+
if ( function_exists( 'curl_version' ) ) {
|
575 |
+
$curlversion = curl_version();
|
576 |
+
echo '<tr title=""><td>' . __( 'cURL version', 'mainwp-child' ) . '</td><td>' . esc_html( $curlversion['version'] ) . '</td></tr>';
|
577 |
+
echo '<tr title=""><td>' . __( 'cURL SSL version', 'mainwp-child' ) . '</td><td>' . esc_html( $curlversion['ssl_version'] ) . '</td></tr>';
|
578 |
+
} else {
|
579 |
+
echo '<tr title=""><td>' . __( 'cURL version', 'mainwp-child' ) . '</td><td>' . __( 'unavailable', 'mainwp-child' ) . '</td></tr>';
|
580 |
+
}
|
581 |
+
echo '<tr title=""><td>' . __( 'WP-Cron url:', 'mainwp-child' ) . '</td><td>' . esc_html( site_url( 'wp-cron.php' ) ) . '</td></tr>';
|
582 |
+
|
583 |
+
echo '<tr><td>' . __( 'Server self connect:', 'mainwp-child' ) . '</td><td>';
|
584 |
+
$raw_response = \BackWPup_Job::get_jobrun_url( 'test' );
|
585 |
+
$test_result = '';
|
586 |
+
if ( is_wp_error( $raw_response ) ) {
|
587 |
+
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), esc_html( $raw_response->get_error_message() ) );
|
588 |
+
} elseif ( 200 !== (int) wp_remote_retrieve_response_code( $raw_response ) && 204 !== (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
589 |
+
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), esc_html( wp_remote_retrieve_response_code( $raw_response ) ) );
|
590 |
+
}
|
591 |
+
$headers = wp_remote_retrieve_headers( $raw_response );
|
592 |
+
if ( isset( $headers['x-backwpup-ver'] ) && \BackWPup::get_plugin_data( 'version' ) !== $headers['x-backwpup-ver'] ) {
|
593 |
+
$test_result .= sprintf( __( 'The BackWPup HTTP response header returns a false value: "%s"', 'mainwp-child' ), esc_html( $headers['x-backwpup-ver'] ) );
|
594 |
+
}
|
595 |
+
|
596 |
+
if ( empty( $test_result ) ) {
|
597 |
+
esc_html_e( 'Response Test O.K.', 'mainwp-child' );
|
598 |
+
} else {
|
599 |
+
echo esc_html( $test_result );
|
600 |
+
}
|
601 |
+
echo '</td></tr>';
|
602 |
+
|
603 |
+
echo '<tr><td>' . __( 'Temp folder:', 'mainwp-child' ) . '</td><td>';
|
604 |
+
if ( ! is_dir( \BackWPup::get_plugin_data( 'TEMP' ) ) ) {
|
605 |
+
echo sprintf( __( 'Temp folder %s doesn\'t exist.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) );
|
606 |
+
} elseif ( ! is_writable( \BackWPup::get_plugin_data( 'TEMP' ) ) ) {
|
607 |
+
echo sprintf( __( 'Temporary folder %s is not writable.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) );
|
608 |
+
} else {
|
609 |
+
echo esc_html( \BackWPup::get_plugin_data( 'TEMP' ) );
|
610 |
+
}
|
611 |
+
echo '</td></tr>';
|
612 |
+
|
613 |
+
echo '<tr><td>' . __( 'Log folder:', 'mainwp-child' ) . '</td><td>';
|
614 |
+
|
615 |
+
$log_folder = \BackWPup_File::get_absolute_path( get_site_option( 'backwpup_cfg_logfolder' ) );
|
616 |
+
|
617 |
+
if ( ! is_dir( $log_folder ) ) {
|
618 |
+
echo sprintf( __( 'Logs folder %s not exist.', 'mainwp-child' ), esc_html( $log_folder ) );
|
619 |
+
} elseif ( ! is_writable( $log_folder ) ) {
|
620 |
+
echo sprintf( __( 'Log folder %s is not writable.', 'mainwp-child' ), esc_html( $log_folder ) );
|
621 |
+
} else {
|
622 |
+
echo esc_html( $log_folder );
|
623 |
+
}
|
624 |
+
echo '</td></tr>';
|
625 |
+
echo '<tr title=""><td>' . __( 'Server', 'mainwp-child' ) . '</td><td>' . ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : '' ) . '</td></tr>';
|
626 |
+
echo '<tr title=""><td>' . __( 'Operating System', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_OS ) . '</td></tr>';
|
627 |
+
echo '<tr title=""><td>' . __( 'PHP SAPI', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_SAPI ) . '</td></tr>';
|
628 |
+
echo '<tr title=""><td>' . __( 'Current PHP user', 'mainwp-child' ) . '</td><td>' . esc_html( get_current_user() ) . '</td></tr>';
|
629 |
+
$text = version_compare( phpversion(), '5.3.0' ) < 0 && (bool) ini_get( 'safe_mode' ) ? __( 'On', 'mainwp-child' ) : __( 'Off', 'mainwp-child' );
|
630 |
+
echo '<tr title=""><td>' . __( 'Safe Mode', 'mainwp-child' ) . '</td><td>' . $text . '</td></tr>';
|
631 |
+
echo '<tr title=">=30"><td>' . __( 'Maximum execution time', 'mainwp-child' ) . '</td><td>' . ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'mainwp-child' ) . '</td></tr>';
|
632 |
+
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
|
633 |
+
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __( 'Alternative WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'On', 'mainwp-child' ) . '</td></tr>';
|
634 |
+
} else {
|
635 |
+
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __( 'Alternative WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'Off', 'mainwp-child' ) . '</td></tr>';
|
636 |
+
}
|
637 |
+
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
638 |
+
echo '<tr title="DISABLE_WP_CRON"><td>' . __( 'Disabled WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'On', 'mainwp-child' ) . '</td></tr>';
|
639 |
+
} else {
|
640 |
+
echo '<tr title="DISABLE_WP_CRON"><td>' . __( 'Disabled WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'Off', 'mainwp-child' ) . '</td></tr>';
|
641 |
+
}
|
642 |
+
if ( defined( 'FS_CHMOD_DIR' ) ) {
|
643 |
+
echo '<tr title="FS_CHMOD_DIR"><td>' . __( 'CHMOD Dir', 'mainwp-child' ) . '</td><td>' . FS_CHMOD_DIR . '</td></tr>';
|
644 |
+
} else {
|
645 |
+
echo '<tr title="FS_CHMOD_DIR"><td>' . __( 'CHMOD Dir', 'mainwp-child' ) . '</td><td>0755</td></tr>';
|
646 |
+
}
|
647 |
+
|
648 |
+
$now = localtime( time(), true );
|
649 |
+
echo '<tr title=""><td>' . __( 'Server Time', 'mainwp-child' ) . '</td><td>' . esc_html( $now['tm_hour'] ) . ':' . esc_html( $now['tm_min'] ) . '</td></tr>';
|
650 |
+
echo '<tr title=""><td>' . __( 'Blog Time', 'mainwp-child' ) . '</td><td>' . esc_html( date_i18n( 'H:i' ) ) . '</td></tr>';
|
651 |
+
echo '<tr title=""><td>' . __( 'Blog Timezone', 'mainwp-child' ) . '</td><td>' . esc_html( get_option( 'timezone_string' ) ) . '</td></tr>';
|
652 |
+
echo '<tr title=""><td>' . __( 'Blog Time offset', 'mainwp-child' ) . '</td><td>' . sprintf( __( '%s hours', 'mainwp-child' ), esc_html( get_option( 'gmt_offset' ) ) ) . '</td></tr>';
|
653 |
+
echo '<tr title="WPLANG"><td>' . __( 'Blog language', 'mainwp-child' ) . '</td><td>' . esc_html( get_bloginfo( 'language' ) ) . '</td></tr>';
|
654 |
+
echo '<tr title="utf8"><td>' . __( 'MySQL Client encoding', 'mainwp-child' ) . '</td><td>';
|
655 |
+
echo defined( 'DB_CHARSET' ) ? esc_html( DB_CHARSET ) : '';
|
656 |
+
echo '</td></tr>';
|
657 |
+
echo '<tr title="URF-8"><td>' . __( 'Blog charset', 'mainwp-child' ) . '</td><td>' . esc_html( get_bloginfo( 'charset' ) ) . '</td></tr>';
|
658 |
+
echo '<tr title=">=128M"><td>' . __( 'PHP Memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>';
|
659 |
+
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
|
660 |
+
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
|
661 |
+
echo '<tr title=""><td>' . __( 'Memory in use', 'mainwp-child' ) . '</td><td>' . esc_html( size_format( memory_get_usage( true ), 2 ) ) . '</td></tr>';
|
662 |
+
|
663 |
+
$disabled = ini_get( 'disable_functions' );
|
664 |
+
if ( ! empty( $disabled ) ) {
|
665 |
+
$disabledarry = explode( ',', $disabled );
|
666 |
+
echo '<tr title=""><td>' . __( 'Disabled PHP Functions:', 'mainwp-child' ) . '</td><td>';
|
667 |
+
echo esc_html( implode( ', ', $disabledarry ) );
|
668 |
+
echo '</td></tr>';
|
669 |
+
}
|
670 |
+
|
671 |
+
echo '<tr title=""><td>' . __( 'Loaded PHP Extensions:', 'mainwp-child' ) . '</td><td>';
|
672 |
+
$extensions = get_loaded_extensions();
|
673 |
+
sort( $extensions );
|
674 |
+
echo esc_html( implode( ', ', $extensions ) );
|
675 |
+
echo '</td></tr>';
|
676 |
+
echo '</table>';
|
677 |
+
|
678 |
+
$output = ob_get_contents();
|
679 |
+
|
680 |
+
ob_end_clean();
|
681 |
+
|
682 |
+
return array(
|
683 |
+
'success' => 1,
|
684 |
+
'response' => $output,
|
685 |
+
);
|
686 |
+
}
|
687 |
+
|
688 |
+
/**
|
689 |
+
* Delete BackWPup Log.
|
690 |
+
*
|
691 |
+
* @uses \BackWPup_File::get_absolute_path()
|
692 |
+
*
|
693 |
+
* @return int[]|string[] On success return success[1] & error[] message on failure.
|
694 |
+
*/
|
695 |
+
protected function delete_log() {
|
696 |
+
if ( ! isset( $_POST['settings']['logfile'] ) || ! is_array( $_POST['settings']['logfile'] ) ) {
|
697 |
+
return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) );
|
698 |
+
}
|
699 |
+
|
700 |
+
$dir = get_site_option( 'backwpup_cfg_logfolder' );
|
701 |
+
$dir = \BackWPup_File::get_absolute_path( $dir );
|
702 |
+
|
703 |
+
foreach ( $_POST['settings']['logfile'] as $logfile ) {
|
704 |
+
$logfile = basename( $logfile );
|
705 |
+
|
706 |
+
if ( ! is_writeable( $dir ) ) {
|
707 |
+
return array( 'error' => __( 'Directory not writable:', 'mainwp-child' ) . $dir );
|
708 |
+
}
|
709 |
+
if ( ! is_file( $dir . $logfile ) ) {
|
710 |
+
return array( 'error' => __( 'Not file:', 'mainwp-child' ) . $dir . $logfile );
|
711 |
+
}
|
712 |
+
|
713 |
+
unlink( $dir . $logfile );
|
714 |
+
|
715 |
+
}
|
716 |
+
|
717 |
+
return array( 'success' => 1 );
|
718 |
+
}
|
719 |
+
|
720 |
+
/**
|
721 |
+
* Delete backup job.
|
722 |
+
*
|
723 |
+
* @uses \BackWPup_Option::delete_job()
|
724 |
+
*
|
725 |
+
* @return array|int[]|string[] On success return success[1] & error['message'] on failure.
|
726 |
+
*/
|
727 |
+
protected function delete_job() {
|
728 |
+
if ( ! isset( $_POST['job_id'] ) ) {
|
729 |
+
return array( 'error' => __( 'Missing job_id.', 'mainwp-child' ) );
|
730 |
+
}
|
731 |
+
|
732 |
+
$job_id = (int) $_POST['job_id'];
|
733 |
+
|
734 |
+
wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $job_id ) );
|
735 |
+
if ( ! \BackWPup_Option::delete_job( $job_id ) ) {
|
736 |
+
return array( 'error' => __( 'Cannot delete job', 'mainwp-child' ) );
|
737 |
+
}
|
738 |
+
|
739 |
+
return array( 'success' => 1 );
|
740 |
+
}
|
741 |
+
|
742 |
+
/**
|
743 |
+
* Delete backup.
|
744 |
+
*
|
745 |
+
* @uses \BackWPup::get_destination()
|
746 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
747 |
+
* @uses \BackWPup::get_destination::file_delete()
|
748 |
+
*
|
749 |
+
* @return array|int[]|string[] On success return success[1] response['DELETED'] & error['message'] on failure.
|
750 |
+
*/
|
751 |
+
protected function delete_backup() {
|
752 |
+
if ( ! isset( $_POST['settings']['backupfile'] ) ) {
|
753 |
+
return array( 'error' => __( 'Missing backupfile.', 'mainwp-child' ) );
|
754 |
+
}
|
755 |
+
|
756 |
+
if ( ! isset( $_POST['settings']['dest'] ) ) {
|
757 |
+
return array( 'error' => __( 'Missing dest.', 'mainwp-child' ) );
|
758 |
+
}
|
759 |
+
|
760 |
+
$backupfile = isset( $_POST['settings']['backupfile'] ) ? wp_unslash( $_POST['settings']['backupfile'] ) : '';
|
761 |
+
$dest = isset( $_POST['settings']['dest'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['dest'] ) ) : '';
|
762 |
+
|
763 |
+
list( $dest_id, $dest_name ) = explode( '_', $dest );
|
764 |
+
|
765 |
+
$dest_class = \BackWPup::get_destination( $dest_name );
|
766 |
+
|
767 |
+
if ( is_null( $dest_class ) ) {
|
768 |
+
return array( 'error' => __( 'Invalid dest class.', 'mainwp-child' ) );
|
769 |
+
}
|
770 |
+
|
771 |
+
$files = $dest_class->file_get_list( $dest );
|
772 |
+
|
773 |
+
foreach ( $files as $file ) {
|
774 |
+
if ( is_array( $file ) && $file['file'] == $backupfile ) {
|
775 |
+
$dest_class->file_delete( $dest, $backupfile );
|
776 |
+
|
777 |
+
return array(
|
778 |
+
'success' => 1,
|
779 |
+
'response' => 'DELETED',
|
780 |
+
);
|
781 |
+
}
|
782 |
+
}
|
783 |
+
|
784 |
+
return array(
|
785 |
+
'success' => 1,
|
786 |
+
'response' => 'Not found',
|
787 |
+
);
|
788 |
+
}
|
789 |
+
|
790 |
+
/**
|
791 |
+
* View BackWPup log.
|
792 |
+
*
|
793 |
+
* @return array|int[]|string[] On success return $output[] & error['message'] on failure.
|
794 |
+
*/
|
795 |
+
protected function view_log() {
|
796 |
+
if ( ! isset( $_POST['settings']['logfile'] ) ) {
|
797 |
+
return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) );
|
798 |
+
}
|
799 |
+
|
800 |
+
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
801 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
802 |
+
$log_file = $log_folder . basename( $_POST['settings']['logfile'] );
|
803 |
+
|
804 |
+
if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) {
|
805 |
+
$output = __( 'Log file doesn\'t exists', 'mainwp-child' );
|
806 |
+
} else {
|
807 |
+
if ( ! file_exists( $log_file ) && file_exists( $log_file . '.gz' ) ) {
|
808 |
+
$log_file = $log_file . '.gz';
|
809 |
+
}
|
810 |
+
|
811 |
+
if ( ! file_exists( $log_file ) && file_exists( $log_file . '.bz2' ) ) {
|
812 |
+
$log_file = $log_file . '.bz2';
|
813 |
+
}
|
814 |
+
|
815 |
+
if ( '.gz' == substr( $log_file, - 3 ) ) {
|
816 |
+
$output = file_get_contents( 'compress.zlib://' . $log_file, false );
|
817 |
+
} else {
|
818 |
+
$output = file_get_contents( $log_file, false );
|
819 |
+
}
|
820 |
+
}
|
821 |
+
|
822 |
+
return array(
|
823 |
+
'success' => 1,
|
824 |
+
'response' => $output,
|
825 |
+
);
|
826 |
+
}
|
827 |
+
|
828 |
+
/**
|
829 |
+
* Build Tables.
|
830 |
+
*
|
831 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
832 |
+
* @uses \BackWPup_File::get_absolute_path()
|
833 |
+
* @uses \BackWPup_Page_Logs()
|
834 |
+
* @uses \BackWPup_Page_Backups()
|
835 |
+
* @uses \BackWPup_Option::get_job_ids()
|
836 |
+
* @uses \BackWPup_Option::get()
|
837 |
+
* @uses \BackWPup::get_destination()
|
838 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
839 |
+
* @uses \BackWPup_Option::get()
|
840 |
+
*
|
841 |
+
* @return array Return table array or error['message'] on failure.
|
842 |
+
*/
|
843 |
+
protected function tables() {
|
844 |
+
if ( ! isset( $_POST['settings']['type'] ) ) {
|
845 |
+
return array( 'error' => __( 'Missing type.', 'mainwp-child' ) );
|
846 |
+
}
|
847 |
+
|
848 |
+
if ( ! isset( $_POST['settings']['website_id'] ) ) {
|
849 |
+
return array( 'error' => __( 'Missing website id.', 'mainwp-child' ) );
|
850 |
+
}
|
851 |
+
|
852 |
+
$type = isset( $_POST['settings']['type'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['type'] ) ) : '';
|
853 |
+
$website_id = isset( $_POST['settings']['website_id'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['website_id'] ) ) : '';
|
854 |
+
|
855 |
+
$this->wp_list_table_dependency();
|
856 |
+
|
857 |
+
$array = array();
|
858 |
+
|
859 |
+
switch ( $type ) {
|
860 |
+
case 'logs':
|
861 |
+
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
862 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
863 |
+
$log_folder = untrailingslashit( $log_folder );
|
864 |
+
|
865 |
+
if ( ! is_dir( $log_folder ) ) {
|
866 |
+
return array(
|
867 |
+
'success' => 1,
|
868 |
+
'response' => $array,
|
869 |
+
);
|
870 |
+
}
|
871 |
+
update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 );
|
872 |
+
$output = new \BackWPup_Page_Logs();
|
873 |
+
$output->prepare_items();
|
874 |
+
break;
|
875 |
+
|
876 |
+
case 'backups':
|
877 |
+
update_user_option( get_current_user_id(), 'backwpupbackups_per_page', 99999999 );
|
878 |
+
$output = new \BackWPup_Page_Backups();
|
879 |
+
$output->items = array();
|
880 |
+
|
881 |
+
$jobids = \BackWPup_Option::get_job_ids();
|
882 |
+
|
883 |
+
if ( ! empty( $jobids ) ) {
|
884 |
+
foreach ( $jobids as $jobid ) {
|
885 |
+
if ( \BackWPup_Option::get( $jobid, 'backuptype' ) == 'sync' ) {
|
886 |
+
continue;
|
887 |
+
}
|
888 |
+
|
889 |
+
$dests = \BackWPup_Option::get( $jobid, 'destinations' );
|
890 |
+
foreach ( $dests as $dest ) {
|
891 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
892 |
+
if ( is_null( $dest_class ) ) {
|
893 |
+
continue;
|
894 |
+
}
|
895 |
+
$items = $dest_class->file_get_list( $jobid . '_' . $dest );
|
896 |
+
if ( ! empty( $items ) ) {
|
897 |
+
foreach ( $items as $item ) {
|
898 |
+
$temp_single_item = $item;
|
899 |
+
$temp_single_item['dest'] = $jobid . '_' . $dest;
|
900 |
+
$temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) );
|
901 |
+
$output->items[] = $temp_single_item;
|
902 |
+
}
|
903 |
+
}
|
904 |
+
}
|
905 |
+
}
|
906 |
+
}
|
907 |
+
|
908 |
+
break;
|
909 |
+
|
910 |
+
case 'jobs':
|
911 |
+
$output = new \BackWPup_Page_Jobs();
|
912 |
+
$output->prepare_items();
|
913 |
+
break;
|
914 |
+
}
|
915 |
+
|
916 |
+
if ( is_array( $output->items ) ) {
|
917 |
+
if ( 'jobs' == $type ) {
|
918 |
+
foreach ( $output->items as $key => $val ) {
|
919 |
+
$temp_array = array();
|
920 |
+
$temp_array['id'] = $val;
|
921 |
+
$temp_array['name'] = \BackWPup_Option::get( $val, 'name' );
|
922 |
+
$temp_array['type'] = \BackWPup_Option::get( $val, 'type' );
|
923 |
+
$temp_array['destinations'] = \BackWPup_Option::get( $val, 'destinations' );
|
924 |
+
|
925 |
+
if ( $this->is_backwpup_pro ) {
|
926 |
+
$temp_array['export'] = str_replace( '&', '&', wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupjobs&action=export&jobs[]=' . $val, 'bulk-jobs' ) );
|
927 |
+
}
|
928 |
+
|
929 |
+
if ( \BackWPup_Option::get( $val, 'activetype' ) == 'wpcron' ) {
|
930 |
+
$nextrun = wp_next_scheduled( 'backwpup_cron', array( 'id' => $val ) );
|
931 |
+
if ( $nextrun + ( get_option( 'gmt_offset' ) * 3600 ) ) {
|
932 |
+
$temp_array['nextrun'] = sprintf( __( '%1$s at %2$s by WP-Cron', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $nextrun, true ), date_i18n( get_option( 'time_format' ), $nextrun, true ) );
|
933 |
+
} else {
|
934 |
+
$temp_array['nextrun'] = __( 'Not scheduled!', 'mainwp-child' );
|
935 |
+
}
|
936 |
+
} else {
|
937 |
+
$temp_array['nextrun'] = __( 'Inactive', 'mainwp-child' );
|
938 |
+
}
|
939 |
+
if ( \BackWPup_Option::get( $val, 'lastrun' ) ) {
|
940 |
+
$lastrun = \BackWPup_Option::get( $val, 'lastrun' );
|
941 |
+
$temp_array['lastrun'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $lastrun, true ), date_i18n( get_option( 'time_format' ), $lastrun, true ) );
|
942 |
+
if ( \BackWPup_Option::get( $val, 'lastruntime' ) ) {
|
943 |
+
$temp_array['lastrun'] .= ' ' . sprintf( __( 'Runtime: %d seconds', 'mainwp-child' ), \BackWPup_Option::get( $val, 'lastruntime' ) );
|
944 |
+
}
|
945 |
+
} else {
|
946 |
+
$temp_array['lastrun'] = __( 'not yet', 'mainwp-child' );
|
947 |
+
}
|
948 |
+
|
949 |
+
$temp_array['website_id'] = $website_id;
|
950 |
+
$array[] = $temp_array;
|
951 |
+
}
|
952 |
+
} elseif ( 'backups' == $type ) {
|
953 |
+
$without_dupes = array();
|
954 |
+
foreach ( $output->items as $key ) {
|
955 |
+
$temp_array = $key;
|
956 |
+
$temp_array['downloadurl'] = str_replace(
|
957 |
+
array(
|
958 |
+
'&',
|
959 |
+
network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=',
|
960 |
+
),
|
961 |
+
array(
|
962 |
+
'&',
|
963 |
+
admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=',
|
964 |
+
),
|
965 |
+
$temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' )
|
966 |
+
);
|
967 |
+
|
968 |
+
$temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups';
|
969 |
+
if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches ) ) {
|
970 |
+
if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
|
971 |
+
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
|
972 |
+
}
|
973 |
+
}
|
974 |
+
|
975 |
+
$temp_array['website_id'] = $website_id;
|
976 |
+
|
977 |
+
if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) {
|
978 |
+
$array[] = $temp_array;
|
979 |
+
$without_dupes[ $temp_array['file'] ] = 1;
|
980 |
+
}
|
981 |
+
}
|
982 |
+
} else {
|
983 |
+
foreach ( $output->items as $key => $val ) {
|
984 |
+
$array[] = $val;
|
985 |
+
}
|
986 |
+
}
|
987 |
+
}
|
988 |
+
|
989 |
+
return array(
|
990 |
+
'success' => 1,
|
991 |
+
'response' => $array,
|
992 |
+
);
|
993 |
+
}
|
994 |
+
|
995 |
+
/**
|
996 |
+
* Initiate download link.
|
997 |
+
*/
|
998 |
+
public function init_download_backup() {
|
999 |
+
if ( ! isset( $_GET['page'] ) || 'backwpupbackups' !== $_GET['page'] || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] ) ) {
|
1000 |
+
return;
|
1001 |
+
}
|
1002 |
+
?>
|
1003 |
+
<script type="text/javascript">
|
1004 |
+
document.addEventListener("DOMContentLoaded", function(event) {
|
1005 |
+
var downloadLink = document.querySelector( 'a.backup-download-link[data-jobid="<?php echo intval( $_GET['download_click_id'] ); ?>"' );
|
1006 |
+
if (typeof(downloadLink) !== 'undefined' && downloadLink !== null) {
|
1007 |
+
downloadLink.click();
|
1008 |
+
}
|
1009 |
+
});
|
1010 |
+
</script>
|
1011 |
+
<?php
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
/**
|
1015 |
+
* Download backup.
|
1016 |
+
*
|
1017 |
+
* @uses MainWP_Child_Back_WP_Up::verify_nonce_without_session()
|
1018 |
+
* @uses \BackWPup::get_destination()
|
1019 |
+
* @uses \BackWPup::get_destination::file_download()
|
1020 |
+
*/
|
1021 |
+
public function download_backup() {
|
1022 |
+
if ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) || ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
1023 |
+
die( '-1' );
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
if ( ! current_user_can( 'backwpup_backups_download' ) ) {
|
1027 |
+
die( '-2' );
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
if ( ! $this->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
1031 |
+
die( '-3' );
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
$dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) );
|
1035 |
+
if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) {
|
1036 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
1037 |
+
if ( is_null( $dest_class ) ) {
|
1038 |
+
die( '-4' );
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
$dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] );
|
1042 |
+
} else {
|
1043 |
+
die( '-5' );
|
1044 |
+
}
|
1045 |
+
|
1046 |
+
die();
|
1047 |
+
}
|
1048 |
+
|
1049 |
+
/**
|
1050 |
+
* Create security nounce without session.
|
1051 |
+
*
|
1052 |
+
* @param int $action Action performing.
|
1053 |
+
*
|
1054 |
+
* @return string|false Return nonce or FALSE on failure.
|
1055 |
+
*/
|
1056 |
+
protected function create_nonce_without_session( $action = - 1 ) {
|
1057 |
+
$user = wp_get_current_user();
|
1058 |
+
$uid = (int) $user->ID;
|
1059 |
+
if ( ! $uid ) {
|
1060 |
+
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
$i = wp_nonce_tick();
|
1064 |
+
|
1065 |
+
return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1066 |
+
}
|
1067 |
+
|
1068 |
+
/**
|
1069 |
+
* Verify nonce without session.
|
1070 |
+
*
|
1071 |
+
* @param string $nonce Nonce to verify.
|
1072 |
+
* @param int $action Action to perform.
|
1073 |
+
*
|
1074 |
+
* @return bool|int FALSE on failure. 1 or 2 on success.
|
1075 |
+
*/
|
1076 |
+
protected function verify_nonce_without_session($nonce, $action = - 1 ) {
|
1077 |
+
$nonce = (string) $nonce;
|
1078 |
+
$user = wp_get_current_user();
|
1079 |
+
$uid = (int) $user->ID;
|
1080 |
+
if ( ! $uid ) {
|
1081 |
+
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
1082 |
+
}
|
1083 |
+
|
1084 |
+
if ( empty( $nonce ) ) {
|
1085 |
+
return false;
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
$i = wp_nonce_tick();
|
1089 |
+
|
1090 |
+
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1091 |
+
if ( hash_equals( $expected, $nonce ) ) {
|
1092 |
+
return 1;
|
1093 |
+
}
|
1094 |
+
|
1095 |
+
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1096 |
+
if ( hash_equals( $expected, $nonce ) ) {
|
1097 |
+
return 2;
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
return false;
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
/**
|
1104 |
+
* BackWPup Ajax Working.
|
1105 |
+
*
|
1106 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1107 |
+
* @uses \BackWPup_Page_Jobs::ajax_working()
|
1108 |
+
*
|
1109 |
+
* @return array Return success array[ success, response ]
|
1110 |
+
*/
|
1111 |
+
protected function ajax_working() {
|
1112 |
+
|
1113 |
+
if ( ! isset( $_POST['settings'] ) || ! is_array( $_POST['settings'] ) || ! isset( $_POST['settings']['logfile'] ) || ! isset( $_POST['settings']['logpos'] ) ) {
|
1114 |
+
return array( 'error' => __( 'Missing logfile or logpos.', 'mainwp-child' ) );
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
$_GET['logfile'] = isset( $_POST['settings']['logfile'] ) ? wp_unslash( $_POST['settings']['logfile'] ) : '';
|
1118 |
+
$_GET['logpos'] = isset( $_POST['settings']['logpos'] ) ? wp_unslash( $_POST['settings']['logpos'] ) : '';
|
1119 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpupworking_ajax_nonce' );
|
1120 |
+
|
1121 |
+
$this->wp_list_table_dependency();
|
1122 |
+
|
1123 |
+
/**
|
1124 |
+
* MainWP BackWPup WP Die ajax handler.
|
1125 |
+
*
|
1126 |
+
* @param string $message Error message container.
|
1127 |
+
* @return string Error message.
|
1128 |
+
*/
|
1129 |
+
function mainwp_backwpup_wp_die_ajax_handler( $message ) {
|
1130 |
+
return 'mainwp_backwpup_wp_die_ajax_handler';
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
// We do this in order to not die when using wp_die.
|
1134 |
+
if ( ! defined( 'DOING_AJAX' ) ) {
|
1135 |
+
|
1136 |
+
/**
|
1137 |
+
* Checks whether ajax job is in progress.
|
1138 |
+
*
|
1139 |
+
* @const ( bool ) Default: true
|
1140 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Back_WP_Up.html
|
1141 |
+
*/
|
1142 |
+
define( 'DOING_AJAX', true );
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' );
|
1146 |
+
remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
|
1147 |
+
|
1148 |
+
ob_start();
|
1149 |
+
\BackWPup_Page_Jobs::ajax_working();
|
1150 |
+
|
1151 |
+
$output = ob_get_contents();
|
1152 |
+
|
1153 |
+
ob_end_clean();
|
1154 |
+
|
1155 |
+
return array(
|
1156 |
+
'success' => 1,
|
1157 |
+
'response' => $output,
|
1158 |
+
);
|
1159 |
+
}
|
1160 |
+
|
1161 |
+
/**
|
1162 |
+
* Backup now.
|
1163 |
+
*
|
1164 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1165 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1166 |
+
* @uses \BackWPup_Page_Jobs::load()
|
1167 |
+
* @uses \BackWPup_Job::get_working_data()
|
1168 |
+
*
|
1169 |
+
* @return array Response array[ success, response, logfile ] or array[ error ]
|
1170 |
+
*/
|
1171 |
+
protected function backup_now() {
|
1172 |
+
|
1173 |
+
if ( ! isset( $_POST['settings']['job_id'] ) ) {
|
1174 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
// Simulate http://wp/wp-admin/admin.php?jobid=1&page=backwpupjobs&action=runnow.
|
1178 |
+
$_GET['jobid'] = isset( $_POST['settings']['job_id'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['job_id'] ) ) : '';
|
1179 |
+
|
1180 |
+
$_REQUEST['action'] = 'runnow';
|
1181 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpup_job_run-runnowlink' );
|
1182 |
+
|
1183 |
+
update_site_option( 'backwpup_messages', array() );
|
1184 |
+
|
1185 |
+
$this->wp_list_table_dependency();
|
1186 |
+
|
1187 |
+
ob_start();
|
1188 |
+
\BackWPup_Page_Jobs::load();
|
1189 |
+
ob_end_clean();
|
1190 |
+
|
1191 |
+
$output = $this->check_backwpup_messages();
|
1192 |
+
|
1193 |
+
if ( isset( $output['error'] ) ) {
|
1194 |
+
return array( 'error' => '\BackWPup_Page_Jobs::load fail: ' . $output['error'] );
|
1195 |
+
} else {
|
1196 |
+
$job_object = \BackWPup_Job::get_working_data();
|
1197 |
+
if ( is_object( $job_object ) ) {
|
1198 |
+
return array(
|
1199 |
+
'success' => 1,
|
1200 |
+
'response' => $output['message'],
|
1201 |
+
'logfile' => basename( $job_object->logfile ),
|
1202 |
+
);
|
1203 |
+
} else {
|
1204 |
+
return array(
|
1205 |
+
'success' => 1,
|
1206 |
+
'response' => $output['message'],
|
1207 |
+
);
|
1208 |
+
}
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
/**
|
1213 |
+
* Abort backup.
|
1214 |
+
*
|
1215 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1216 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1217 |
+
* @uses \BackWPup_Page_Jobs::load()
|
1218 |
+
*
|
1219 |
+
* @return array|string[] Return array or error[message] on failure.
|
1220 |
+
*/
|
1221 |
+
protected function backup_abort() {
|
1222 |
+
$_REQUEST['action'] = 'abort';
|
1223 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'abort-job' );
|
1224 |
+
|
1225 |
+
update_site_option( 'backwpup_messages', array() );
|
1226 |
+
|
1227 |
+
$this->wp_list_table_dependency();
|
1228 |
+
|
1229 |
+
ob_start();
|
1230 |
+
\BackWPup_Page_Jobs::load();
|
1231 |
+
ob_end_clean();
|
1232 |
+
|
1233 |
+
$output = $this->check_backwpup_messages();
|
1234 |
+
|
1235 |
+
if ( isset( $output['error'] ) ) {
|
1236 |
+
return array( 'error' => 'Cannot abort: ' . $output['error'] );
|
1237 |
+
} else {
|
1238 |
+
return array(
|
1239 |
+
'success' => 1,
|
1240 |
+
'response' => $output['message'],
|
1241 |
+
);
|
1242 |
+
}
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
/**
|
1246 |
+
* WordPress list table dependency.
|
1247 |
+
*
|
1248 |
+
* @uses MainWP_Child_Back_WP_Up::MainWP_Fake_Wp_Screen()
|
1249 |
+
*/
|
1250 |
+
protected function wp_list_table_dependency() {
|
1251 |
+
mainwp_child_backwpup_wp_list_table_dependency();
|
1252 |
+
if ( ! class_exists( '\WP_List_Table' ) ) {
|
1253 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
1254 |
+
}
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
/**
|
1258 |
+
* Wizard system scan.
|
1259 |
+
*
|
1260 |
+
* @uses \BackWPup_Pro_Wizard_SystemTest()
|
1261 |
+
*
|
1262 |
+
* @return array|string[] Return array or error[message] on failure.
|
1263 |
+
*/
|
1264 |
+
protected function wizard_system_scan() {
|
1265 |
+
if ( class_exists( '\BackWPup_Pro_Wizard_SystemTest' ) ) {
|
1266 |
+
ob_start();
|
1267 |
+
|
1268 |
+
$system_test = new \BackWPup_Pro_Wizard_SystemTest();
|
1269 |
+
$system_test->execute( null );
|
1270 |
+
|
1271 |
+
$output = ob_get_contents();
|
1272 |
+
|
1273 |
+
ob_end_clean();
|
1274 |
+
|
1275 |
+
return array(
|
1276 |
+
'success' => 1,
|
1277 |
+
'response' => $output,
|
1278 |
+
);
|
1279 |
+
} else {
|
1280 |
+
return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' );
|
1281 |
+
}
|
1282 |
+
}
|
1283 |
+
|
1284 |
+
/**
|
1285 |
+
* Check destination email.
|
1286 |
+
*
|
1287 |
+
* @uses PHPMailer()
|
1288 |
+
* @uses \BackWPup::get_plugin_data()
|
1289 |
+
* @uses \Swift_SmtpTransport::newInstance()
|
1290 |
+
* @uses \Swift_SendmailTransport::newInstance()
|
1291 |
+
* @uses \Swift_MailTransport::newInstance()
|
1292 |
+
* @uses \Swift_Mailer::newInstance()
|
1293 |
+
* @uses \Swift_Message::newInstance()
|
1294 |
+
* @uses \Exception
|
1295 |
+
*
|
1296 |
+
* @return array|\Exception Return response array.
|
1297 |
+
*/
|
1298 |
+
protected function destination_email_check_email() {
|
1299 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1300 |
+
|
1301 |
+
$message = '';
|
1302 |
+
|
1303 |
+
$emailmethod = ( isset( $settings['emailmethod'] ) ? $settings['emailmethod'] : '' );
|
1304 |
+
$emailsendmail = ( isset( $settings['emailsendmail'] ) ? $settings['emailsendmail'] : '' );
|
1305 |
+
$emailhost = ( isset( $settings['emailhost'] ) ? $settings['emailhost'] : '' );
|
1306 |
+
$emailhostport = ( isset( $settings['emailhostport'] ) ? $settings['emailhostport'] : '' );
|
1307 |
+
$emailsecure = ( isset( $settings['emailsecure'] ) ? $settings['emailsecure'] : '' );
|
1308 |
+
$emailuser = ( isset( $settings['emailuser'] ) ? $settings['emailuser'] : '' );
|
1309 |
+
$emailpass = ( isset( $settings['emailpass'] ) ? $settings['emailpass'] : '' );
|
1310 |
+
|
1311 |
+
if ( ! isset( $settings['emailaddress'] ) || strlen( $settings['emailaddress'] ) < 2 ) {
|
1312 |
+
$message = __( 'Missing email address.', 'mainwp-child' );
|
1313 |
+
} else {
|
1314 |
+
if ( $emailmethod ) {
|
1315 |
+
|
1316 |
+
/**
|
1317 |
+
* PHP mailer instance.
|
1318 |
+
*
|
1319 |
+
* @global object
|
1320 |
+
*/
|
1321 |
+
global $phpmailer;
|
1322 |
+
|
1323 |
+
if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
|
1324 |
+
if ( file_exists( ABSPATH . WPINC . '/PHPMailer/PHPMailer.php' )) {
|
1325 |
+
require ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
|
1326 |
+
require ABSPATH . WPINC . '/PHPMailer/SMTP.php';
|
1327 |
+
require ABSPATH . WPINC . '/PHPMailer/Exception.php';
|
1328 |
+
$phpmailer = new \PHPMailer\PHPMailer\PHPMailer( true ); // phpcs:ignore -- to custom init PHP mailer
|
1329 |
+
} elseif ( file_exists( ABSPATH . WPINC . '/class-phpmailer.php' ) ) {
|
1330 |
+
require_once ABSPATH . WPINC . '/class-phpmailer.php';
|
1331 |
+
require_once ABSPATH . WPINC . '/class-smtp.php';
|
1332 |
+
$phpmailer = new \PHPMailer( true ); // phpcs:ignore -- to custom init PHP mailer
|
1333 |
+
}
|
1334 |
+
}
|
1335 |
+
if ( is_object( $phpmailer ) ) {
|
1336 |
+
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
|
1337 |
+
$emailmethod = $phpmailer->Mailer;
|
1338 |
+
$emailsendmail = $phpmailer->Sendmail;
|
1339 |
+
$emailhost = $phpmailer->Host;
|
1340 |
+
$emailhostport = $phpmailer->Port;
|
1341 |
+
$emailsecure = $phpmailer->SMTPSecure;
|
1342 |
+
$emailuser = $phpmailer->Username;
|
1343 |
+
$emailpass = $phpmailer->Password;
|
1344 |
+
}
|
1345 |
+
}
|
1346 |
+
|
1347 |
+
if ( ! class_exists( '\Swift', false ) ) {
|
1348 |
+
require \BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php';
|
1349 |
+
}
|
1350 |
+
|
1351 |
+
if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) {
|
1352 |
+
$mbEncoding = mb_internal_encoding();
|
1353 |
+
mb_internal_encoding( 'ASCII' );
|
1354 |
+
}
|
1355 |
+
|
1356 |
+
try {
|
1357 |
+
// Create the Transport.
|
1358 |
+
if ( 'smtp' == $emailmethod ) {
|
1359 |
+
$transport = \Swift_SmtpTransport::newInstance( $emailhost, $emailhostport );
|
1360 |
+
$transport->setUsername( $emailuser );
|
1361 |
+
$transport->setPassword( $emailpass );
|
1362 |
+
if ( 'ssl' == $emailsecure ) {
|
1363 |
+
$transport->setEncryption( 'ssl' );
|
1364 |
+
}
|
1365 |
+
if ( 'tls' == $emailsecure ) {
|
1366 |
+
$transport->setEncryption( 'tls' );
|
1367 |
+
}
|
1368 |
+
} elseif ( 'sendmail' == $emailmethod ) {
|
1369 |
+
$transport = \Swift_SendmailTransport::newInstance( $emailsendmail );
|
1370 |
+
} else {
|
1371 |
+
$transport = \Swift_MailTransport::newInstance();
|
1372 |
+
}
|
1373 |
+
$emailer = \Swift_Mailer::newInstance( $transport );
|
1374 |
+
|
1375 |
+
$message = \Swift_Message::newInstance( __( 'BackWPup archive sending TEST Message', 'mainwp-child' ) );
|
1376 |
+
$message->setFrom( array( ( isset( $settings['emailsndemail'] ) ? $settings['emailsndemail'] : 'from@example.com' ) => isset( $settings['emailsndemailname'] ) ? $settings['emailsndemailname'] : '' ) );
|
1377 |
+
$message->setTo( array( $settings['emailaddress'] ) );
|
1378 |
+
$message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) );
|
1379 |
+
|
1380 |
+
$result = $emailer->send( $message );
|
1381 |
+
} catch ( \Exception $e ) {
|
1382 |
+
$message = 'Swift Mailer: ' . $e->getMessage();
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
if ( isset( $mbEncoding ) ) {
|
1386 |
+
mb_internal_encoding( $mbEncoding );
|
1387 |
+
}
|
1388 |
+
|
1389 |
+
if ( ! isset( $result ) || ! $result ) {
|
1390 |
+
$message = __( 'Error while sending email!', 'mainwp-child' );
|
1391 |
+
} else {
|
1392 |
+
$message = __( 'Email sent.', 'mainwp-child' );
|
1393 |
+
}
|
1394 |
+
}
|
1395 |
+
|
1396 |
+
return array(
|
1397 |
+
'success' => 1,
|
1398 |
+
'message' => $message,
|
1399 |
+
);
|
1400 |
+
}
|
1401 |
+
|
1402 |
+
/**
|
1403 |
+
* Get job files.
|
1404 |
+
*
|
1405 |
+
* @uses BackWPup_File::get_upload_dir()
|
1406 |
+
* @uses BackWPup_File::get_folder_size()
|
1407 |
+
* @return array Response array containing folder locations and size.
|
1408 |
+
*/
|
1409 |
+
protected function get_job_files() {
|
1410 |
+
/**
|
1411 |
+
* Taken from BackWPup_JobType_File::get_exclude_dirs.
|
1412 |
+
*
|
1413 |
+
* @param array $folder Folders to exclude.
|
1414 |
+
* @return array Return folders list.
|
1415 |
+
*/
|
1416 |
+
function mainwp_backwpup_get_exclude_dirs( $folder ) {
|
1417 |
+
$folder = trailingslashit( str_replace( '\\', '/', realpath( $folder ) ) );
|
1418 |
+
$exclude_dir_array = array();
|
1419 |
+
|
1420 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ) != $folder ) {
|
1421 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) );
|
1422 |
+
}
|
1423 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ) != $folder ) {
|
1424 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) );
|
1425 |
+
}
|
1426 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ) != $folder ) {
|
1427 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) );
|
1428 |
+
}
|
1429 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ) != $folder ) {
|
1430 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) );
|
1431 |
+
}
|
1432 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ) != $folder ) {
|
1433 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) );
|
1434 |
+
}
|
1435 |
+
|
1436 |
+
return array_unique( $exclude_dir_array );
|
1437 |
+
}
|
1438 |
+
|
1439 |
+
$return = array();
|
1440 |
+
|
1441 |
+
$folders = array(
|
1442 |
+
'abs' => ABSPATH,
|
1443 |
+
'content' => WP_CONTENT_DIR,
|
1444 |
+
'plugin' => WP_PLUGIN_DIR,
|
1445 |
+
'theme' => get_theme_root(),
|
1446 |
+
'upload' => \BackWPup_File::get_upload_dir(),
|
1447 |
+
);
|
1448 |
+
|
1449 |
+
foreach ( $folders as $key => $folder ) {
|
1450 |
+
$return_temp = array();
|
1451 |
+
$main_folder_name = realpath( $folder );
|
1452 |
+
|
1453 |
+
if ( $main_folder_name ) {
|
1454 |
+
$main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) );
|
1455 |
+
$main_folder_size = '(' . size_format( \BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')';
|
1456 |
+
|
1457 |
+
$dir = opendir( $main_folder_name );
|
1458 |
+
if ( $dir ) {
|
1459 |
+
while ( false !== ( $file = readdir( $dir ) ) ) {
|
1460 |
+
if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) {
|
1461 |
+
$folder_size = ' (' . size_format( \BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')';
|
1462 |
+
$return_temp[] = array(
|
1463 |
+
'size' => $folder_size,
|
1464 |
+
'name' => $file,
|
1465 |
+
);
|
1466 |
+
|
1467 |
+
}
|
1468 |
+
}
|
1469 |
+
|
1470 |
+
closedir( $dir );
|
1471 |
+
}
|
1472 |
+
|
1473 |
+
$return[ $key ] = array(
|
1474 |
+
'size' => $main_folder_size,
|
1475 |
+
'name' => $folder,
|
1476 |
+
'folders' => $return_temp,
|
1477 |
+
);
|
1478 |
+
}
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
return array(
|
1482 |
+
'success' => 1,
|
1483 |
+
'folders' => $return,
|
1484 |
+
);
|
1485 |
+
}
|
1486 |
+
|
1487 |
+
/**
|
1488 |
+
* Get Child Site Tables.
|
1489 |
+
*
|
1490 |
+
* @uses BackWPup_Option::get()
|
1491 |
+
*
|
1492 |
+
* @return array Query response containing the tables.
|
1493 |
+
*/
|
1494 |
+
protected function get_child_tables() {
|
1495 |
+
|
1496 |
+
/** @global $wpdb wpdb */
|
1497 |
+
global $wpdb;
|
1498 |
+
|
1499 |
+
$return = array();
|
1500 |
+
|
1501 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1502 |
+
|
1503 |
+
if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) {
|
1504 |
+
$mysqli = new \mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) ); // phpcs:ignore -- third party code.
|
1505 |
+
|
1506 |
+
if ( $mysqli->connect_error ) {
|
1507 |
+
$return['message'] = $mysqli->connect_error;
|
1508 |
+
} else {
|
1509 |
+
if ( ! empty( $settings['dbname'] ) ) {
|
1510 |
+
$res = $mysqli->query( 'SHOW FULL TABLES FROM `' . $mysqli->real_escape_string( $settings['dbname'] ) . '`' );
|
1511 |
+
if ( $res ) {
|
1512 |
+
$tables_temp = array();
|
1513 |
+
while ( $table = $res->fetch_array( MYSQLI_NUM ) ) { // phpcs:ignore -- third party code.
|
1514 |
+
$tables_temp[] = $table[0];
|
1515 |
+
}
|
1516 |
+
|
1517 |
+
$res->close();
|
1518 |
+
$return['tables'] = $tables_temp;
|
1519 |
+
}
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
if ( empty( $settings['dbname'] ) || ! empty( $settings['first'] ) ) {
|
1523 |
+
$res = $mysqli->query( 'SHOW DATABASES' );
|
1524 |
+
if ( $res ) {
|
1525 |
+
$databases_temp = array();
|
1526 |
+
while ( $db = $res->fetch_array() ) {
|
1527 |
+
$databases_temp[] = $db['Database'];
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
$res->close();
|
1531 |
+
$return['databases'] = $databases_temp;
|
1532 |
+
}
|
1533 |
+
}
|
1534 |
+
}
|
1535 |
+
$mysqli->close();
|
1536 |
+
} else {
|
1537 |
+
$tables_temp = array();
|
1538 |
+
|
1539 |
+
$tables = $wpdb->get_results( 'SHOW FULL TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- safe query.
|
1540 |
+
foreach ( $tables as $table ) {
|
1541 |
+
$tables_temp[] = $table[0];
|
1542 |
+
}
|
1543 |
+
|
1544 |
+
$return['tables'] = $tables_temp;
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
if ( isset( $settings['job_id'] ) ) {
|
1548 |
+
$return['dbdumpexclude'] = \BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' );
|
1549 |
+
}
|
1550 |
+
return array(
|
1551 |
+
'success' => 1,
|
1552 |
+
'return' => $return,
|
1553 |
+
);
|
1554 |
+
}
|
1555 |
+
|
1556 |
+
/**
|
1557 |
+
* Insert or update global jobs.
|
1558 |
+
*
|
1559 |
+
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs()
|
1560 |
+
*
|
1561 |
+
* @return array Response array containing job_id, changes & message array.
|
1562 |
+
*/
|
1563 |
+
protected function insert_or_update_jobs_global() {
|
1564 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1565 |
+
|
1566 |
+
if ( ! is_array( $settings ) ) {
|
1567 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
if ( ! isset( $settings['job_id'] ) ) {
|
1571 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1572 |
+
}
|
1573 |
+
|
1574 |
+
if ( $settings['job_id'] > 0 ) {
|
1575 |
+
$new_job_id = intval( $settings['job_id'] );
|
1576 |
+
} else {
|
1577 |
+
$new_job_id = null;
|
1578 |
+
}
|
1579 |
+
|
1580 |
+
$changes_array = array();
|
1581 |
+
$message_array = array();
|
1582 |
+
|
1583 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1584 |
+
$temp_array = array();
|
1585 |
+
$temp_array['tab'] = $key;
|
1586 |
+
$temp_array['value'] = $val;
|
1587 |
+
if ( ! is_null( $new_job_id ) ) {
|
1588 |
+
$temp_array['job_id'] = $new_job_id;
|
1589 |
+
} else {
|
1590 |
+
$temp_array['job_id'] = $settings['job_id'];
|
1591 |
+
}
|
1592 |
+
|
1593 |
+
$_POST['settings'] = $temp_array;
|
1594 |
+
$return = $this->insert_or_update_jobs();
|
1595 |
+
|
1596 |
+
if ( is_null( $new_job_id ) ) {
|
1597 |
+
if ( ! isset( $return['job_id'] ) ) {
|
1598 |
+
return array( 'error' => __( 'Missing new job_id', 'mainwp-child' ) );
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
$new_job_id = $return['job_id'];
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
// We want to exit gracefully.
|
1605 |
+
if ( isset( $return['error_message'] ) ) {
|
1606 |
+
$message_array[ $return['error_message'] ] = 1;
|
1607 |
+
}
|
1608 |
+
|
1609 |
+
if ( isset( $return['changes'] ) ) {
|
1610 |
+
$changes_array = array_merge( $changes_array, $return['changes'] );
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
if ( isset( $return['message'] ) ) {
|
1614 |
+
foreach ( $return['message'] as $message ) {
|
1615 |
+
if ( ! isset( $message_array[ $message ] ) ) {
|
1616 |
+
$message_array[ $message ] = 1;
|
1617 |
+
}
|
1618 |
+
}
|
1619 |
+
}
|
1620 |
+
}
|
1621 |
+
|
1622 |
+
return array(
|
1623 |
+
'success' => 1,
|
1624 |
+
'job_id' => $new_job_id,
|
1625 |
+
'changes' => $changes_array,
|
1626 |
+
'message' => array_keys( $message_array ),
|
1627 |
+
);
|
1628 |
+
}
|
1629 |
+
|
1630 |
+
/**
|
1631 |
+
* Edit form post save.
|
1632 |
+
*
|
1633 |
+
* Parses & saves files, folders, boolean fields excluding any unwanted files or directories.
|
1634 |
+
* [Taken from BackWPup_JobType_File::edit_form_post_save with some tweaks].
|
1635 |
+
*
|
1636 |
+
* @uses BackWPup_Option::update()
|
1637 |
+
*
|
1638 |
+
* @param $post_data Post data to save.
|
1639 |
+
* @param $id Post ID.
|
1640 |
+
*/
|
1641 |
+
public function edit_form_post_save($post_data, $id ) {
|
1642 |
+
// Parse and save files to exclude.
|
1643 |
+
$exclude_input = $post_data['fileexclude'];
|
1644 |
+
$to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array();
|
1645 |
+
if ( $to_exclude_list ) {
|
1646 |
+
$to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) );
|
1647 |
+
}
|
1648 |
+
$to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array();
|
1649 |
+
$to_exclude_parsed = array();
|
1650 |
+
foreach ( $to_exclude as $key => $value ) {
|
1651 |
+
$normalized = wp_normalize_path( trim( $value ) );
|
1652 |
+
if ( $normalized ) {
|
1653 |
+
$to_exclude_parsed[ $key ] = $normalized;
|
1654 |
+
}
|
1655 |
+
}
|
1656 |
+
sort( $to_exclude_parsed );
|
1657 |
+
\BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) );
|
1658 |
+
unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized );
|
1659 |
+
|
1660 |
+
// Parse and save folders to include.
|
1661 |
+
$include_input = $post_data['dirinclude'];
|
1662 |
+
$include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array();
|
1663 |
+
$to_include = $include_list ? explode( ',', $include_list ) : array();
|
1664 |
+
$to_include_parsed = array();
|
1665 |
+
foreach ( $to_include as $key => $value ) {
|
1666 |
+
$normalized = trailingslashit( wp_normalize_path( trim( $value ) ) );
|
1667 |
+
if ( $normalized ) {
|
1668 |
+
$normalized = filter_var( $normalized, FILTER_SANITIZE_URL );
|
1669 |
+
}
|
1670 |
+
$realpath = $normalized && '/' !== $normalized ? realpath( $normalized ) : false;
|
1671 |
+
if ( $realpath ) {
|
1672 |
+
$to_include_parsed[ $key ] = $realpath;
|
1673 |
+
}
|
1674 |
+
}
|
1675 |
+
sort( $to_include_parsed );
|
1676 |
+
\BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) );
|
1677 |
+
unset( $include_input, $include_list, $to_include, $to_include_parsed, $normalized, $realpath );
|
1678 |
+
|
1679 |
+
// Parse and save boolean fields.
|
1680 |
+
$boolean_fields_def = array(
|
1681 |
+
'backupexcludethumbs' => FILTER_VALIDATE_BOOLEAN,
|
1682 |
+
'backupspecialfiles' => FILTER_VALIDATE_BOOLEAN,
|
1683 |
+
'backuproot' => FILTER_VALIDATE_BOOLEAN,
|
1684 |
+
'backupabsfolderup' => FILTER_VALIDATE_BOOLEAN,
|
1685 |
+
'backupcontent' => FILTER_VALIDATE_BOOLEAN,
|
1686 |
+
'backupplugins' => FILTER_VALIDATE_BOOLEAN,
|
1687 |
+
'backupthemes' => FILTER_VALIDATE_BOOLEAN,
|
1688 |
+
'backupuploads' => FILTER_VALIDATE_BOOLEAN,
|
1689 |
+
);
|
1690 |
+
|
1691 |
+
foreach ( $boolean_fields_def as $key => $value ) {
|
1692 |
+
\BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) );
|
1693 |
+
}
|
1694 |
+
// Parse and save directories to exclude.
|
1695 |
+
$exclude_dirs_def = array(
|
1696 |
+
'backuprootexcludedirs' => array(
|
1697 |
+
'filter' => FILTER_SANITIZE_URL,
|
1698 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1699 |
+
),
|
1700 |
+
'backuppluginsexcludedirs' => array(
|
1701 |
+
'filter' => FILTER_SANITIZE_URL,
|
1702 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1703 |
+
),
|
1704 |
+
'backupcontentexcludedirs' => array(
|
1705 |
+
'filter' => FILTER_SANITIZE_URL,
|
1706 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1707 |
+
),
|
1708 |
+
'backupthemesexcludedirs' => array(
|
1709 |
+
'filter' => FILTER_SANITIZE_URL,
|
1710 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1711 |
+
),
|
1712 |
+
'backupuploadsexcludedirs' => array(
|
1713 |
+
'filter' => FILTER_SANITIZE_URL,
|
1714 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1715 |
+
),
|
1716 |
+
);
|
1717 |
+
foreach ( $exclude_dirs_def as $key => $filter ) {
|
1718 |
+
$value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array();
|
1719 |
+
\BackWPup_Option::update( $id, $key, $value );
|
1720 |
+
}
|
1721 |
+
}
|
1722 |
+
|
1723 |
+
/**
|
1724 |
+
* Insert or update jobs.
|
1725 |
+
*
|
1726 |
+
* @uses BackWPup_Option::get_job_ids()
|
1727 |
+
* @uses BackWPup_Option::get()
|
1728 |
+
* @uses BackWPup_Option::update()
|
1729 |
+
* @uses BackWPup_Admin::get_messages()
|
1730 |
+
* @uses BackWPup_Admin::message()
|
1731 |
+
* @uses BackWPup_Job::get_jobrun_url()
|
1732 |
+
* @uses BackWPup_Page_Editjob::save_post_form()
|
1733 |
+
* @uses MainWP_Child_Back_WP_Up::edit_form_post_save()
|
1734 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1735 |
+
*
|
1736 |
+
* @return array Response array containing job_id, changes & message array.
|
1737 |
+
*/
|
1738 |
+
protected function insert_or_update_jobs() {
|
1739 |
+
|
1740 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1741 |
+
|
1742 |
+
if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) {
|
1743 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1744 |
+
}
|
1745 |
+
|
1746 |
+
if ( ! isset( $settings['tab'] ) ) {
|
1747 |
+
return array( 'error' => __( 'Missing tab', 'mainwp-child' ) );
|
1748 |
+
}
|
1749 |
+
|
1750 |
+
if ( ! isset( $settings['job_id'] ) ) {
|
1751 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1752 |
+
}
|
1753 |
+
|
1754 |
+
if ( ! class_exists( '\BackWPup' ) ) {
|
1755 |
+
return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) );
|
1756 |
+
}
|
1757 |
+
|
1758 |
+
if ( $settings['job_id'] > 0 ) {
|
1759 |
+
$job_id = intval( $settings['job_id'] );
|
1760 |
+
} else {
|
1761 |
+
// generate jobid if not exists.
|
1762 |
+
$newjobid = \BackWPup_Option::get_job_ids();
|
1763 |
+
sort( $newjobid );
|
1764 |
+
$job_id = end( $newjobid ) + 1;
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
update_site_option( 'backwpup_messages', array() );
|
1768 |
+
|
1769 |
+
if ( isset( $settings['value']['backupdir'] ) && empty( $settings['value']['backupdir'] ) ) {
|
1770 |
+
$backupdir = \BackWPup_Option::get( (int) $job_id, 'backupdir' );
|
1771 |
+
if ( ! empty( $backupdir ) ) {
|
1772 |
+
$settings['value']['backupdir'] = $backupdir;
|
1773 |
+
}
|
1774 |
+
}
|
1775 |
+
|
1776 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1777 |
+
$_POST[ $key ] = $val;
|
1778 |
+
}
|
1779 |
+
|
1780 |
+
if ( 'jobtype-FILE' == $settings['tab'] ) {
|
1781 |
+
$this->edit_form_post_save( $settings['value'], $job_id );
|
1782 |
+
$messages = \BackWPup_Admin::get_messages();
|
1783 |
+
if ( empty( $messages['error'] ) ) {
|
1784 |
+
$url = \BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id );
|
1785 |
+
\BackWPup_Admin::message( sprintf( __( 'Changes for job <i>%s</i> saved.', 'mainwp-child' ), \BackWPup_Option::get( $job_id, 'name' ) ) . ' <a href="' . network_admin_url( 'admin.php' ) . '?page=backwpupjobs">' . __( 'Jobs overview', 'mainwp-child' ) . '</a> | <a href="' . $url['url'] . '">' . __( 'Run now', 'mainwp-child' ) . '</a>' );
|
1786 |
+
}
|
1787 |
+
} elseif ( 'dest-DROPBOX' == $settings['tab'] ) {
|
1788 |
+
unset( $settings['value'] );
|
1789 |
+
\BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
|
1790 |
+
} else {
|
1791 |
+
\BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
|
1792 |
+
}
|
1793 |
+
|
1794 |
+
$return = $this->check_backwpup_messages();
|
1795 |
+
|
1796 |
+
if ( isset( $return['error'] ) ) {
|
1797 |
+
return array(
|
1798 |
+
'success' => 1,
|
1799 |
+
'error_message' => __( 'Cannot save jobs: ' . $return['error'], 'mainwp-child' ),
|
1800 |
+
);
|
1801 |
+
}
|
1802 |
+
|
1803 |
+
if ( isset( $settings['value']['sugarrefreshtoken'] ) ) {
|
1804 |
+
\BackWPup_Option::update( $job_id, 'sugarrefreshtoken', $settings['value']['sugarrefreshtoken'] );
|
1805 |
+
}
|
1806 |
+
|
1807 |
+
if ( isset( $settings['value']['gdriverefreshtoken'] ) ) {
|
1808 |
+
\BackWPup_Option::update( $job_id, 'gdriverefreshtoken', $settings['value']['gdriverefreshtoken'] );
|
1809 |
+
}
|
1810 |
+
|
1811 |
+
if ( isset( $settings['value']['dbdumpspecialsetalltables'] ) && $settings['value']['dbdumpspecialsetalltables'] ) {
|
1812 |
+
\BackWPup_Option::update( $job_id, 'dbdumpexclude', array() );
|
1813 |
+
}
|
1814 |
+
|
1815 |
+
if ( isset( $settings['value']['dropboxtoken'] ) && isset( $settings['value']['dropboxroot'] ) ) {
|
1816 |
+
\BackWPup_Option::update( $job_id, 'dropboxtoken', $settings['value']['dropboxtoken'] );
|
1817 |
+
\BackWPup_Option::update( $job_id, 'dropboxroot', $settings['value']['dropboxroot'] );
|
1818 |
+
}
|
1819 |
+
|
1820 |
+
$changes_array = array();
|
1821 |
+
|
1822 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1823 |
+
$temp_value = \BackWPup_Option::get( $job_id, $key );
|
1824 |
+
if ( is_string( $temp_value ) ) {
|
1825 |
+
if ( isset( $this->exclusions[ $settings['tab'] ] ) ) {
|
1826 |
+
if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) {
|
1827 |
+
$changes_array[ $key ] = $temp_value;
|
1828 |
+
}
|
1829 |
+
} elseif ( strcmp( $temp_value, $val ) != 0 ) {
|
1830 |
+
$changes_array[ $key ] = $temp_value;
|
1831 |
+
}
|
1832 |
+
}
|
1833 |
+
}
|
1834 |
+
|
1835 |
+
return array(
|
1836 |
+
'success' => 1,
|
1837 |
+
'job_id' => $job_id,
|
1838 |
+
'changes' => $changes_array,
|
1839 |
+
'message' => $return['message'],
|
1840 |
+
);
|
1841 |
+
}
|
1842 |
+
|
1843 |
+
|
1844 |
+
/**
|
1845 |
+
* Update settings.
|
1846 |
+
*
|
1847 |
+
* @uses BackWPup_Page_Settings()
|
1848 |
+
* @uses BackWPup_Page_Settings::save_post_form()
|
1849 |
+
* @uses BackWPup_Pro_Settings_APIKeys::get_instance()
|
1850 |
+
* @uses BackWPup_Pro_Settings_APIKeys::save_form()
|
1851 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1852 |
+
*
|
1853 |
+
* @return array Response array success, changes, message[].
|
1854 |
+
*/
|
1855 |
+
protected function update_settings() {
|
1856 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1857 |
+
|
1858 |
+
if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) {
|
1859 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1860 |
+
}
|
1861 |
+
|
1862 |
+
if ( ! class_exists( '\BackWPup' ) ) {
|
1863 |
+
return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) );
|
1864 |
+
}
|
1865 |
+
|
1866 |
+
if ( isset( $settings['value']['is_premium'] ) && 1 == $settings['value']['is_premium'] && false == $this->is_backwpup_pro ) {
|
1867 |
+
return array( 'error' => __( 'You try to use pro version settings in non pro plugin version. Please install pro version on child and try again.', 'mainwp-child' ) );
|
1868 |
+
}
|
1869 |
+
|
1870 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1871 |
+
$_POST[ $key ] = $val;
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
update_site_option( 'backwpup_messages', array() );
|
1875 |
+
|
1876 |
+
$settings_views = array();
|
1877 |
+
$settings_updaters = array();
|
1878 |
+
|
1879 |
+
$backwpup = new \BackWPup_Page_Settings( $settings_views, $settings_updaters );
|
1880 |
+
$backwpup->save_post_form();
|
1881 |
+
|
1882 |
+
if ( class_exists( '\BackWPup_Pro' ) ) {
|
1883 |
+
$pro_settings = \BackWPup_Pro_Settings_APIKeys::get_instance();
|
1884 |
+
$pro_settings->save_form();
|
1885 |
+
|
1886 |
+
}
|
1887 |
+
$return = $this->check_backwpup_messages();
|
1888 |
+
|
1889 |
+
if ( isset( $return['error'] ) ) {
|
1890 |
+
return array( 'error' => __( 'Cannot save settings: ' . $return['error'], 'mainwp-child' ) );
|
1891 |
+
}
|
1892 |
+
|
1893 |
+
$exclusions = array(
|
1894 |
+
'is_premium',
|
1895 |
+
'dropboxappsecret',
|
1896 |
+
'dropboxsandboxappsecret',
|
1897 |
+
'sugarsyncsecret',
|
1898 |
+
'googleclientsecret',
|
1899 |
+
'override',
|
1900 |
+
'httpauthpassword',
|
1901 |
+
);
|
1902 |
+
|
1903 |
+
$changes_array = array();
|
1904 |
+
|
1905 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1906 |
+
|
1907 |
+
$temp_value = get_site_option( 'backwpup_cfg_' . $key, '' );
|
1908 |
+
if ( ! in_array( $key, $exclusions ) && strcmp( $temp_value, $val ) != 0 ) {
|
1909 |
+
$changes_array[ $key ] = $temp_value;
|
1910 |
+
}
|
1911 |
+
}
|
1912 |
+
|
1913 |
+
return array(
|
1914 |
+
'success' => 1,
|
1915 |
+
'changes' => $changes_array,
|
1916 |
+
'message' => $return['message'],
|
1917 |
+
);
|
1918 |
+
}
|
1919 |
+
|
1920 |
+
/**
|
1921 |
+
* Check BackWPup Message.
|
1922 |
+
*
|
1923 |
+
* @return array|string[] Returns an empty array or Error[], Message[].
|
1924 |
+
*/
|
1925 |
+
protected function check_backwpup_messages() {
|
1926 |
+
$message = get_site_option( 'backwpup_messages', array() );
|
1927 |
+
update_site_option( 'backwpup_messages', array() );
|
1928 |
+
|
1929 |
+
if ( isset( $message['error'] ) ) {
|
1930 |
+
return array( 'error' => implode( ', ', $message['error'] ) );
|
1931 |
+
} elseif ( isset( $message['updated'] ) ) {
|
1932 |
+
return array( 'message' => $message['updated'] );
|
1933 |
+
} else {
|
1934 |
+
return array( 'error' => 'Generic error' );
|
1935 |
+
}
|
1936 |
+
}
|
1937 |
+
}
|
1938 |
+
|
1939 |
+
// phpcs:disable Generic.Files.OneObjectStructurePerFile -- fake class
|
1940 |
+
if ( ! class_exists( '\MainWP\Child\MainWP_Fake_Wp_Screen' ) ) {
|
1941 |
+
/**
|
1942 |
+
* Class MainWP_Fake_Wp_Screen
|
1943 |
+
*
|
1944 |
+
* @used-by MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1945 |
+
*/
|
1946 |
+
class MainWP_Fake_Wp_Screen {
|
1947 |
+
/** @var string Action. */
|
1948 |
+
public $action;
|
1949 |
+
/** @var string Base url. */
|
1950 |
+
public $base;
|
1951 |
+
/** @var int ID*/
|
1952 |
+
public $id;
|
1953 |
+
}
|
1954 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class/class-mainwp-child-branding-render.php
CHANGED
@@ -1,376 +1,380 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Render Branding
|
4 |
-
*
|
5 |
-
* This file handles rendering the Child Branding settings.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Branding_Render
|
14 |
-
*
|
15 |
-
* @package MainWP\Child
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Branding_Render {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of the class.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
public static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Method instance()
|
28 |
-
*
|
29 |
-
* Create a public static instance.
|
30 |
-
*
|
31 |
-
* @return mixed Class instance.
|
32 |
-
*/
|
33 |
-
public static function instance() {
|
34 |
-
if ( null === self::$instance ) {
|
35 |
-
self::$instance = new self();
|
36 |
-
}
|
37 |
-
return self::$instance;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Get Class Name.
|
42 |
-
*
|
43 |
-
* @return string
|
44 |
-
*/
|
45 |
-
public static function get_class_name() {
|
46 |
-
return __CLASS__;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* MainWP_Child_Branding_Render constructor.
|
51 |
-
*
|
52 |
-
* Run any time the class is called.
|
53 |
-
*/
|
54 |
-
public function __construct() {
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Method admin_head_hide_elements().
|
59 |
-
*/
|
60 |
-
public function admin_head_hide_elements() {
|
61 |
-
?>
|
62 |
-
<script type="text/javascript">
|
63 |
-
document.addEventListener( "DOMContentLoaded", function( event ) {
|
64 |
-
document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
|
65 |
-
document.getElementById( "menu-plugins" ).outerHTML = '';
|
66 |
-
var els_core = document.querySelectorAll( "a[href='update-core.php']" );
|
67 |
-
for ( var i = 0, l = els_core.length; i < l; i++ ) {
|
68 |
-
var el = els_core[i];
|
69 |
-
el.parentElement.innerHTML = '';
|
70 |
-
}
|
71 |
-
} );
|
72 |
-
</script>
|
73 |
-
<?php
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Render Contact Support.
|
78 |
-
*
|
79 |
-
* @return string Contact Support form html.
|
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 |
-
$back_link =
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
$send_email_message =
|
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 |
-
$mail .=
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
if (
|
254 |
-
|
255 |
-
}
|
256 |
-
|
257 |
-
if (
|
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 |
-
itemCount
|
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 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Render Branding
|
4 |
+
*
|
5 |
+
* This file handles rendering the Child Branding settings.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Branding_Render
|
14 |
+
*
|
15 |
+
* @package MainWP\Child
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Branding_Render {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
public static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Method instance()
|
28 |
+
*
|
29 |
+
* Create a public static instance.
|
30 |
+
*
|
31 |
+
* @return mixed Class instance.
|
32 |
+
*/
|
33 |
+
public static function instance() {
|
34 |
+
if ( null === self::$instance ) {
|
35 |
+
self::$instance = new self();
|
36 |
+
}
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Get Class Name.
|
42 |
+
*
|
43 |
+
* @return string
|
44 |
+
*/
|
45 |
+
public static function get_class_name() {
|
46 |
+
return __CLASS__;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* MainWP_Child_Branding_Render constructor.
|
51 |
+
*
|
52 |
+
* Run any time the class is called.
|
53 |
+
*/
|
54 |
+
public function __construct() {
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Method admin_head_hide_elements().
|
59 |
+
*/
|
60 |
+
public function admin_head_hide_elements() {
|
61 |
+
?>
|
62 |
+
<script type="text/javascript">
|
63 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
64 |
+
document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
|
65 |
+
document.getElementById( "menu-plugins" ).outerHTML = '';
|
66 |
+
var els_core = document.querySelectorAll( "a[href='update-core.php']" );
|
67 |
+
for ( var i = 0, l = els_core.length; i < l; i++ ) {
|
68 |
+
var el = els_core[i];
|
69 |
+
el.parentElement.innerHTML = '';
|
70 |
+
}
|
71 |
+
} );
|
72 |
+
</script>
|
73 |
+
<?php
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Render Contact Support.
|
78 |
+
*
|
79 |
+
* @return string Contact Support form html.
|
80 |
+
*
|
81 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::$child_branding_options
|
82 |
+
*/
|
83 |
+
public function contact_support() {
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Current user global.
|
87 |
+
*
|
88 |
+
* @global string
|
89 |
+
*/
|
90 |
+
global $current_user;
|
91 |
+
|
92 |
+
?>
|
93 |
+
<style>
|
94 |
+
.mainwp_info-box-yellow {
|
95 |
+
margin: 5px 0 15px;
|
96 |
+
padding: .6em;
|
97 |
+
background: #ffffe0;
|
98 |
+
border: 1px solid #e6db55;
|
99 |
+
border-radius: 3px;
|
100 |
+
-moz-border-radius: 3px;
|
101 |
+
-webkit-border-radius: 3px;
|
102 |
+
clear: both;
|
103 |
+
}
|
104 |
+
</style>
|
105 |
+
<?php
|
106 |
+
$opts = MainWP_Child_Branding::instance()->child_branding_options;
|
107 |
+
|
108 |
+
if ( isset( $_POST['submit'] ) ) {
|
109 |
+
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), '_contactNonce' ) ) {
|
110 |
+
return false;
|
111 |
+
}
|
112 |
+
$this->render_submit_message( $opts );
|
113 |
+
return;
|
114 |
+
}
|
115 |
+
|
116 |
+
$from_page = '';
|
117 |
+
if ( isset( $_GET['from_page'] ) ) {
|
118 |
+
$from_page = isset( $_GET['from_page'] ) ? rawurldecode( wp_unslash( $_GET['from_page'] ) ) : '';
|
119 |
+
} else {
|
120 |
+
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
121 |
+
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
122 |
+
$from_page = rawurldecode( $fullurl );
|
123 |
+
}
|
124 |
+
|
125 |
+
$support_message = $opts['support_message'];
|
126 |
+
$support_message = nl2br( stripslashes( $support_message ) );
|
127 |
+
$from_email = $current_user ? $current_user->user_email : '';
|
128 |
+
?>
|
129 |
+
<form action="" method="post">
|
130 |
+
<div style="width: 99%;">
|
131 |
+
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
|
132 |
+
<div style="height: auto; margin-bottom: 10px; text-align: left">
|
133 |
+
<p><?php echo wp_kses_post( $support_message ); ?></p>
|
134 |
+
<p>
|
135 |
+
<label for="mainwp_branding_contact_message_subject"><?php esc_html_e( 'Subject:', 'mainwp-child' ); ?></label>
|
136 |
+
<br>
|
137 |
+
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;">
|
138 |
+
</p>
|
139 |
+
<p>
|
140 |
+
<label for="mainwp_branding_contact_send_from"><?php esc_html_e( 'From:', 'mainwp-child' ); ?></label>
|
141 |
+
<br>
|
142 |
+
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_attr( $from_email ); ?>">
|
143 |
+
</p>
|
144 |
+
<div style="max-width: 650px;">
|
145 |
+
<label for="mainwp_branding_contact_message_content"><?php esc_html_e( 'Your message:', 'mainwp-child' ); ?></label>
|
146 |
+
<br>
|
147 |
+
<?php
|
148 |
+
remove_editor_styles(); // stop custom theme styling interfering with the editor.
|
149 |
+
wp_editor(
|
150 |
+
'',
|
151 |
+
'mainwp_branding_contact_message_content',
|
152 |
+
array(
|
153 |
+
'textarea_name' => 'mainwp_branding_contact_message_content',
|
154 |
+
'textarea_rows' => 10,
|
155 |
+
'teeny' => true,
|
156 |
+
'wpautop' => true,
|
157 |
+
'media_buttons' => false,
|
158 |
+
)
|
159 |
+
);
|
160 |
+
?>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
+
<br/>
|
164 |
+
<?php
|
165 |
+
$button_title = $opts['submit_button_title'];
|
166 |
+
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit', 'mainwp-child' );
|
167 |
+
?>
|
168 |
+
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit" value="<?php echo esc_attr( $button_title ); ?>" class="button-primary button" style="float: left"/>
|
169 |
+
</div>
|
170 |
+
<input type="hidden" name="mainwp_branding_send_from_page" value="<?php echo esc_url( $from_page ); ?>"/>
|
171 |
+
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
|
172 |
+
</form>
|
173 |
+
<?php
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Render contact support submit message.
|
178 |
+
*
|
179 |
+
* @param array $opts An array containg message options.
|
180 |
+
*/
|
181 |
+
private function render_submit_message( $opts ) {
|
182 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
183 |
+
$back_link = $opts['message_return_sender'];
|
184 |
+
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
|
185 |
+
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
|
186 |
+
|
187 |
+
if ( $this->send_support_mail() ) {
|
188 |
+
$send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
|
189 |
+
if ( ! empty( $send_email_message ) ) {
|
190 |
+
$send_email_message = stripslashes( $send_email_message );
|
191 |
+
} else {
|
192 |
+
$send_email_message = __( 'Message has been submitted successfully.', 'mainwp-child' );
|
193 |
+
}
|
194 |
+
} else {
|
195 |
+
$send_email_message = __( 'Sending email failed!', 'mainwp-child' );
|
196 |
+
}
|
197 |
+
?>
|
198 |
+
<div class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '  ' . $back_link; ?></div>
|
199 |
+
<?php
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Send support email.
|
204 |
+
*
|
205 |
+
* @return bool Return TRUE on success FALSE on failure.
|
206 |
+
*
|
207 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options()
|
208 |
+
*/
|
209 |
+
public function send_support_mail() {
|
210 |
+
$opts = MainWP_Child_Branding::instance()->get_branding_options();
|
211 |
+
$email = $opts['support_email'];
|
212 |
+
$sub = isset( $_POST['mainwp_branding_contact_message_subject'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_subject'] ) ) ) ) : '';
|
213 |
+
$from = isset( $_POST['mainwp_branding_contact_send_from'] ) ? trim( wp_unslash( $_POST['mainwp_branding_contact_send_from'] ) ) : '';
|
214 |
+
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
|
215 |
+
$content = isset( $_POST['mainwp_branding_contact_message_content'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_content'] ) ) ) ) : '';
|
216 |
+
$mail = '';
|
217 |
+
$headers = '';
|
218 |
+
|
219 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
220 |
+
|
221 |
+
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Current user global.
|
225 |
+
*
|
226 |
+
* @global string
|
227 |
+
*/
|
228 |
+
global $current_user;
|
229 |
+
|
230 |
+
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
|
231 |
+
if ( ! empty( $from ) ) {
|
232 |
+
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
|
233 |
+
}
|
234 |
+
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
|
235 |
+
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $from_page ) ? "<a href='" . esc_url( $from_page ) . "'>" . esc_url( $from_page ) . "</a></p>\r\n\r\n" : '' );
|
236 |
+
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n";
|
237 |
+
$mail .= "<p>Support Text:</p>\r\n\r\n";
|
238 |
+
$mail .= '<p>' . $content . "</p>\r\n\r\n";
|
239 |
+
|
240 |
+
wp_mail( $email, $subject, $mail, $headers );
|
241 |
+
|
242 |
+
return true;
|
243 |
+
}
|
244 |
+
return false;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* After admin bar render.
|
249 |
+
*/
|
250 |
+
public function after_admin_bar_render() {
|
251 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
252 |
+
|
253 |
+
if ( ! is_array( $hide_slugs ) ) {
|
254 |
+
$hide_slugs = array();
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( 0 == count( $hide_slugs ) ) {
|
258 |
+
return;
|
259 |
+
}
|
260 |
+
|
261 |
+
if ( ! function_exists( '\get_plugin_updates' ) ) {
|
262 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
263 |
+
}
|
264 |
+
|
265 |
+
$count_hide = 0;
|
266 |
+
|
267 |
+
$updates = get_plugin_updates();
|
268 |
+
if ( is_array( $updates ) ) {
|
269 |
+
foreach ( $updates as $slug => $data ) {
|
270 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
271 |
+
$count_hide++;
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( 0 == $count_hide ) {
|
277 |
+
return;
|
278 |
+
}
|
279 |
+
?>
|
280 |
+
<script type="text/javascript">
|
281 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
282 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
283 |
+
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
|
284 |
+
itemCount;
|
285 |
+
|
286 |
+
if ( typeof( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
|
287 |
+
itemCount = $adminBarUpdates.textContent;
|
288 |
+
itemCount = parseInt( itemCount );
|
289 |
+
|
290 |
+
itemCount -= mainwpCountHide;
|
291 |
+
if ( itemCount < 0 )
|
292 |
+
itemCount = 0;
|
293 |
+
|
294 |
+
$adminBarUpdates.textContent = itemCount;
|
295 |
+
}
|
296 |
+
} );
|
297 |
+
</script>
|
298 |
+
<?php
|
299 |
+
}
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Admin footer text.
|
303 |
+
*/
|
304 |
+
public function in_admin_footer() {
|
305 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
306 |
+
|
307 |
+
if ( ! is_array( $hide_slugs ) ) {
|
308 |
+
$hide_slugs = array();
|
309 |
+
}
|
310 |
+
|
311 |
+
$count_hide = 0;
|
312 |
+
|
313 |
+
$updates = get_plugin_updates();
|
314 |
+
if ( is_array( $updates ) ) {
|
315 |
+
foreach ( $updates as $slug => $data ) {
|
316 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
317 |
+
$count_hide++;
|
318 |
+
}
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
if ( 0 == $count_hide ) {
|
323 |
+
return;
|
324 |
+
}
|
325 |
+
|
326 |
+
?>
|
327 |
+
<script type="text/javascript">
|
328 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
329 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
330 |
+
if ( typeof( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
|
331 |
+
<?php
|
332 |
+
// hide update notice row.
|
333 |
+
if ( in_array( 'mainwp-child/mainwp-child.php', $hide_slugs ) ) {
|
334 |
+
?>
|
335 |
+
var el = document.querySelector( 'tr#mainwp-child-update' );
|
336 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
337 |
+
el.style.display = 'none';
|
338 |
+
}
|
339 |
+
<?php
|
340 |
+
}
|
341 |
+
// hide update notice row.
|
342 |
+
if ( in_array( 'mainwp-child-reports/mainwp-child-reports.php', $hide_slugs ) ) {
|
343 |
+
?>
|
344 |
+
var el = document.querySelector( 'tr#mainwp-child-reports-update' );
|
345 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
346 |
+
el.style.display = 'none';
|
347 |
+
}
|
348 |
+
<?php
|
349 |
+
}
|
350 |
+
?>
|
351 |
+
}
|
352 |
+
|
353 |
+
if ( mainwpCountHide > 0 ) {
|
354 |
+
jQuery( document ).ready( function () {
|
355 |
+
|
356 |
+
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
|
357 |
+
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
|
358 |
+
itemCount;
|
359 |
+
itemCount = $adminBarUpdates.find( '.ab-label' ).text();
|
360 |
+
itemCount -= mainwpCountHide;
|
361 |
+
if ( itemCount < 0 )
|
362 |
+
itemCount = 0;
|
363 |
+
|
364 |
+
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
|
365 |
+
itemPCount -= mainwpCountHide;
|
366 |
+
|
367 |
+
if ( itemPCount < 0 )
|
368 |
+
itemPCount = 0;
|
369 |
+
|
370 |
+
$adminBarUpdates.find( '.ab-label' ).text( itemCount );
|
371 |
+
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
|
372 |
+
|
373 |
+
} );
|
374 |
+
}
|
375 |
+
} );
|
376 |
+
</script>
|
377 |
+
<?php
|
378 |
+
}
|
379 |
+
|
380 |
+
}
|
class/class-mainwp-child-branding.php
CHANGED
@@ -1,1356 +1,1392 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Branding
|
4 |
-
*
|
5 |
-
* MainWP Branding extension handler.
|
6 |
-
* Extension URL: https://mainwp.com/extension/branding/
|
7 |
-
*
|
8 |
-
* @package MainWP\Child
|
9 |
-
*/
|
10 |
-
|
11 |
-
namespace MainWP\Child;
|
12 |
-
|
13 |
-
// phpcs:disable Generic.Metrics.CyclomaticComplexity -- to custom read/write files, complex functions/features.
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Class MainWP_Child_Branding
|
17 |
-
*
|
18 |
-
* MainWP Branding extension handler.
|
19 |
-
*/
|
20 |
-
class MainWP_Child_Branding {
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Public static variable to hold the single instance of the class.
|
24 |
-
*
|
25 |
-
* @var mixed Default null
|
26 |
-
*/
|
27 |
-
public static $instance = null;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Public variable to hold the MainWP Child plugin directory information.
|
31 |
-
*
|
32 |
-
* @var string Default null
|
33 |
-
*/
|
34 |
-
public $child_plugin_dir;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Method instance()
|
38 |
-
*
|
39 |
-
* Create a public static instance.
|
40 |
-
*
|
41 |
-
* @return mixed Class instance.
|
42 |
-
*/
|
43 |
-
public static function instance() {
|
44 |
-
if ( null === self::$instance ) {
|
45 |
-
self::$instance = new self();
|
46 |
-
}
|
47 |
-
return self::$instance;
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* MainWP_Child_Branding constructor.
|
52 |
-
*
|
53 |
-
* Run any time class is called.
|
54 |
-
*
|
55 |
-
* @return void
|
56 |
-
*/
|
57 |
-
public function __construct() {
|
58 |
-
$this->child_plugin_dir = dirname( dirname( __FILE__ ) );
|
59 |
-
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
60 |
-
add_filter( 'mainwp_child_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
|
61 |
-
$this->child_branding_options = $this->init_options();
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Method init_options()
|
66 |
-
*
|
67 |
-
* Initiate the branding extension options.
|
68 |
-
*
|
69 |
-
* @return array Array containing branding options.
|
70 |
-
*/
|
71 |
-
public function init_options() {
|
72 |
-
|
73 |
-
$opts = get_option( 'mainwp_child_branding_settings' );
|
74 |
-
|
75 |
-
if ( ! is_array( $opts ) ) {
|
76 |
-
$opts = array();
|
77 |
-
}
|
78 |
-
|
79 |
-
if ( ! isset( $opts['contact_label'] ) || empty( $opts['contact_label'] ) ) {
|
80 |
-
$opts['contact_label'] = __( 'Contact Support', 'mainwp-child' );
|
81 |
-
}
|
82 |
-
|
83 |
-
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
|
84 |
-
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
|
85 |
-
$cancelled_branding = ( 'yes' === $disconnected ) && ! $preserve_branding;
|
86 |
-
|
87 |
-
$opts['cancelled_branding'] = $cancelled_branding;
|
88 |
-
$opts['branding_preserve_title'] = '';
|
89 |
-
|
90 |
-
if ( ! $cancelled_branding ) {
|
91 |
-
if ( isset( $opts['branding_header'] ) ) {
|
92 |
-
$branding_header = $opts['branding_header'];
|
93 |
-
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
|
94 |
-
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
|
95 |
-
}
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Filter 'mainwp_child_branding_init_options'
|
101 |
-
*
|
102 |
-
* Set custom branding setting through the filter.
|
103 |
-
*
|
104 |
-
* @since 4.0
|
105 |
-
*/
|
106 |
-
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
|
107 |
-
return $opts;
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Method get_extra_options()
|
112 |
-
*
|
113 |
-
* Get extra branding settings.
|
114 |
-
*
|
115 |
-
* @return array Array containing the extra branding settings.
|
116 |
-
*/
|
117 |
-
public function get_extra_options() {
|
118 |
-
$extra = array();
|
119 |
-
if ( is_array( $this->child_branding_options ) && isset( $this->child_branding_options['extra_settings'] ) ) {
|
120 |
-
$extra = $this->child_branding_options['extra_settings'];
|
121 |
-
if ( ! is_array( $extra ) ) {
|
122 |
-
$extra = array();
|
123 |
-
}
|
124 |
-
}
|
125 |
-
|
126 |
-
return $extra;
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Method plugin_row_meta()
|
131 |
-
*
|
132 |
-
* Handle plugin meta information when custom branding is applied.
|
133 |
-
*
|
134 |
-
* @param array $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
135 |
-
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
|
136 |
-
* @param string $child_plugin_slug MainWP Child plugin slug.
|
137 |
-
*
|
138 |
-
* @return array An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
139 |
-
*/
|
140 |
-
public function plugin_row_meta( $plugin_meta, $plugin_file, $child_plugin_slug ) {
|
141 |
-
if ( $child_plugin_slug !== $plugin_file ) {
|
142 |
-
return $plugin_meta;
|
143 |
-
}
|
144 |
-
|
145 |
-
if ( ! $this->is_branding() ) {
|
146 |
-
return $plugin_meta;
|
147 |
-
}
|
148 |
-
// hide View details links!
|
149 |
-
$meta_total = count( $plugin_meta );
|
150 |
-
for ( $i = 0; $i < $meta_total; $i++ ) {
|
151 |
-
$str_meta = $plugin_meta[ $i ];
|
152 |
-
if ( strpos( $str_meta, 'plugin-install.php?tab=plugin-information' ) ) {
|
153 |
-
unset( $plugin_meta[ $i ] );
|
154 |
-
break;
|
155 |
-
}
|
156 |
-
}
|
157 |
-
|
158 |
-
return $plugin_meta;
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Method child_deactivation()
|
163 |
-
*
|
164 |
-
* Empty custom branding options upon MainWP Child plugin deactivation.
|
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 |
-
$current_settings['
|
248 |
-
|
249 |
-
$current_settings['
|
250 |
-
$current_settings['
|
251 |
-
$current_settings['
|
252 |
-
$current_settings['
|
253 |
-
$current_settings['
|
254 |
-
$current_settings['
|
255 |
-
$current_settings['
|
256 |
-
$current_settings['
|
257 |
-
$current_settings['
|
258 |
-
$current_settings['
|
259 |
-
$current_settings['
|
260 |
-
$current_settings['
|
261 |
-
$current_settings['
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
$current_settings['
|
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 |
-
add_filter( '
|
507 |
-
add_action( '
|
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 |
-
* Method
|
536 |
-
*
|
537 |
-
*
|
538 |
-
*/
|
539 |
-
public function
|
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 |
-
$extra_setting
|
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 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
$
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
}
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
*
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
*
|
1185 |
-
*
|
1186 |
-
*
|
1187 |
-
*
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
*
|
1233 |
-
*
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
*
|
1246 |
-
*
|
1247 |
-
*
|
1248 |
-
*
|
1249 |
-
*
|
1250 |
-
*
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
*
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
*
|
1325 |
-
*
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Branding
|
4 |
+
*
|
5 |
+
* MainWP Branding extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/branding/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace MainWP\Child;
|
12 |
+
|
13 |
+
// phpcs:disable Generic.Metrics.CyclomaticComplexity -- to custom read/write files, complex functions/features.
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class MainWP_Child_Branding
|
17 |
+
*
|
18 |
+
* MainWP Branding extension handler.
|
19 |
+
*/
|
20 |
+
class MainWP_Child_Branding {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Public static variable to hold the single instance of the class.
|
24 |
+
*
|
25 |
+
* @var mixed Default null
|
26 |
+
*/
|
27 |
+
public static $instance = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Public variable to hold the MainWP Child plugin directory information.
|
31 |
+
*
|
32 |
+
* @var string Default null
|
33 |
+
*/
|
34 |
+
public $child_plugin_dir;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Method instance()
|
38 |
+
*
|
39 |
+
* Create a public static instance.
|
40 |
+
*
|
41 |
+
* @return mixed Class instance.
|
42 |
+
*/
|
43 |
+
public static function instance() {
|
44 |
+
if ( null === self::$instance ) {
|
45 |
+
self::$instance = new self();
|
46 |
+
}
|
47 |
+
return self::$instance;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* MainWP_Child_Branding constructor.
|
52 |
+
*
|
53 |
+
* Run any time class is called.
|
54 |
+
*
|
55 |
+
* @return void
|
56 |
+
*/
|
57 |
+
public function __construct() {
|
58 |
+
$this->child_plugin_dir = dirname( dirname( __FILE__ ) );
|
59 |
+
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
60 |
+
add_filter( 'mainwp_child_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
|
61 |
+
$this->child_branding_options = $this->init_options();
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Method init_options()
|
66 |
+
*
|
67 |
+
* Initiate the branding extension options.
|
68 |
+
*
|
69 |
+
* @return array Array containing branding options.
|
70 |
+
*/
|
71 |
+
public function init_options() {
|
72 |
+
|
73 |
+
$opts = get_option( 'mainwp_child_branding_settings' );
|
74 |
+
|
75 |
+
if ( ! is_array( $opts ) ) {
|
76 |
+
$opts = array();
|
77 |
+
}
|
78 |
+
|
79 |
+
if ( ! isset( $opts['contact_label'] ) || empty( $opts['contact_label'] ) ) {
|
80 |
+
$opts['contact_label'] = __( 'Contact Support', 'mainwp-child' );
|
81 |
+
}
|
82 |
+
|
83 |
+
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
|
84 |
+
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
|
85 |
+
$cancelled_branding = ( 'yes' === $disconnected ) && ! $preserve_branding;
|
86 |
+
|
87 |
+
$opts['cancelled_branding'] = $cancelled_branding;
|
88 |
+
$opts['branding_preserve_title'] = '';
|
89 |
+
|
90 |
+
if ( ! $cancelled_branding ) {
|
91 |
+
if ( isset( $opts['branding_header'] ) ) {
|
92 |
+
$branding_header = $opts['branding_header'];
|
93 |
+
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
|
94 |
+
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Filter 'mainwp_child_branding_init_options'
|
101 |
+
*
|
102 |
+
* Set custom branding setting through the filter.
|
103 |
+
*
|
104 |
+
* @since 4.0
|
105 |
+
*/
|
106 |
+
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
|
107 |
+
return $opts;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Method get_extra_options()
|
112 |
+
*
|
113 |
+
* Get extra branding settings.
|
114 |
+
*
|
115 |
+
* @return array Array containing the extra branding settings.
|
116 |
+
*/
|
117 |
+
public function get_extra_options() {
|
118 |
+
$extra = array();
|
119 |
+
if ( is_array( $this->child_branding_options ) && isset( $this->child_branding_options['extra_settings'] ) ) {
|
120 |
+
$extra = $this->child_branding_options['extra_settings'];
|
121 |
+
if ( ! is_array( $extra ) ) {
|
122 |
+
$extra = array();
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
return $extra;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Method plugin_row_meta()
|
131 |
+
*
|
132 |
+
* Handle plugin meta information when custom branding is applied.
|
133 |
+
*
|
134 |
+
* @param array $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
135 |
+
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
|
136 |
+
* @param string $child_plugin_slug MainWP Child plugin slug.
|
137 |
+
*
|
138 |
+
* @return array An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
139 |
+
*/
|
140 |
+
public function plugin_row_meta( $plugin_meta, $plugin_file, $child_plugin_slug ) {
|
141 |
+
if ( $child_plugin_slug !== $plugin_file ) {
|
142 |
+
return $plugin_meta;
|
143 |
+
}
|
144 |
+
|
145 |
+
if ( ! $this->is_branding() ) {
|
146 |
+
return $plugin_meta;
|
147 |
+
}
|
148 |
+
// hide View details links!
|
149 |
+
$meta_total = count( $plugin_meta );
|
150 |
+
for ( $i = 0; $i < $meta_total; $i++ ) {
|
151 |
+
$str_meta = $plugin_meta[ $i ];
|
152 |
+
if ( strpos( $str_meta, 'plugin-install.php?tab=plugin-information' ) ) {
|
153 |
+
unset( $plugin_meta[ $i ] );
|
154 |
+
break;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
return $plugin_meta;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Method child_deactivation()
|
163 |
+
*
|
164 |
+
* Empty custom branding options upon MainWP Child plugin deactivation.
|
165 |
+
*
|
166 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
167 |
+
*/
|
168 |
+
public function child_deactivation() {
|
169 |
+
$brandingOptions_empty = array(
|
170 |
+
'hide',
|
171 |
+
'disable_change',
|
172 |
+
'disable_switching_theme',
|
173 |
+
'show_support',
|
174 |
+
'support_email',
|
175 |
+
'support_message',
|
176 |
+
'remove_restore',
|
177 |
+
'remove_setting',
|
178 |
+
'remove_server_info',
|
179 |
+
'remove_wp_tools',
|
180 |
+
'remove_wp_setting',
|
181 |
+
'remove_permalink',
|
182 |
+
'contact_label',
|
183 |
+
'email_message',
|
184 |
+
'message_return_sender',
|
185 |
+
'submit_button_title',
|
186 |
+
'extra_settings',
|
187 |
+
'branding_ext_enabled',
|
188 |
+
);
|
189 |
+
|
190 |
+
foreach ( $brandingOptions_empty as $opt ) {
|
191 |
+
if ( isset( $this->child_branding_options[ $opt ] ) ) {
|
192 |
+
$this->child_branding_options[ $opt ] = '';
|
193 |
+
}
|
194 |
+
}
|
195 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Method action()
|
200 |
+
*
|
201 |
+
* Fire off certain branding actions.
|
202 |
+
*
|
203 |
+
* @uses MainWP_Child_Branding::update_branding() Update custom branding settings.
|
204 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
205 |
+
*/
|
206 |
+
public function action() {
|
207 |
+
$information = array();
|
208 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
209 |
+
switch ( $mwp_action ) {
|
210 |
+
case 'update_branding':
|
211 |
+
$information = $this->update_branding();
|
212 |
+
break;
|
213 |
+
}
|
214 |
+
MainWP_Helper::write( $information );
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Method update_branding()
|
219 |
+
*
|
220 |
+
* Update custom branding settings.
|
221 |
+
*
|
222 |
+
* @return array Action result.
|
223 |
+
*
|
224 |
+
* @used-by \MainWP\Child\MainWP_Child_Branding::action() Fire off certain Google Pagespeed Insights plugin actions.
|
225 |
+
*
|
226 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
227 |
+
*/
|
228 |
+
public function update_branding() {
|
229 |
+
$information = array();
|
230 |
+
$settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for bacwards compatibility.
|
231 |
+
if ( ! is_array( $settings ) ) {
|
232 |
+
return $information;
|
233 |
+
}
|
234 |
+
|
235 |
+
$current_settings = $this->child_branding_options;
|
236 |
+
$current_extra_setting = $this->child_branding_options['extra_settings'];
|
237 |
+
|
238 |
+
$current_settings['branding_ext_enabled'] = 'Y';
|
239 |
+
|
240 |
+
$header = array(
|
241 |
+
'name' => $settings['child_plugin_name'],
|
242 |
+
'description' => $settings['child_plugin_desc'],
|
243 |
+
'author' => $settings['child_plugin_author'],
|
244 |
+
'authoruri' => $settings['child_plugin_author_uri'],
|
245 |
+
'pluginuri' => isset( $settings['child_plugin_uri'] ) ? $settings['child_plugin_uri'] : '',
|
246 |
+
);
|
247 |
+
$current_settings['branding_header'] = $header;
|
248 |
+
|
249 |
+
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
|
250 |
+
$current_settings['support_email'] = $settings['child_support_email'];
|
251 |
+
$current_settings['support_message'] = $settings['child_support_message'];
|
252 |
+
$current_settings['remove_restore'] = $settings['child_remove_restore'];
|
253 |
+
$current_settings['remove_setting'] = $settings['child_remove_setting'];
|
254 |
+
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
|
255 |
+
$current_settings['remove_connection_detail'] = isset( $settings['child_remove_connection_detail'] ) ? $settings['child_remove_connection_detail'] : 0;
|
256 |
+
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
|
257 |
+
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
|
258 |
+
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
|
259 |
+
$current_settings['contact_label'] = $settings['child_button_contact_label'];
|
260 |
+
$current_settings['email_message'] = $settings['child_send_email_message'];
|
261 |
+
$current_settings['message_return_sender'] = $settings['child_message_return_sender'];
|
262 |
+
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
|
263 |
+
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
|
264 |
+
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) ? 'T' : '';
|
265 |
+
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
|
266 |
+
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
|
267 |
+
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
|
268 |
+
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
|
269 |
+
}
|
270 |
+
$current_settings['extra_settings'] = $this->get_extra_settings( $current_extra_setting, $settings, $information );
|
271 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
|
272 |
+
|
273 |
+
$information['result'] = 'SUCCESS';
|
274 |
+
|
275 |
+
return $information;
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Method get_extra_settings()
|
280 |
+
*
|
281 |
+
* Get extra branding settings.
|
282 |
+
*
|
283 |
+
* @param array $current_extra_setting An array containing the current extra branding settings.
|
284 |
+
* @param array $settings An array containing the branding settings.
|
285 |
+
* @param array $information An array containing the synchronization information.
|
286 |
+
*
|
287 |
+
* @used-by MainWP_Child_Branding::update_branding() Update custom branding settings.
|
288 |
+
*
|
289 |
+
* @return array An array of branding extra settings
|
290 |
+
*/
|
291 |
+
public function get_extra_settings( $current_extra_setting, $settings, &$information ) {
|
292 |
+
|
293 |
+
$extra_setting = array(
|
294 |
+
'show_button_in' => $settings['child_show_support_button_in'],
|
295 |
+
'global_footer' => $settings['child_global_footer'],
|
296 |
+
'dashboard_footer' => $settings['child_dashboard_footer'],
|
297 |
+
'remove_widget_welcome' => $settings['child_remove_widget_welcome'],
|
298 |
+
'remove_widget_glance' => $settings['child_remove_widget_glance'],
|
299 |
+
'remove_widget_activity' => $settings['child_remove_widget_activity'],
|
300 |
+
'remove_widget_quick' => $settings['child_remove_widget_quick'],
|
301 |
+
'remove_widget_news' => $settings['child_remove_widget_news'],
|
302 |
+
'login_image_link' => $settings['child_login_image_link'],
|
303 |
+
'login_image_title' => $settings['child_login_image_title'],
|
304 |
+
'site_generator' => $settings['child_site_generator'],
|
305 |
+
'generator_link' => $settings['child_generator_link'],
|
306 |
+
'admin_css' => $settings['child_admin_css'],
|
307 |
+
'login_css' => $settings['child_login_css'],
|
308 |
+
'texts_replace' => $settings['child_texts_replace'],
|
309 |
+
'hide_nag' => $settings['child_hide_nag'],
|
310 |
+
'hide_screen_opts' => $settings['child_hide_screen_opts'],
|
311 |
+
'hide_help_box' => $settings['child_hide_help_box'],
|
312 |
+
'hide_metabox_post_excerpt' => $settings['child_hide_metabox_post_excerpt'],
|
313 |
+
'hide_metabox_post_slug' => $settings['child_hide_metabox_post_slug'],
|
314 |
+
'hide_metabox_post_tags' => $settings['child_hide_metabox_post_tags'],
|
315 |
+
'hide_metabox_post_author' => $settings['child_hide_metabox_post_author'],
|
316 |
+
'hide_metabox_post_comments' => $settings['child_hide_metabox_post_comments'],
|
317 |
+
'hide_metabox_post_revisions' => $settings['child_hide_metabox_post_revisions'],
|
318 |
+
'hide_metabox_post_discussion' => $settings['child_hide_metabox_post_discussion'],
|
319 |
+
'hide_metabox_post_categories' => $settings['child_hide_metabox_post_categories'],
|
320 |
+
'hide_metabox_post_custom_fields' => $settings['child_hide_metabox_post_custom_fields'],
|
321 |
+
'hide_metabox_post_trackbacks' => $settings['child_hide_metabox_post_trackbacks'],
|
322 |
+
'hide_metabox_page_custom_fields' => $settings['child_hide_metabox_page_custom_fields'],
|
323 |
+
'hide_metabox_page_author' => $settings['child_hide_metabox_page_author'],
|
324 |
+
'hide_metabox_page_discussion' => $settings['child_hide_metabox_page_discussion'],
|
325 |
+
'hide_metabox_page_revisions' => $settings['child_hide_metabox_page_revisions'],
|
326 |
+
'hide_metabox_page_attributes' => $settings['child_hide_metabox_page_attributes'],
|
327 |
+
'hide_metabox_page_slug' => $settings['child_hide_metabox_page_slug'],
|
328 |
+
);
|
329 |
+
|
330 |
+
if ( isset( $settings['child_login_image_url'] ) ) {
|
331 |
+
if ( empty( $settings['child_login_image_url'] ) ) {
|
332 |
+
$extra_setting['login_image'] = array();
|
333 |
+
} else {
|
334 |
+
try {
|
335 |
+
$upload = $this->branding_upload_image( $settings['child_login_image_url'] );
|
336 |
+
if ( null !== $upload ) {
|
337 |
+
$extra_setting['login_image'] = array(
|
338 |
+
'path' => $upload['path'],
|
339 |
+
'url' => $upload['url'],
|
340 |
+
);
|
341 |
+
if ( isset( $current_extra_setting['login_image']['path'] ) ) {
|
342 |
+
$old_file = $current_extra_setting['login_image']['path'];
|
343 |
+
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
344 |
+
unlink( $old_file );
|
345 |
+
}
|
346 |
+
}
|
347 |
+
}
|
348 |
+
} catch ( \Exception $e ) {
|
349 |
+
$information['error']['login_image'] = $e->getMessage();
|
350 |
+
}
|
351 |
+
}
|
352 |
+
} elseif ( isset( $current_extra_setting['login_image'] ) ) {
|
353 |
+
$extra_setting['login_image'] = $current_extra_setting['login_image'];
|
354 |
+
}
|
355 |
+
|
356 |
+
if ( isset( $settings['child_favico_image_url'] ) ) {
|
357 |
+
if ( empty( $settings['child_favico_image_url'] ) ) {
|
358 |
+
$extra_setting['favico_image'] = array();
|
359 |
+
} else {
|
360 |
+
try {
|
361 |
+
$upload = $this->branding_upload_image( $settings['child_favico_image_url'] );
|
362 |
+
if ( null !== $upload ) {
|
363 |
+
$extra_setting['favico_image'] = array(
|
364 |
+
'path' => $upload['path'],
|
365 |
+
'url' => $upload['url'],
|
366 |
+
);
|
367 |
+
if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
|
368 |
+
$old_file = $current_extra_setting['favico_image']['path'];
|
369 |
+
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
370 |
+
unlink( $old_file );
|
371 |
+
}
|
372 |
+
}
|
373 |
+
}
|
374 |
+
} catch ( \Exception $e ) {
|
375 |
+
$information['error']['favico_image'] = $e->getMessage();
|
376 |
+
}
|
377 |
+
}
|
378 |
+
} elseif ( isset( $current_extra_setting['favico_image'] ) ) {
|
379 |
+
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
|
380 |
+
}
|
381 |
+
return $extra_setting;
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Method branding_upload_image()
|
386 |
+
*
|
387 |
+
* Upload custom image from MainWP Dashboard.
|
388 |
+
*
|
389 |
+
* @param string $img_url Contains image URL.
|
390 |
+
*
|
391 |
+
* @return array An array containing the image information such as path and URL.
|
392 |
+
* @throws \Exception Error message.
|
393 |
+
*
|
394 |
+
* @uses \MainWP\Child\MainWP_Helper::get_class_name()
|
395 |
+
*/
|
396 |
+
public function branding_upload_image( $img_url ) {
|
397 |
+
include_once ABSPATH . 'wp-admin/includes/file.php';
|
398 |
+
|
399 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
400 |
+
$temporary_file = download_url( $img_url );
|
401 |
+
remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
402 |
+
|
403 |
+
if ( is_wp_error( $temporary_file ) ) {
|
404 |
+
throw new \Exception( $temporary_file->get_error_message() );
|
405 |
+
} else {
|
406 |
+
$upload_dir = wp_upload_dir();
|
407 |
+
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );
|
408 |
+
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
|
409 |
+
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
|
410 |
+
$moved = rename( $temporary_file, $local_img_path );
|
411 |
+
if ( $moved ) {
|
412 |
+
return array(
|
413 |
+
'path' => $local_img_path,
|
414 |
+
'url' => $local_img_url,
|
415 |
+
);
|
416 |
+
}
|
417 |
+
}
|
418 |
+
if ( file_exists( $temporary_file ) ) {
|
419 |
+
unlink( $temporary_file );
|
420 |
+
}
|
421 |
+
|
422 |
+
return null;
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Method branding_init()
|
427 |
+
*
|
428 |
+
* Initiate custom branding features.
|
429 |
+
*
|
430 |
+
* @return void
|
431 |
+
*
|
432 |
+
* @uses \MainWP\Child\MainWP_Child_Branding_Render::instance()
|
433 |
+
* @uses \MainWP\Child\MainWP_Child_Branding_Render::get_class_name()
|
434 |
+
*/
|
435 |
+
public function branding_init() {
|
436 |
+
|
437 |
+
$extra_setting = $this->get_extra_options();
|
438 |
+
|
439 |
+
if ( is_admin() ) {
|
440 |
+
add_action( 'in_admin_footer', array( MainWP_Child_Branding_Render::instance(), 'in_admin_footer' ) );
|
441 |
+
} elseif ( is_user_logged_in() ) {
|
442 |
+
add_action( 'wp_after_admin_bar_render', array( MainWP_Child_Branding_Render::instance(), 'after_admin_bar_render' ) );
|
443 |
+
}
|
444 |
+
|
445 |
+
$opts = $this->child_branding_options;
|
446 |
+
|
447 |
+
$cancelled_branding = $opts['cancelled_branding'];
|
448 |
+
|
449 |
+
if ( $cancelled_branding ) {
|
450 |
+
return;
|
451 |
+
}
|
452 |
+
|
453 |
+
// enable branding in case child plugin deactive and re-activated.
|
454 |
+
add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) );
|
455 |
+
|
456 |
+
if ( $this->is_branding() ) {
|
457 |
+
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
458 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
459 |
+
}
|
460 |
+
|
461 |
+
if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
|
462 |
+
return;
|
463 |
+
}
|
464 |
+
|
465 |
+
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
|
466 |
+
|
467 |
+
if ( 'T' === $opts['disable_change'] ) {
|
468 |
+
|
469 |
+
// Disable the WordPress plugin update notifications.
|
470 |
+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
471 |
+
add_filter( 'pre_site_transient_update_plugins', '__return_null' );
|
472 |
+
|
473 |
+
// Disable the WordPress theme update notifications.
|
474 |
+
remove_action( 'load-update-core.php', 'wp_update_themes' );
|
475 |
+
add_filter(
|
476 |
+
'pre_site_transient_update_themes',
|
477 |
+
function( $a ) {
|
478 |
+
return null;
|
479 |
+
}
|
480 |
+
);
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Disable the WordPress core update notifications.
|
484 |
+
*
|
485 |
+
* @uses MainWP_Child_Branding_Render::get_class_name()
|
486 |
+
*/
|
487 |
+
function remove_core_updates() {
|
488 |
+
add_action(
|
489 |
+
'init',
|
490 |
+
function( $a ) {
|
491 |
+
remove_action( 'wp_version_check', 'wp_version_check' );
|
492 |
+
},
|
493 |
+
2
|
494 |
+
);
|
495 |
+
add_filter( 'pre_option_update_core', '__return_null' );
|
496 |
+
add_filter( 'pre_site_transient_update_core', '__return_null' );
|
497 |
+
} add_action( 'after_setup_theme', 'remove_core_updates' );
|
498 |
+
|
499 |
+
add_action( 'admin_head', array( MainWP_Child_Branding_Render::get_class_name(), 'admin_head_hide_elements' ), 15 );
|
500 |
+
add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9 );
|
501 |
+
}
|
502 |
+
|
503 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
504 |
+
|
505 |
+
if ( ! isset( $opts['disable_wp_branding'] ) || 'Y' !== $opts['disable_wp_branding'] ) {
|
506 |
+
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
|
507 |
+
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
|
508 |
+
// branding site generator.
|
509 |
+
$types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' );
|
510 |
+
foreach ( $types as $type ) {
|
511 |
+
add_filter( 'get_the_generator_' . $type, array( &$this, 'custom_generator' ), 999, 2 );
|
512 |
+
}
|
513 |
+
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
514 |
+
add_action( 'login_enqueue_scripts', array( &$this, 'custom_login_css' ) );
|
515 |
+
add_filter( 'gettext', array( &$this, 'custom_gettext' ), 99, 3 );
|
516 |
+
add_action( 'login_head', array( &$this, 'custom_login_logo' ) );
|
517 |
+
add_filter( 'login_headerurl', array( &$this, 'custom_login_headerurl' ) );
|
518 |
+
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
|
519 |
+
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
|
520 |
+
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
521 |
+
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
|
522 |
+
add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 );
|
523 |
+
}
|
524 |
+
|
525 |
+
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
|
526 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
527 |
+
}
|
528 |
+
|
529 |
+
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
|
530 |
+
add_action( 'admin_menu', array( &$this, 'remove_default_page_metaboxes' ) );
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Method admin_init()
|
536 |
+
*
|
537 |
+
* Remove remove the update nag.
|
538 |
+
*/
|
539 |
+
public function admin_init() {
|
540 |
+
remove_action( 'admin_notices', 'update_nag', 3 );
|
541 |
+
}
|
542 |
+
|
543 |
+
/**
|
544 |
+
* Method admin_menu()
|
545 |
+
*
|
546 |
+
* Add the support form page admin menu item.
|
547 |
+
*
|
548 |
+
* @uses \MainWP\Child\MainWP_Child_Branding_Render::instance()
|
549 |
+
*/
|
550 |
+
public function admin_menu() {
|
551 |
+
|
552 |
+
/**
|
553 |
+
* Filter 'mainwp_branding_role_cap_enable_contact_form'
|
554 |
+
*
|
555 |
+
* Manage the support form visibility. Set false to hide the support form page.
|
556 |
+
*
|
557 |
+
* @since 4.0
|
558 |
+
*/
|
559 |
+
$enable_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
|
560 |
+
|
561 |
+
if ( ! $enable_contact && ! current_user_can( 'administrator' ) ) {
|
562 |
+
return false;
|
563 |
+
}
|
564 |
+
|
565 |
+
$extra_setting = $this->get_extra_options();
|
566 |
+
if ( empty( $extra_setting ) ) {
|
567 |
+
return false;
|
568 |
+
}
|
569 |
+
$opts = $this->child_branding_options;
|
570 |
+
|
571 |
+
if ( 'T' === $opts['show_support'] ) {
|
572 |
+
$title = $opts['contact_label'];
|
573 |
+
if ( isset( $extra_setting['show_button_in'] ) && ( 2 === (int) $extra_setting['show_button_in'] || 3 === (int) $extra_setting['show_button_in'] ) ) {
|
574 |
+
$title = $opts['contact_label'];
|
575 |
+
add_menu_page(
|
576 |
+
$title,
|
577 |
+
$title,
|
578 |
+
'read',
|
579 |
+
'ContactSupport2',
|
580 |
+
array(
|
581 |
+
MainWP_Child_Branding_Render::instance(),
|
582 |
+
'contact_support',
|
583 |
+
),
|
584 |
+
'',
|
585 |
+
'2.0001'
|
586 |
+
);
|
587 |
+
}
|
588 |
+
|
589 |
+
if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) {
|
590 |
+
add_submenu_page(
|
591 |
+
null,
|
592 |
+
$title,
|
593 |
+
$opts['contact_label'],
|
594 |
+
'read',
|
595 |
+
'ContactSupport',
|
596 |
+
array(
|
597 |
+
MainWP_Child_Branding_Render::instance(),
|
598 |
+
'contact_support',
|
599 |
+
)
|
600 |
+
);
|
601 |
+
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
|
602 |
+
}
|
603 |
+
}
|
604 |
+
}
|
605 |
+
|
606 |
+
/**
|
607 |
+
* Method remove_default_post_metaboxes()
|
608 |
+
*
|
609 |
+
* Hide new post screen unwanted metaboxes.
|
610 |
+
*/
|
611 |
+
public function remove_default_post_metaboxes() {
|
612 |
+
$extra_setting = $this->get_extra_options();
|
613 |
+
|
614 |
+
add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) );
|
615 |
+
add_filter( 'manage_edit-post_tag_columns', array( &$this, 'manage_my_category_columns' ) );
|
616 |
+
add_filter( 'manage_edit-category_columns', array( &$this, 'manage_my_category_columns' ) );
|
617 |
+
|
618 |
+
if ( isset( $extra_setting['hide_metabox_post_custom_fields'] ) && $extra_setting['hide_metabox_post_custom_fields'] ) {
|
619 |
+
remove_meta_box( 'postcustom', 'post', 'normal' );
|
620 |
+
}
|
621 |
+
if ( isset( $extra_setting['hide_metabox_post_excerpt'] ) && $extra_setting['hide_metabox_post_excerpt'] ) {
|
622 |
+
remove_meta_box( 'postexcerpt', 'post', 'normal' );
|
623 |
+
}
|
624 |
+
if ( isset( $extra_setting['hide_metabox_post_discussion'] ) && $extra_setting['hide_metabox_post_discussion'] ) {
|
625 |
+
remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
|
626 |
+
}
|
627 |
+
if ( isset( $extra_setting['hide_metabox_post_trackbacks'] ) && $extra_setting['hide_metabox_post_trackbacks'] ) {
|
628 |
+
remove_meta_box( 'trackbacksdiv', 'post', 'normal' );
|
629 |
+
}
|
630 |
+
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
|
631 |
+
remove_meta_box( 'slugdiv', 'post', 'normal' );
|
632 |
+
}
|
633 |
+
if ( isset( $extra_setting['hide_metabox_post_author'] ) && $extra_setting['hide_metabox_post_author'] ) {
|
634 |
+
remove_meta_box( 'authordiv', 'post', 'normal' );
|
635 |
+
}
|
636 |
+
if ( isset( $extra_setting['hide_metabox_post_revisions'] ) && $extra_setting['hide_metabox_post_revisions'] ) {
|
637 |
+
remove_meta_box( 'revisionsdiv', 'post', 'normal' );
|
638 |
+
}
|
639 |
+
if ( isset( $extra_setting['hide_metabox_post_tags'] ) && $extra_setting['hide_metabox_post_tags'] ) {
|
640 |
+
remove_meta_box( 'tagsdiv-post_tag', 'post', 'normal' );
|
641 |
+
}
|
642 |
+
if ( isset( $extra_setting['hide_metabox_post_categories'] ) && $extra_setting['hide_metabox_post_categories'] ) {
|
643 |
+
remove_meta_box( 'categorydiv', 'post', 'normal' );
|
644 |
+
}
|
645 |
+
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
|
646 |
+
remove_meta_box( 'commentsdiv', 'post', 'normal' );
|
647 |
+
}
|
648 |
+
}
|
649 |
+
|
650 |
+
/**
|
651 |
+
* Method custom_post_columns()
|
652 |
+
*
|
653 |
+
* Hide unwanted posts table columns.
|
654 |
+
*
|
655 |
+
* @param array $defaults An array containing default Manage Posts columns.
|
656 |
+
*
|
657 |
+
* @return array $defaults An updated array containing default Manage Posts columns.
|
658 |
+
*/
|
659 |
+
public function custom_post_columns( $defaults ) {
|
660 |
+
$extra_setting = $this->get_extra_options();
|
661 |
+
|
662 |
+
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
|
663 |
+
unset( $defaults['comments'] );
|
664 |
+
}
|
665 |
+
if ( isset( $extra_setting['hide_metabox_post_author'] ) && $extra_setting['hide_metabox_post_author'] ) {
|
666 |
+
unset( $defaults['author'] );
|
667 |
+
}
|
668 |
+
if ( isset( $extra_setting['hide_metabox_post_categories'] ) && $extra_setting['hide_metabox_post_categories'] ) {
|
669 |
+
unset( $defaults['categories'] );
|
670 |
+
}
|
671 |
+
|
672 |
+
return $defaults;
|
673 |
+
}
|
674 |
+
|
675 |
+
/**
|
676 |
+
* Method manage_my_category_columns()
|
677 |
+
*
|
678 |
+
* Hide the post slug metabox.
|
679 |
+
*
|
680 |
+
* @param array $defaults An array containing default Manage Posts columns.
|
681 |
+
*
|
682 |
+
* @return array $defaults An updated array containing default Manage Posts columns.
|
683 |
+
*/
|
684 |
+
public function manage_my_category_columns( $defaults ) {
|
685 |
+
$extra_setting = $this->get_extra_options();
|
686 |
+
|
687 |
+
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
|
688 |
+
unset( $defaults['slug'] );
|
689 |
+
}
|
690 |
+
|
691 |
+
return $defaults;
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Method remove_default_page_metaboxes()
|
696 |
+
*
|
697 |
+
* Hide new post screen unwanted metaboxes.
|
698 |
+
*/
|
699 |
+
public function remove_default_page_metaboxes() {
|
700 |
+
$extra_setting = $this->get_extra_options();
|
701 |
+
|
702 |
+
add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) );
|
703 |
+
|
704 |
+
if ( isset( $extra_setting['hide_metabox_page_custom_fields'] ) && $extra_setting['hide_metabox_page_custom_fields'] ) {
|
705 |
+
remove_meta_box( 'postcustom', 'page', 'normal' );
|
706 |
+
}
|
707 |
+
if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) {
|
708 |
+
remove_meta_box( 'authordiv', 'page', 'normal' );
|
709 |
+
}
|
710 |
+
if ( isset( $extra_setting['hide_metabox_page_discussion'] ) && $extra_setting['hide_metabox_page_discussion'] ) {
|
711 |
+
remove_meta_box( 'commentstatusdiv', 'page', 'normal' );
|
712 |
+
}
|
713 |
+
if ( isset( $extra_setting['hide_metabox_page_slug'] ) && $extra_setting['hide_metabox_page_slug'] ) {
|
714 |
+
remove_meta_box( 'slugdiv', 'page', 'normal' );
|
715 |
+
}
|
716 |
+
if ( isset( $extra_setting['hide_metabox_page_revisions'] ) && $extra_setting['hide_metabox_page_revisions'] ) {
|
717 |
+
remove_meta_box( 'revisionsdiv', 'page', 'normal' );
|
718 |
+
}
|
719 |
+
if ( isset( $extra_setting['hide_metabox_page_attributes'] ) && $extra_setting['hide_metabox_page_attributes'] ) {
|
720 |
+
remove_meta_box( 'pageparentdiv', 'page', 'normal' );
|
721 |
+
}
|
722 |
+
if ( isset( $extra_setting['hide_metabox_page_comments'] ) && $extra_setting['hide_metabox_page_comments'] ) {
|
723 |
+
remove_meta_box( 'commentsdiv', 'page', 'normal' );
|
724 |
+
}
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Method custom_pages_columns()
|
729 |
+
*
|
730 |
+
* Hide unwanted pages table columns.
|
731 |
+
*
|
732 |
+
* @param array $defaults An array containing default Manage Pages columns.
|
733 |
+
*
|
734 |
+
* @return array $defaults An updated array containing default Manage Pages columns.
|
735 |
+
*/
|
736 |
+
public function custom_pages_columns( $defaults ) {
|
737 |
+
$extra_setting = $this->get_extra_options();
|
738 |
+
|
739 |
+
if ( isset( $extra_setting['hide_metabox_page_comments'] ) && $extra_setting['hide_metabox_page_comments'] ) {
|
740 |
+
unset( $defaults['comments'] );
|
741 |
+
}
|
742 |
+
if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) {
|
743 |
+
unset( $defaults['author'] );
|
744 |
+
}
|
745 |
+
|
746 |
+
return $defaults;
|
747 |
+
}
|
748 |
+
|
749 |
+
/**
|
750 |
+
* Method branding_redirect()
|
751 |
+
*
|
752 |
+
* Prevent updates by redirecting access from the Updates and Plugins page.
|
753 |
+
*/
|
754 |
+
public function branding_redirect() {
|
755 |
+
$pos1 = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'update-core.php' ) : false;
|
756 |
+
$pos2 = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'plugins.php' ) : false;
|
757 |
+
if ( false !== $pos1 || false !== $pos2 ) {
|
758 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
759 |
+
exit();
|
760 |
+
}
|
761 |
+
}
|
762 |
+
|
763 |
+
/**
|
764 |
+
* Method core_update_footer()
|
765 |
+
*
|
766 |
+
* Remove the footer text containing the WP Core version info.
|
767 |
+
*/
|
768 |
+
public function core_update_footer() {
|
769 |
+
echo '';
|
770 |
+
}
|
771 |
+
|
772 |
+
/**
|
773 |
+
* Method core_update_footer()
|
774 |
+
*
|
775 |
+
* Set custom admin footer text.
|
776 |
+
*/
|
777 |
+
public function admin_footer_text() {
|
778 |
+
$extra_setting = $this->get_extra_options();
|
779 |
+
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
780 |
+
echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) );
|
781 |
+
}
|
782 |
+
}
|
783 |
+
|
784 |
+
/**
|
785 |
+
* Method custom_favicon_frontend()
|
786 |
+
*
|
787 |
+
* Set custom site favicon.
|
788 |
+
*/
|
789 |
+
public function custom_favicon_frontend() {
|
790 |
+
$extra_setting = $this->get_extra_options();
|
791 |
+
if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) {
|
792 |
+
$favico = $extra_setting['favico_image']['url'];
|
793 |
+
echo '<link rel="shortcut icon" href="' . esc_url( $favico ) . '"/>' . "\n";
|
794 |
+
}
|
795 |
+
}
|
796 |
+
|
797 |
+
/**
|
798 |
+
* Method custom_login_logo()
|
799 |
+
*
|
800 |
+
* Set custom site login page logo.
|
801 |
+
*/
|
802 |
+
public function custom_login_logo() {
|
803 |
+
$extra_setting = $this->get_extra_options();
|
804 |
+
if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) {
|
805 |
+
$login_logo = $extra_setting['login_image']['url'];
|
806 |
+
echo '<style type="text/css">#login h1 a { background-image: url(\'' . esc_url( $login_logo ) . '\') !important; height:70px !important; width:310px !important; background-size: auto auto !important; }</style>';
|
807 |
+
}
|
808 |
+
}
|
809 |
+
|
810 |
+
/**
|
811 |
+
* Method custom_login_headerurl()
|
812 |
+
*
|
813 |
+
* Set custom site login logo link.
|
814 |
+
*
|
815 |
+
* @param string $value Contains the image link information.
|
816 |
+
*
|
817 |
+
* @return string $value Contains the image link updated information.
|
818 |
+
*/
|
819 |
+
public function custom_login_headerurl( $value ) {
|
820 |
+
$extra_setting = $this->get_extra_options();
|
821 |
+
if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) {
|
822 |
+
return $extra_setting['login_image_link'];
|
823 |
+
}
|
824 |
+
|
825 |
+
return $value;
|
826 |
+
}
|
827 |
+
|
828 |
+
/**
|
829 |
+
* Method custom_login_headertitle()
|
830 |
+
*
|
831 |
+
* Set custom site login logo title.
|
832 |
+
*
|
833 |
+
* @param string $value Contains the image title information.
|
834 |
+
*
|
835 |
+
* @return string $value Contains the image title updated information.
|
836 |
+
*/
|
837 |
+
public function custom_login_headertitle( $value ) {
|
838 |
+
$extra_setting = $this->get_extra_options();
|
839 |
+
if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) {
|
840 |
+
return $extra_setting['login_image_title'];
|
841 |
+
}
|
842 |
+
|
843 |
+
return $value;
|
844 |
+
}
|
845 |
+
|
846 |
+
/**
|
847 |
+
* Method custom_gettext()
|
848 |
+
*
|
849 |
+
* Replace language domains.
|
850 |
+
*
|
851 |
+
* @param array $translations An array containing the list of available translations.
|
852 |
+
* @param string $text Contains the text to replace.
|
853 |
+
* @param string $domain Contains the language domain.
|
854 |
+
*
|
855 |
+
* @return array $translations An array containing the list of available translations.
|
856 |
+
*/
|
857 |
+
public function custom_gettext( $translations, $text, $domain = 'default' ) {
|
858 |
+
$extra_setting = $this->get_extra_options();
|
859 |
+
$texts_replace = $extra_setting['texts_replace'];
|
860 |
+
if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) {
|
861 |
+
foreach ( $texts_replace as $text => $replace ) {
|
862 |
+
if ( ! empty( $text ) ) {
|
863 |
+
$translations = str_replace( $text, $replace, $translations );
|
864 |
+
}
|
865 |
+
}
|
866 |
+
}
|
867 |
+
|
868 |
+
return $translations;
|
869 |
+
}
|
870 |
+
|
871 |
+
/**
|
872 |
+
* Method custom_admin_css()
|
873 |
+
*
|
874 |
+
* Set custom WP Admin area CSS.
|
875 |
+
*/
|
876 |
+
public function custom_admin_css() {
|
877 |
+
$header_css = '';
|
878 |
+
$extra_setting = $this->get_extra_options();
|
879 |
+
|
880 |
+
if ( isset( $extra_setting['admin_css'] ) && ! empty( $extra_setting['admin_css'] ) ) {
|
881 |
+
$header_css .= $extra_setting['admin_css'];
|
882 |
+
}
|
883 |
+
|
884 |
+
if ( isset( $extra_setting['hide_screen_opts'] ) && ! empty( $extra_setting['hide_screen_opts'] ) ) {
|
885 |
+
$header_css .= ' #screen-options-link-wrap { display: none; }';
|
886 |
+
}
|
887 |
+
|
888 |
+
if ( isset( $extra_setting['hide_help_box'] ) && ! empty( $extra_setting['hide_help_box'] ) ) {
|
889 |
+
$header_css .= ' #contextual-help-link-wrap { display: none; }';
|
890 |
+
$header_css .= ' #contextual-help-link { display: none; }';
|
891 |
+
}
|
892 |
+
|
893 |
+
if ( ! empty( $header_css ) ) {
|
894 |
+
echo '<style>' . self::parse_css( $header_css ) . '</style>';
|
895 |
+
}
|
896 |
+
}
|
897 |
+
|
898 |
+
/**
|
899 |
+
* Method custom_login_css()
|
900 |
+
*
|
901 |
+
* Set custom Login page CSS.
|
902 |
+
*/
|
903 |
+
public function custom_login_css() {
|
904 |
+
$extra_setting = $this->get_extra_options();
|
905 |
+
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
|
906 |
+
echo '<style>' . self::parse_css( $extra_setting['login_css'] ) . '</style>';
|
907 |
+
}
|
908 |
+
}
|
909 |
+
|
910 |
+
/**
|
911 |
+
* Method parse_css()
|
912 |
+
*
|
913 |
+
* Parses CSS into an array.
|
914 |
+
*
|
915 |
+
* @param string $css Contains the CSS code that needs to be parsed.
|
916 |
+
*
|
917 |
+
* @return mixed Rebuilt CSS.
|
918 |
+
*
|
919 |
+
* Copyright (C) 2009 Peter Kröner, CSSPARSER.
|
920 |
+
*/
|
921 |
+
public static function parse_css( $css ) {
|
922 |
+
|
923 |
+
// Remove CSS-Comments.
|
924 |
+
$css = preg_replace( '/\/\*.*?\*\//ms', '', $css );
|
925 |
+
// Remove HTML-Comments.
|
926 |
+
$css = preg_replace( '/([^\'"]+?)(\<!--|--\>)([^\'"]+?)/ms', '$1$3', $css );
|
927 |
+
// Extract @media-blocks into $blocks.
|
928 |
+
preg_match_all( '/@.+?\}[^\}]*?\}/ms', $css, $blocks );
|
929 |
+
// Append the rest to $blocks.
|
930 |
+
array_push( $blocks[0], preg_replace( '/@.+?\}[^\}]*?\}/ms', '', $css ) );
|
931 |
+
$ordered = array();
|
932 |
+
$count_blocks = count( $blocks[0] );
|
933 |
+
for ( $i = 0; $i < $count_blocks; $i++ ) {
|
934 |
+
// If @media-block, strip declaration and parenthesis.
|
935 |
+
if ( '@media' === substr( $blocks[0][ $i ], 0, 6 ) ) {
|
936 |
+
$ordered_key = preg_replace( '/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ] );
|
937 |
+
$ordered_value = preg_replace( '/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ] );
|
938 |
+
} elseif ( '@' === substr( $blocks[0][ $i ], 0, 1 ) ) {
|
939 |
+
$ordered_key = $blocks[0][ $i ];
|
940 |
+
$ordered_value = $blocks[0][ $i ];
|
941 |
+
} else {
|
942 |
+
$ordered_key = 'main';
|
943 |
+
$ordered_value = $blocks[0][ $i ];
|
944 |
+
}
|
945 |
+
// Split by parenthesis, ignoring those inside content-quotes.
|
946 |
+
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
947 |
+
}
|
948 |
+
return self::parse_css_rebuild( $ordered );
|
949 |
+
}
|
950 |
+
|
951 |
+
/**
|
952 |
+
* Method parse_css_rebuild()
|
953 |
+
*
|
954 |
+
* Rebuild parsed CSS.
|
955 |
+
*
|
956 |
+
* @param string $ordered Contains the parsed CSS code that needs to be rebuit.
|
957 |
+
*
|
958 |
+
* @return mixed CSS output.
|
959 |
+
*
|
960 |
+
* Copyright (C) 2009 Peter Kröner, CSSPARSER.
|
961 |
+
*/
|
962 |
+
public static function parse_css_rebuild( $ordered ) {
|
963 |
+
// Beginning to rebuild new slim CSS-Array.
|
964 |
+
foreach ( $ordered as $key => $val ) {
|
965 |
+
$new = array();
|
966 |
+
$count_val = count( $val );
|
967 |
+
for ( $i = 0; $i < $count_val; $i++ ) {
|
968 |
+
// Split selectors and rules and split properties and values.
|
969 |
+
$selector = trim( $val[ $i ], " \r\n\t" );
|
970 |
+
|
971 |
+
if ( ! empty( $selector ) ) {
|
972 |
+
if ( ! isset( $new[ $selector ] ) ) {
|
973 |
+
$new[ $selector ] = array();
|
974 |
+
}
|
975 |
+
|
976 |
+
$rules = explode( ';', $val[ ++$i ] );
|
977 |
+
|
978 |
+
// to fix css like this: 'data:image/svg+xml;charset=US-ASCII'.
|
979 |
+
$tmp_rules = array();
|
980 |
+
$j = 0;
|
981 |
+
$cou = count( $rules );
|
982 |
+
while ( $j < $cou ) {
|
983 |
+
$rule = $rules[ $j ];
|
984 |
+
$pos = strpos( $rule, 'data:image/svg+xml' );
|
985 |
+
if ( 0 < $pos ) {
|
986 |
+
$len = strlen( $rule );
|
987 |
+
$len1 = strlen( 'data:image/svg+xml' );
|
988 |
+
$len2 = $pos + $len1;
|
989 |
+
if ( $len == $len2 ) {
|
990 |
+
$rule = $rule . ';' . $rules[ $j + 1 ];
|
991 |
+
$j++;
|
992 |
+
}
|
993 |
+
}
|
994 |
+
$j++;
|
995 |
+
$tmp_rules[] = $rule;
|
996 |
+
}
|
997 |
+
$rules = $tmp_rules;
|
998 |
+
|
999 |
+
foreach ( $rules as $rule ) {
|
1000 |
+
$rule = trim( $rule, " \r\n\t" );
|
1001 |
+
if ( ! empty( $rule ) ) {
|
1002 |
+
$rule = array_reverse( explode( ':', $rule ) );
|
1003 |
+
$property = trim( array_pop( $rule ), " \r\n\t" );
|
1004 |
+
$value = implode( ':', array_reverse( $rule ) );
|
1005 |
+
|
1006 |
+
if ( ! isset( $new[ $selector ][ $property ] ) || ! preg_match( '/!important/', $new[ $selector ][ $property ] ) ) {
|
1007 |
+
$new[ $selector ][ $property ] = $value;
|
1008 |
+
} elseif ( preg_match( '/!important/', $new[ $selector ][ $property ] ) && preg_match( '/!important/', $value ) ) {
|
1009 |
+
$new[ $selector ][ $property ] = $value;
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
}
|
1014 |
+
}
|
1015 |
+
$ordered[ $key ] = $new;
|
1016 |
+
}
|
1017 |
+
$parsed = $ordered;
|
1018 |
+
|
1019 |
+
$output = '';
|
1020 |
+
foreach ( $parsed as $media => $content ) {
|
1021 |
+
if ( '@media' === substr( $media, 0, 6 ) ) {
|
1022 |
+
$output .= $media . " {\n";
|
1023 |
+
$prefix = "\t";
|
1024 |
+
} else {
|
1025 |
+
$prefix = '';
|
1026 |
+
}
|
1027 |
+
|
1028 |
+
foreach ( $content as $selector => $rules ) {
|
1029 |
+
$output .= $prefix . $selector . " {\n";
|
1030 |
+
foreach ( $rules as $property => $value ) {
|
1031 |
+
$output .= $prefix . "\t" . $property . ': ' . $value;
|
1032 |
+
$output .= ";\n";
|
1033 |
+
}
|
1034 |
+
$output .= $prefix . "}\n\n";
|
1035 |
+
}
|
1036 |
+
if ( '@media' === substr( $media, 0, 6 ) ) {
|
1037 |
+
$output .= "}\n\n";
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
return $output;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
/**
|
1044 |
+
* Method custom_generator()
|
1045 |
+
*
|
1046 |
+
* Set custom generator meta tag.
|
1047 |
+
*
|
1048 |
+
* @param string $generator Contains the generator information.
|
1049 |
+
* @param string $type Contains the generator type information.
|
1050 |
+
*
|
1051 |
+
* @return string Contains the updated generator information.
|
1052 |
+
*/
|
1053 |
+
public function custom_generator( $generator, $type = '' ) {
|
1054 |
+
$extra_setting = $this->get_extra_options();
|
1055 |
+
if ( isset( $extra_setting['site_generator'] ) ) {
|
1056 |
+
if ( ! empty( $extra_setting['site_generator'] ) ) {
|
1057 |
+
switch ( $type ) :
|
1058 |
+
case 'html':
|
1059 |
+
$generator = '<meta name="generator" content="' . $extra_setting['site_generator'] . '">';
|
1060 |
+
break;
|
1061 |
+
case 'xhtml':
|
1062 |
+
$generator = '<meta name="generator" content="' . $extra_setting['site_generator'] . '" />';
|
1063 |
+
break;
|
1064 |
+
case 'atom':
|
1065 |
+
if ( ! empty( $extra_setting['generator_link'] ) ) {
|
1066 |
+
$generator = '<generator uri="' . $extra_setting['generator_link'] . '" >' . $extra_setting['site_generator'] . '</generator>';
|
1067 |
+
}
|
1068 |
+
break;
|
1069 |
+
case 'rss2':
|
1070 |
+
if ( ! empty( $extra_setting['generator_link'] ) ) {
|
1071 |
+
$generator = '<generator>' . $extra_setting['generator_link'] . '</generator>';
|
1072 |
+
}
|
1073 |
+
break;
|
1074 |
+
case 'rdf':
|
1075 |
+
if ( ! empty( $extra_setting['generator_link'] ) ) {
|
1076 |
+
$generator = '<admin:generatorAgent rdf:resource="' . $extra_setting['generator_link'] . '" />';
|
1077 |
+
}
|
1078 |
+
break;
|
1079 |
+
case 'comment':
|
1080 |
+
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" -->';
|
1081 |
+
break;
|
1082 |
+
case 'export':
|
1083 |
+
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" created="' . date( 'Y-m-d H:i' ) . '" -->'; //phpcs:ignore -- current local time.
|
1084 |
+
break;
|
1085 |
+
endswitch;
|
1086 |
+
|
1087 |
+
return $generator;
|
1088 |
+
}
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
return $generator;
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
/**
|
1095 |
+
* Method custom_dashboard_widgets()
|
1096 |
+
*
|
1097 |
+
* Hide unwanted WordPress Dashboard page widgets.
|
1098 |
+
*/
|
1099 |
+
public function custom_dashboard_widgets() {
|
1100 |
+
|
1101 |
+
/**
|
1102 |
+
* Public variable to hold the Metaboxes array.
|
1103 |
+
*
|
1104 |
+
* @var array Metaboxes.
|
1105 |
+
*/
|
1106 |
+
global $wp_meta_boxes;
|
1107 |
+
|
1108 |
+
$extra_setting = $this->get_extra_options();
|
1109 |
+
if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) {
|
1110 |
+
remove_action( 'welcome_panel', 'wp_welcome_panel' );
|
1111 |
+
}
|
1112 |
+
if ( isset( $extra_setting['remove_widget_glance'] ) && $extra_setting['remove_widget_glance'] ) {
|
1113 |
+
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'] );
|
1114 |
+
}
|
1115 |
+
if ( isset( $extra_setting['remove_widget_activity'] ) && $extra_setting['remove_widget_activity'] ) {
|
1116 |
+
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity'] );
|
1117 |
+
}
|
1118 |
+
if ( isset( $extra_setting['remove_widget_quick'] ) && $extra_setting['remove_widget_quick'] ) {
|
1119 |
+
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] );
|
1120 |
+
}
|
1121 |
+
if ( isset( $extra_setting['remove_widget_news'] ) && $extra_setting['remove_widget_news'] ) {
|
1122 |
+
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
|
1123 |
+
}
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
/**
|
1127 |
+
* Method branding_global_footer()
|
1128 |
+
*
|
1129 |
+
* Set custom footer text.
|
1130 |
+
*/
|
1131 |
+
public function branding_global_footer() {
|
1132 |
+
$extra_setting = $this->get_extra_options();
|
1133 |
+
if ( isset( $extra_setting['global_footer'] ) && ! empty( $extra_setting['global_footer'] ) ) {
|
1134 |
+
echo wp_kses_post( nl2br( stripslashes( $extra_setting['global_footer'] ) ) );
|
1135 |
+
}
|
1136 |
+
}
|
1137 |
+
|
1138 |
+
/**
|
1139 |
+
* Method add_support_button_in_top_admin_bar()
|
1140 |
+
*
|
1141 |
+
* Add or remove the admin bar Support button node.
|
1142 |
+
*
|
1143 |
+
* @param object $wp_admin_bar An object containing the WP Admin bar information.
|
1144 |
+
*
|
1145 |
+
* @return bool If conditions not met, return false.
|
1146 |
+
*/
|
1147 |
+
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
|
1148 |
+
|
1149 |
+
/**
|
1150 |
+
* Filter 'mainwp_branding_role_cap_enable_contact_form'
|
1151 |
+
*
|
1152 |
+
* Manage the support form visibility. Set false to hide the support form page.
|
1153 |
+
*
|
1154 |
+
* @since 4.0
|
1155 |
+
*/
|
1156 |
+
$enable_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
|
1157 |
+
|
1158 |
+
if ( ! $enable_contact && ! current_user_can( 'administrator' ) ) {
|
1159 |
+
return false;
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
if ( isset( $_GET['from_page'] ) ) {
|
1163 |
+
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . ( ! empty( $_GET['from_page'] ) ? rawurlencode( esc_url( wp_unslash( $_GET['from_page'] ) ) ) : '' ) );
|
1164 |
+
} else {
|
1165 |
+
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
1166 |
+
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
1167 |
+
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . rawurlencode( esc_url( $fullurl ) ) );
|
1168 |
+
}
|
1169 |
+
$args = array(
|
1170 |
+
'id' => 999,
|
1171 |
+
'title' => $this->child_branding_options['contact_label'],
|
1172 |
+
'parent' => 'top-secondary',
|
1173 |
+
'href' => $href,
|
1174 |
+
'meta' => array(
|
1175 |
+
'class' => 'mainwp_branding_support_top_bar_button',
|
1176 |
+
'title' => $this->child_branding_options['contact_label'],
|
1177 |
+
),
|
1178 |
+
);
|
1179 |
+
|
1180 |
+
$wp_admin_bar->add_node( $args );
|
1181 |
+
}
|
1182 |
+
|
1183 |
+
/**
|
1184 |
+
* Method is_branding()
|
1185 |
+
*
|
1186 |
+
* Check if the custom branding is enabled.
|
1187 |
+
*
|
1188 |
+
* @return bool If branding enabled, return true, if not, return false.
|
1189 |
+
*/
|
1190 |
+
public function is_branding() {
|
1191 |
+
$opts = $this->child_branding_options;
|
1192 |
+
|
1193 |
+
if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
|
1194 |
+
return false;
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
|
1198 |
+
$cancelled_branding = $opts['cancelled_branding'];
|
1199 |
+
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
|
1200 |
+
|
1201 |
+
if ( $cancelled_branding ) {
|
1202 |
+
return false;
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
if ( 'T' === $is_hide ) {
|
1206 |
+
return true;
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
|
1210 |
+
return true;
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
return false;
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
/**
|
1217 |
+
* Method get_branding_title()
|
1218 |
+
*
|
1219 |
+
* Get custom title for the MainWP Child plugin.
|
1220 |
+
*
|
1221 |
+
* @return mixed If branding enabled, return custom title.
|
1222 |
+
*/
|
1223 |
+
public function get_branding_title() {
|
1224 |
+
if ( $this->is_branding() ) {
|
1225 |
+
$branding_header = $this->child_branding_options['branding_header'];
|
1226 |
+
return $branding_header['name'];
|
1227 |
+
}
|
1228 |
+
return '';
|
1229 |
+
}
|
1230 |
+
|
1231 |
+
/**
|
1232 |
+
* Method get_branding_options()
|
1233 |
+
*
|
1234 |
+
* Get branding options.
|
1235 |
+
*
|
1236 |
+
* @return array An array containing the branding options.
|
1237 |
+
*/
|
1238 |
+
public function get_branding_options() {
|
1239 |
+
return $this->child_branding_options;
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
/**
|
1243 |
+
* Method save_branding_options()
|
1244 |
+
*
|
1245 |
+
* Save branding options.
|
1246 |
+
*
|
1247 |
+
* @param string $name Contains the option name.
|
1248 |
+
* @param string $val Contains the option value.
|
1249 |
+
*
|
1250 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option() Update database option.
|
1251 |
+
*/
|
1252 |
+
public function save_branding_options( $name, $val ) {
|
1253 |
+
$this->child_branding_options[ $name ] = $val;
|
1254 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
/**
|
1258 |
+
* Method branding_map_meta_cap()
|
1259 |
+
*
|
1260 |
+
* Set cutom capabilities to disable theme switching.
|
1261 |
+
*
|
1262 |
+
* @param array $caps An array of capabiilities.
|
1263 |
+
* @param string $cap Contains the capability.
|
1264 |
+
* @param int $user_id Current user ID.
|
1265 |
+
* @param array $args An array of arguments to process.
|
1266 |
+
*
|
1267 |
+
* @return array $caps An array of updated capabiilities.
|
1268 |
+
*/
|
1269 |
+
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
|
1270 |
+
if ( isset( $this->child_branding_options['disable_switching_theme'] ) && 'T' === $this->child_branding_options['disable_switching_theme'] ) {
|
1271 |
+
if ( 'switch_themes' === $cap ) {
|
1272 |
+
$caps[0] = 'do_not_allow';
|
1273 |
+
}
|
1274 |
+
}
|
1275 |
+
return $caps;
|
1276 |
+
}
|
1277 |
+
|
1278 |
+
/**
|
1279 |
+
* Method modify_plugin_header()
|
1280 |
+
*
|
1281 |
+
* Modify plugin header to show custom plugin info.
|
1282 |
+
*
|
1283 |
+
* @param array $plugins An array of installed plugins information.
|
1284 |
+
*
|
1285 |
+
* @return array $plugins Updated array of installed plugins information.
|
1286 |
+
*/
|
1287 |
+
public function modify_plugin_header( $plugins ) {
|
1288 |
+
$opts = $this->child_branding_options;
|
1289 |
+
if ( is_array( $opts ) ) {
|
1290 |
+
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
|
1291 |
+
$cancelled_branding = $opts['cancelled_branding'];
|
1292 |
+
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
|
1293 |
+
|
1294 |
+
if ( $cancelled_branding ) {
|
1295 |
+
return $plugins;
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
if ( 'T' === $is_hide ) {
|
1299 |
+
foreach ( $plugins as $key => $value ) {
|
1300 |
+
$plugin_slug = basename( $key, '.php' );
|
1301 |
+
if ( 'mainwp-child' === $plugin_slug ) {
|
1302 |
+
unset( $plugins[ $key ] );
|
1303 |
+
}
|
1304 |
+
}
|
1305 |
+
return $plugins;
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
|
1309 |
+
return $this->update_plugin_header( $plugins, $branding_header );
|
1310 |
+
} else {
|
1311 |
+
return $plugins;
|
1312 |
+
}
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
return $plugins;
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
/**
|
1319 |
+
* Method hide_update_notice()
|
1320 |
+
*
|
1321 |
+
* Hide the MainWP Child update notice if custom branding is applied.
|
1322 |
+
*
|
1323 |
+
* @param array $slugs An array of slugs of all installed plugins.
|
1324 |
+
*
|
1325 |
+
* @return array $slugs Updated array of slugs of all installed plugins.
|
1326 |
+
*/
|
1327 |
+
public function hide_update_notice( $slugs ) {
|
1328 |
+
$slugs[] = 'mainwp-child/mainwp-child.php';
|
1329 |
+
return $slugs;
|
1330 |
+
}
|
1331 |
+
|
1332 |
+
/**
|
1333 |
+
* Method remove_update_nag()
|
1334 |
+
*
|
1335 |
+
* Hide the MainWP Child update notification on the Updates page.
|
1336 |
+
*
|
1337 |
+
* @param object $value Object containing the updates info.
|
1338 |
+
*
|
1339 |
+
* @return object $value Updated object containing the updates info.
|
1340 |
+
*
|
1341 |
+
* @uses \MainWP\Child\MainWP_Helper::is_updates_screen()
|
1342 |
+
*/
|
1343 |
+
public function remove_update_nag( $value ) {
|
1344 |
+
if ( isset( $_POST['mainwpsignature'] ) ) {
|
1345 |
+
return $value;
|
1346 |
+
}
|
1347 |
+
|
1348 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
1349 |
+
return $value;
|
1350 |
+
}
|
1351 |
+
|
1352 |
+
if ( isset( $value->response['mainwp-child/mainwp-child.php'] ) ) {
|
1353 |
+
unset( $value->response['mainwp-child/mainwp-child.php'] );
|
1354 |
+
}
|
1355 |
+
return $value;
|
1356 |
+
}
|
1357 |
+
|
1358 |
+
|
1359 |
+
/**
|
1360 |
+
* Method update_plugin_header()
|
1361 |
+
*
|
1362 |
+
* Update plugin header to show custom plugin info.
|
1363 |
+
*
|
1364 |
+
* @param array $plugins An array of installed plugins information.
|
1365 |
+
* @param array $header An array containig plugin information.
|
1366 |
+
*
|
1367 |
+
* @return array $plugins Updated array of installed plugins information.
|
1368 |
+
*/
|
1369 |
+
public function update_plugin_header( $plugins, $header ) {
|
1370 |
+
$plugin_key = '';
|
1371 |
+
foreach ( $plugins as $key => $value ) {
|
1372 |
+
$plugin_slug = basename( $key, '.php' );
|
1373 |
+
if ( 'mainwp-child' === $plugin_slug ) {
|
1374 |
+
$plugin_key = $key;
|
1375 |
+
$plugin_data = $value;
|
1376 |
+
}
|
1377 |
+
}
|
1378 |
+
|
1379 |
+
if ( ! empty( $plugin_key ) ) {
|
1380 |
+
$plugin_data['Name'] = stripslashes( $header['name'] );
|
1381 |
+
$plugin_data['Description'] = stripslashes( $header['description'] );
|
1382 |
+
$plugin_data['Author'] = stripslashes( $header['author'] );
|
1383 |
+
$plugin_data['AuthorURI'] = stripslashes( $header['authoruri'] );
|
1384 |
+
if ( ! empty( $header['pluginuri'] ) ) {
|
1385 |
+
$plugin_data['PluginURI'] = stripslashes( $header['pluginuri'] );
|
1386 |
+
}
|
1387 |
+
$plugins[ $plugin_key ] = $plugin_data;
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
return $plugins;
|
1391 |
+
}
|
1392 |
+
}
|
class/class-mainwp-child-bulk-settings-manager.php
CHANGED
@@ -1,310 +1,314 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Bulk Settings Manager
|
4 |
-
*
|
5 |
-
* This file handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Bulk_Settings_Manager
|
14 |
-
*
|
15 |
-
* Handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Bulk_Settings_Manager {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of the class.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
public static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Public statis variable containing the synchronization information.
|
28 |
-
*
|
29 |
-
* @var array Synchronization information.
|
30 |
-
*/
|
31 |
-
public static $information = array();
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Public variable to hold the information about the language domain.
|
35 |
-
*
|
36 |
-
* @var string 'mainwp-child' languge domain.
|
37 |
-
*/
|
38 |
-
public $plugin_translate = 'mainwp-child';
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Create public static instance for MainWP_Child_Bulk_Settings_Manager.
|
42 |
-
*
|
43 |
-
* @return MainWP_Child_Bulk_Settings_Manager|null
|
44 |
-
*/
|
45 |
-
public static function instance() {
|
46 |
-
if ( null === self::$instance ) {
|
47 |
-
self::$instance = new self();
|
48 |
-
}
|
49 |
-
|
50 |
-
return self::$instance;
|
51 |
-
}
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Save Settings & Visit Site as Browser actions.
|
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 |
-
if ( ! isset( $_POST['
|
100 |
-
return array( 'error' => 'Missing
|
101 |
-
}
|
102 |
-
|
103 |
-
$_POST
|
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 |
-
$post_args
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
$get_args
|
153 |
-
}
|
154 |
-
|
155 |
-
$get_args
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
if ( !
|
172 |
-
$temp_post =
|
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 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Bulk Settings Manager
|
4 |
+
*
|
5 |
+
* This file handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Bulk_Settings_Manager
|
14 |
+
*
|
15 |
+
* Handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Bulk_Settings_Manager {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
public static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Public statis variable containing the synchronization information.
|
28 |
+
*
|
29 |
+
* @var array Synchronization information.
|
30 |
+
*/
|
31 |
+
public static $information = array();
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Public variable to hold the information about the language domain.
|
35 |
+
*
|
36 |
+
* @var string 'mainwp-child' languge domain.
|
37 |
+
*/
|
38 |
+
public $plugin_translate = 'mainwp-child';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Create public static instance for MainWP_Child_Bulk_Settings_Manager.
|
42 |
+
*
|
43 |
+
* @return MainWP_Child_Bulk_Settings_Manager|null
|
44 |
+
*/
|
45 |
+
public static function instance() {
|
46 |
+
if ( null === self::$instance ) {
|
47 |
+
self::$instance = new self();
|
48 |
+
}
|
49 |
+
|
50 |
+
return self::$instance;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Save Settings & Visit Site as Browser actions.
|
55 |
+
*
|
56 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
57 |
+
*/
|
58 |
+
public function action() {
|
59 |
+
|
60 |
+
/**
|
61 |
+
* MainWP bulk settings manager fatal error handler.
|
62 |
+
*/
|
63 |
+
function mainwp_bulk_settings_manager_handle_fatal_error() {
|
64 |
+
$error = error_get_last();
|
65 |
+
if ( isset( $error['type'] ) && in_array( $error['type'], array( 1, 4, 16, 64, 256 ) ) && isset( $error['message'] ) ) {
|
66 |
+
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
register_shutdown_function( '\MainWP\Child\mainwp_bulk_settings_manager_handle_fatal_error' );
|
71 |
+
|
72 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
73 |
+
switch ( $mwp_action ) {
|
74 |
+
case 'skeleton_key_visit_site_as_browser': // deprecated.
|
75 |
+
$information = $this->visit_site_as_browser();
|
76 |
+
break;
|
77 |
+
case 'bulk_settings_manager_visit_site_as_browser':
|
78 |
+
$information = $this->visit_site_as_browser();
|
79 |
+
break;
|
80 |
+
case 'save_settings':
|
81 |
+
$information = $this->save_settings();
|
82 |
+
break;
|
83 |
+
default:
|
84 |
+
$information = array( 'error' => 'Unknown action' );
|
85 |
+
}
|
86 |
+
|
87 |
+
MainWP_Helper::write( $information );
|
88 |
+
exit();
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Visit site as a browser.
|
93 |
+
*
|
94 |
+
* @return array|string[] Response array or Error message string within an array.
|
95 |
+
*
|
96 |
+
* @uses \MainWP\Child\MainWP_Helper::get_class_name()
|
97 |
+
*/
|
98 |
+
protected function visit_site_as_browser() { // phpcs:ignore -- ignore complex method notice.
|
99 |
+
if ( ! isset( $_POST['url'] ) || ! is_string( wp_unslash( $_POST['url'] ) ) || strlen( wp_unslash( $_POST['url'] ) ) < 2 ) {
|
100 |
+
return array( 'error' => 'Missing url' );
|
101 |
+
}
|
102 |
+
|
103 |
+
if ( ! isset( $_POST['args'] ) || ! is_array( $_POST['args'] ) ) {
|
104 |
+
return array( 'error' => 'Missing args' );
|
105 |
+
}
|
106 |
+
|
107 |
+
$_POST = stripslashes_deep( wp_unslash( $_POST ) );
|
108 |
+
|
109 |
+
$args = isset( $_POST['args'] ) ? wp_unslash( $_POST['args'] ) : array();
|
110 |
+
|
111 |
+
$current_user = wp_get_current_user();
|
112 |
+
|
113 |
+
$url = isset( $_POST['url'] ) ? '/' . wp_unslash( $_POST['url'] ) : '';
|
114 |
+
|
115 |
+
$expiration = time() + 600;
|
116 |
+
$manager = \WP_Session_Tokens::get_instance( $current_user->ID );
|
117 |
+
$token = $manager->create( $expiration );
|
118 |
+
|
119 |
+
$secure = is_ssl();
|
120 |
+
if ( $secure ) {
|
121 |
+
$auth_cookie_name = SECURE_AUTH_COOKIE;
|
122 |
+
$scheme = 'secure_auth';
|
123 |
+
} else {
|
124 |
+
$auth_cookie_name = AUTH_COOKIE;
|
125 |
+
$scheme = 'auth';
|
126 |
+
}
|
127 |
+
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
|
128 |
+
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
|
129 |
+
$_COOKIE[ $auth_cookie_name ] = $auth_cookie;
|
130 |
+
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
|
131 |
+
$post_args = array();
|
132 |
+
$post_args['body'] = array();
|
133 |
+
$post_args['redirection'] = 5;
|
134 |
+
$post_args['decompress'] = false;
|
135 |
+
$post_args['cookies'] = array(
|
136 |
+
new \WP_Http_Cookie(
|
137 |
+
array(
|
138 |
+
'name' => $auth_cookie_name,
|
139 |
+
'value' => $auth_cookie,
|
140 |
+
)
|
141 |
+
),
|
142 |
+
new \WP_Http_Cookie(
|
143 |
+
array(
|
144 |
+
'name' => LOGGED_IN_COOKIE,
|
145 |
+
'value' => $logged_in_cookie,
|
146 |
+
)
|
147 |
+
),
|
148 |
+
);
|
149 |
+
|
150 |
+
if ( isset( $args['get'] ) ) {
|
151 |
+
$get_args = $args['get'];
|
152 |
+
parse_str( $args['get'], $get_args );
|
153 |
+
}
|
154 |
+
|
155 |
+
if ( ! isset( $get_args ) || ! is_array( $get_args ) ) {
|
156 |
+
$get_args = array();
|
157 |
+
}
|
158 |
+
|
159 |
+
$get_args['bulk_settings_manageruse_nonce_key'] = intval( time() );
|
160 |
+
$get_args['bulk_settings_manageruse_nonce_hmac'] = hash_hmac( 'sha256', $get_args['bulk_settings_manageruse_nonce_key'], NONCE_KEY );
|
161 |
+
|
162 |
+
$good_nonce = null;
|
163 |
+
if ( isset( $args['nonce'] ) && ! empty( $args['nonce'] ) ) {
|
164 |
+
parse_str( $args['nonce'], $temp_nonce );
|
165 |
+
$good_nonce = $this->wp_create_nonce_recursive( $temp_nonce );
|
166 |
+
$get_args = array_merge( $get_args, $good_nonce );
|
167 |
+
}
|
168 |
+
|
169 |
+
if ( isset( $args['post'] ) ) {
|
170 |
+
parse_str( $args['post'], $temp_post );
|
171 |
+
if ( ! isset( $temp_post ) || ! is_array( $temp_post ) ) {
|
172 |
+
$temp_post = array();
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( ! empty( $good_nonce ) ) {
|
176 |
+
$temp_post = array_merge( $temp_post, $good_nonce );
|
177 |
+
}
|
178 |
+
|
179 |
+
$post_args['body'] = $temp_post;
|
180 |
+
}
|
181 |
+
|
182 |
+
$post_args['timeout'] = 25;
|
183 |
+
|
184 |
+
$full_url = add_query_arg( $get_args, get_site_url() . $url );
|
185 |
+
|
186 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
187 |
+
|
188 |
+
$response = wp_remote_post( $full_url, $post_args );
|
189 |
+
|
190 |
+
if ( is_wp_error( $response ) ) {
|
191 |
+
return array( 'error' => 'wp_remote_post error: ' . $response->get_error_message() );
|
192 |
+
}
|
193 |
+
|
194 |
+
$received_content = wp_remote_retrieve_body( $response );
|
195 |
+
|
196 |
+
if ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $received_content, $received_result ) > 0 ) {
|
197 |
+
$received_content_mainwp = json_decode( base64_decode( $received_result[1] ), true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
198 |
+
if ( isset( $received_content_mainwp['error'] ) ) {
|
199 |
+
return array( 'error' => $received_content_mainwp['error'] );
|
200 |
+
}
|
201 |
+
}
|
202 |
+
|
203 |
+
$search_ok_counter = 0;
|
204 |
+
$search_fail_counter = 0;
|
205 |
+
|
206 |
+
if ( isset( $args['search']['ok'] ) ) {
|
207 |
+
foreach ( $args['search']['ok'] as $search ) {
|
208 |
+
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
209 |
+
++ $search_ok_counter;
|
210 |
+
}
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
if ( isset( $args['search']['fail'] ) ) {
|
215 |
+
foreach ( $args['search']['fail'] as $search ) {
|
216 |
+
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
217 |
+
++ $search_fail_counter;
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
unset( $get_args['bulk_settings_manageruse_nonce_key'] );
|
222 |
+
unset( $get_args['bulk_settings_manageruse_nonce_hmac'] );
|
223 |
+
|
224 |
+
return array(
|
225 |
+
'success' => 1,
|
226 |
+
'content' => $received_content,
|
227 |
+
'url' => $full_url,
|
228 |
+
'get' => $get_args,
|
229 |
+
'post' => $post_args['body'],
|
230 |
+
'search_ok_counter' => $search_ok_counter,
|
231 |
+
'search_fail_counter' => $search_fail_counter,
|
232 |
+
);
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Create WP nonce.
|
237 |
+
*
|
238 |
+
* @param array $array An array containing the nonce.
|
239 |
+
*
|
240 |
+
* @return array An array containing the nonce.
|
241 |
+
*/
|
242 |
+
private function wp_create_nonce_recursive( $array ) {
|
243 |
+
foreach ( $array as $key => $value ) {
|
244 |
+
if ( is_array( $array[ $key ] ) ) {
|
245 |
+
$array[ $key ] = $this->wp_create_nonce_recursive( $array[ $key ] );
|
246 |
+
} else {
|
247 |
+
$array[ $key ] = wp_create_nonce( $array[ $key ] );
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
return $array;
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Save site settings.
|
256 |
+
*
|
257 |
+
* @return array|bool|string[] Result array ok|error or FALSE or $whitelist_options[].
|
258 |
+
*/
|
259 |
+
public function save_settings() {
|
260 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
261 |
+
|
262 |
+
if ( ! is_array( $settings ) || empty( $settings ) ) {
|
263 |
+
return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) );
|
264 |
+
}
|
265 |
+
|
266 |
+
$whitelist_options = array(
|
267 |
+
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
|
268 |
+
);
|
269 |
+
|
270 |
+
if ( ! is_multisite() ) {
|
271 |
+
if ( ! defined( 'WP_SITEURL' ) ) {
|
272 |
+
$whitelist_options['general'][] = 'siteurl';
|
273 |
+
}
|
274 |
+
if ( ! defined( 'WP_HOME' ) ) {
|
275 |
+
$whitelist_options['general'][] = 'home';
|
276 |
+
}
|
277 |
+
|
278 |
+
$whitelist_options['general'][] = 'admin_email';
|
279 |
+
$whitelist_options['general'][] = 'users_can_register';
|
280 |
+
$whitelist_options['general'][] = 'default_role';
|
281 |
+
}
|
282 |
+
|
283 |
+
$whitelist_general = $whitelist_options['general'];
|
284 |
+
|
285 |
+
if ( ! empty( $settings['WPLANG'] ) ) {
|
286 |
+
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
287 |
+
if ( wp_can_install_language_pack() ) {
|
288 |
+
$language = wp_download_language_pack( $settings['WPLANG'] );
|
289 |
+
if ( $language ) {
|
290 |
+
$settings['WPLANG'] = $language;
|
291 |
+
}
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
$updated = false;
|
296 |
+
foreach ( $settings as $option => $value ) {
|
297 |
+
if ( in_array( $option, $whitelist_general ) ) {
|
298 |
+
if ( ! is_array( $value ) ) {
|
299 |
+
$value = trim( $value );
|
300 |
+
}
|
301 |
+
$value = wp_unslash( $value );
|
302 |
+
update_option( $option, $value );
|
303 |
+
$updated = true;
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
if ( ! $updated ) {
|
308 |
+
return false;
|
309 |
+
}
|
310 |
+
|
311 |
+
return array( 'result' => 'ok' );
|
312 |
+
}
|
313 |
+
|
314 |
+
}
|
class/class-mainwp-child-callable.php
CHANGED
@@ -1,865 +1,991 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Callable Functions
|
4 |
-
*
|
5 |
-
* Manage functions that can be executed on the child site.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Child_Callable
|
16 |
-
*
|
17 |
-
* Manage functions that can be executed on the child site.
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Callable {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Public static variable to hold the single instance of the class.
|
23 |
-
*
|
24 |
-
* @var mixed Default null
|
25 |
-
*/
|
26 |
-
protected static $instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Private variable to hold the array of all callable functions.
|
30 |
-
*
|
31 |
-
* @var array Callable functions.
|
32 |
-
*/
|
33 |
-
private $callableFunctions = array(
|
34 |
-
'stats' => 'get_site_stats',
|
35 |
-
'upgrade' => 'upgrade_wp',
|
36 |
-
'newpost' => 'new_post',
|
37 |
-
'deactivate' => 'deactivate',
|
38 |
-
'newuser' => 'new_user',
|
39 |
-
'newadminpassword' => 'new_admin_password',
|
40 |
-
'installplugintheme' => 'install_plugin_theme',
|
41 |
-
'upgradeplugintheme' => 'upgrade_plugin_theme',
|
42 |
-
'upgradetranslation' => 'upgrade_translation',
|
43 |
-
'backup' => 'backup',
|
44 |
-
'backup_checkpid' => 'backup_checkpid',
|
45 |
-
'cloneinfo' => 'cloneinfo',
|
46 |
-
'security' => 'get_security_stats',
|
47 |
-
'securityFix' => 'do_security_fix',
|
48 |
-
'securityUnFix' => 'do_security_un_fix',
|
49 |
-
'post_action' => 'post_action',
|
50 |
-
'get_all_posts' => 'get_all_posts',
|
51 |
-
'comment_action' => 'comment_action',
|
52 |
-
'comment_bulk_action' => 'comment_bulk_action',
|
53 |
-
'get_all_comments' => 'get_all_comments',
|
54 |
-
'get_all_themes' => 'get_all_themes',
|
55 |
-
'theme_action' => 'theme_action',
|
56 |
-
'get_all_plugins' => 'get_all_plugins',
|
57 |
-
'plugin_action' => 'plugin_action',
|
58 |
-
'get_all_pages' => 'get_all_pages',
|
59 |
-
'get_all_users' => 'get_all_users',
|
60 |
-
'user_action' => 'user_action',
|
61 |
-
'search_users' => 'search_users',
|
62 |
-
'maintenance_site' => 'maintenance_site',
|
63 |
-
'branding_child_plugin' => 'branding_child_plugin',
|
64 |
-
'code_snippet' => 'code_snippet',
|
65 |
-
'uploader_action' => 'uploader_action',
|
66 |
-
'wordpress_seo' => 'wordpress_seo',
|
67 |
-
'client_report' => 'client_report',
|
68 |
-
'createBackupPoll' => 'backup_poll',
|
69 |
-
'page_speed' => 'page_speed',
|
70 |
-
'woo_com_status' => 'woo_com_status',
|
71 |
-
'links_checker' => 'links_checker',
|
72 |
-
'wordfence' => 'wordfence',
|
73 |
-
'delete_backup' => 'delete_backup',
|
74 |
-
'update_values' => 'update_child_values',
|
75 |
-
'ithemes' => 'ithemes',
|
76 |
-
'updraftplus' => 'updraftplus',
|
77 |
-
'backup_wp' => 'backup_wp',
|
78 |
-
'backwpup' => 'backwpup',
|
79 |
-
'wp_rocket' => 'wp_rocket',
|
80 |
-
'settings_tools' => 'settings_tools',
|
81 |
-
'skeleton_key' => 'bulk_settings_manager', // deprecated.
|
82 |
-
'bulk_settings_manager' => 'bulk_settings_manager',
|
83 |
-
'custom_post_type' => 'custom_post_type',
|
84 |
-
'backup_buddy' => 'backup_buddy',
|
85 |
-
'get_site_icon' => 'get_site_icon',
|
86 |
-
'vulner_checker' => 'vulner_checker',
|
87 |
-
'wp_staging' => 'wp_staging',
|
88 |
-
'disconnect' => 'disconnect',
|
89 |
-
'time_capsule' => 'time_capsule',
|
90 |
-
'extra_excution' => 'extra_execution', // deprecated!
|
91 |
-
'extra_execution' => 'extra_execution',
|
92 |
-
'wpvivid_backuprestore' => 'wpvivid_backuprestore',
|
93 |
-
);
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Private variable to hold the array of all callable functions that don't require regularl authentication.
|
97 |
-
*
|
98 |
-
* @var array Callable functions.
|
99 |
-
*/
|
100 |
-
private $callableFunctionsNoAuth = array(
|
101 |
-
'stats' => 'get_site_stats_no_auth',
|
102 |
-
);
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Method get_class_name()
|
106 |
-
*
|
107 |
-
* Get class name.
|
108 |
-
*
|
109 |
-
* @return string __CLASS__ Class name.
|
110 |
-
*/
|
111 |
-
public static function get_class_name() {
|
112 |
-
return __CLASS__;
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* MainWP_Child_Callable constructor.
|
117 |
-
*
|
118 |
-
* Run any time class is called.
|
119 |
-
*/
|
120 |
-
public function __construct() {
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Method instance()
|
125 |
-
*
|
126 |
-
* Create a public static instance.
|
127 |
-
*
|
128 |
-
* @return mixed Class instance.
|
129 |
-
*/
|
130 |
-
public static function get_instance() {
|
131 |
-
if ( null === self::$instance ) {
|
132 |
-
self::$instance = new self();
|
133 |
-
}
|
134 |
-
return self::$instance;
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Method init_call_functions()
|
139 |
-
*
|
140 |
-
* Initiate callable functions.
|
141 |
-
*
|
142 |
-
* @param bool $auth If true, regular authentication is required.
|
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 |
-
public function
|
323 |
-
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* Method
|
328 |
-
*
|
329 |
-
* Fire off the
|
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 |
-
public function
|
422 |
-
|
423 |
-
}
|
424 |
-
|
425 |
-
/**
|
426 |
-
* Method
|
427 |
-
*
|
428 |
-
* Fire off the
|
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 |
-
public function
|
669 |
-
|
670 |
-
}
|
671 |
-
|
672 |
-
/**
|
673 |
-
* Method
|
674 |
-
*
|
675 |
-
* Fire off the action() function.
|
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 |
-
* Method
|
795 |
-
*
|
796 |
-
*
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
}
|
803 |
-
|
804 |
-
/**
|
805 |
-
* Method
|
806 |
-
*
|
807 |
-
* Fire off the action() function.
|
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 |
-
MainWP_Helper::
|
860 |
-
}
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Callable Functions
|
4 |
+
*
|
5 |
+
* Manage functions that can be executed on the child site.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Callable
|
16 |
+
*
|
17 |
+
* Manage functions that can be executed on the child site.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Callable {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Private variable to hold the array of all callable functions.
|
30 |
+
*
|
31 |
+
* @var array Callable functions.
|
32 |
+
*/
|
33 |
+
private $callableFunctions = array(
|
34 |
+
'stats' => 'get_site_stats',
|
35 |
+
'upgrade' => 'upgrade_wp',
|
36 |
+
'newpost' => 'new_post',
|
37 |
+
'deactivate' => 'deactivate',
|
38 |
+
'newuser' => 'new_user',
|
39 |
+
'newadminpassword' => 'new_admin_password',
|
40 |
+
'installplugintheme' => 'install_plugin_theme',
|
41 |
+
'upgradeplugintheme' => 'upgrade_plugin_theme',
|
42 |
+
'upgradetranslation' => 'upgrade_translation',
|
43 |
+
'backup' => 'backup',
|
44 |
+
'backup_checkpid' => 'backup_checkpid',
|
45 |
+
'cloneinfo' => 'cloneinfo',
|
46 |
+
'security' => 'get_security_stats',
|
47 |
+
'securityFix' => 'do_security_fix',
|
48 |
+
'securityUnFix' => 'do_security_un_fix',
|
49 |
+
'post_action' => 'post_action',
|
50 |
+
'get_all_posts' => 'get_all_posts',
|
51 |
+
'comment_action' => 'comment_action',
|
52 |
+
'comment_bulk_action' => 'comment_bulk_action',
|
53 |
+
'get_all_comments' => 'get_all_comments',
|
54 |
+
'get_all_themes' => 'get_all_themes',
|
55 |
+
'theme_action' => 'theme_action',
|
56 |
+
'get_all_plugins' => 'get_all_plugins',
|
57 |
+
'plugin_action' => 'plugin_action',
|
58 |
+
'get_all_pages' => 'get_all_pages',
|
59 |
+
'get_all_users' => 'get_all_users',
|
60 |
+
'user_action' => 'user_action',
|
61 |
+
'search_users' => 'search_users',
|
62 |
+
'maintenance_site' => 'maintenance_site',
|
63 |
+
'branding_child_plugin' => 'branding_child_plugin',
|
64 |
+
'code_snippet' => 'code_snippet',
|
65 |
+
'uploader_action' => 'uploader_action',
|
66 |
+
'wordpress_seo' => 'wordpress_seo',
|
67 |
+
'client_report' => 'client_report',
|
68 |
+
'createBackupPoll' => 'backup_poll',
|
69 |
+
'page_speed' => 'page_speed',
|
70 |
+
'woo_com_status' => 'woo_com_status',
|
71 |
+
'links_checker' => 'links_checker',
|
72 |
+
'wordfence' => 'wordfence',
|
73 |
+
'delete_backup' => 'delete_backup',
|
74 |
+
'update_values' => 'update_child_values',
|
75 |
+
'ithemes' => 'ithemes',
|
76 |
+
'updraftplus' => 'updraftplus',
|
77 |
+
'backup_wp' => 'backup_wp',
|
78 |
+
'backwpup' => 'backwpup',
|
79 |
+
'wp_rocket' => 'wp_rocket',
|
80 |
+
'settings_tools' => 'settings_tools',
|
81 |
+
'skeleton_key' => 'bulk_settings_manager', // deprecated.
|
82 |
+
'bulk_settings_manager' => 'bulk_settings_manager',
|
83 |
+
'custom_post_type' => 'custom_post_type',
|
84 |
+
'backup_buddy' => 'backup_buddy',
|
85 |
+
'get_site_icon' => 'get_site_icon',
|
86 |
+
'vulner_checker' => 'vulner_checker',
|
87 |
+
'wp_staging' => 'wp_staging',
|
88 |
+
'disconnect' => 'disconnect',
|
89 |
+
'time_capsule' => 'time_capsule',
|
90 |
+
'extra_excution' => 'extra_execution', // deprecated!
|
91 |
+
'extra_execution' => 'extra_execution',
|
92 |
+
'wpvivid_backuprestore' => 'wpvivid_backuprestore',
|
93 |
+
);
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Private variable to hold the array of all callable functions that don't require regularl authentication.
|
97 |
+
*
|
98 |
+
* @var array Callable functions.
|
99 |
+
*/
|
100 |
+
private $callableFunctionsNoAuth = array(
|
101 |
+
'stats' => 'get_site_stats_no_auth',
|
102 |
+
);
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Method get_class_name()
|
106 |
+
*
|
107 |
+
* Get class name.
|
108 |
+
*
|
109 |
+
* @return string __CLASS__ Class name.
|
110 |
+
*/
|
111 |
+
public static function get_class_name() {
|
112 |
+
return __CLASS__;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* MainWP_Child_Callable constructor.
|
117 |
+
*
|
118 |
+
* Run any time class is called.
|
119 |
+
*/
|
120 |
+
public function __construct() {
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Method instance()
|
125 |
+
*
|
126 |
+
* Create a public static instance.
|
127 |
+
*
|
128 |
+
* @return mixed Class instance.
|
129 |
+
*/
|
130 |
+
public static function get_instance() {
|
131 |
+
if ( null === self::$instance ) {
|
132 |
+
self::$instance = new self();
|
133 |
+
}
|
134 |
+
return self::$instance;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Method init_call_functions()
|
139 |
+
*
|
140 |
+
* Initiate callable functions.
|
141 |
+
*
|
142 |
+
* @param bool $auth If true, regular authentication is required.
|
143 |
+
*
|
144 |
+
* @uses \MainWP\Child\MainWP_Helper::error()
|
145 |
+
* @uses \MainWP\Child\MainWP_Utility::handle_fatal_error()
|
146 |
+
* @uses \MainWP\Child\MainWP_Utility::fix_for_custom_themes()
|
147 |
+
*/
|
148 |
+
public function init_call_functions( $auth = false ) {
|
149 |
+
$callable = false;
|
150 |
+
$callable_no_auth = false;
|
151 |
+
$call_func = false;
|
152 |
+
|
153 |
+
// check if function is callable.
|
154 |
+
if ( isset( $_POST['function'] ) ) {
|
155 |
+
$call_func = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : '';
|
156 |
+
$callable = $this->is_callable_function( $call_func ); // check callable func.
|
157 |
+
$callable_no_auth = $this->is_callable_function_no_auth( $call_func ); // check callable no auth func.
|
158 |
+
}
|
159 |
+
|
160 |
+
// Fire off the called function.
|
161 |
+
if ( $auth && isset( $_POST['function'] ) && $callable ) {
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Checks whether cron is in progress.
|
165 |
+
*
|
166 |
+
* @const ( bool ) Default: true
|
167 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
168 |
+
*/
|
169 |
+
define( 'DOING_CRON', true );
|
170 |
+
|
171 |
+
MainWP_Utility::handle_fatal_error();
|
172 |
+
MainWP_Utility::fix_for_custom_themes();
|
173 |
+
$this->call_function( $call_func );
|
174 |
+
} elseif ( isset( $_POST['function'] ) && $callable_no_auth ) {
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Checks whether cron is in progress.
|
178 |
+
*
|
179 |
+
* @const ( bool ) Default: true
|
180 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
181 |
+
*/
|
182 |
+
define( 'DOING_CRON', true );
|
183 |
+
|
184 |
+
MainWP_Utility::fix_for_custom_themes();
|
185 |
+
$this->call_function_no_auth( $call_func );
|
186 |
+
} elseif ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! $callable && ! $callable_no_auth ) {
|
187 |
+
MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Method is_callable_function()
|
193 |
+
*
|
194 |
+
* Check if the function is the list of callable functions.
|
195 |
+
*
|
196 |
+
* @param string $func Contains the name of the function to check.
|
197 |
+
*
|
198 |
+
* @return bool If callable, return true, if not, return false.
|
199 |
+
*/
|
200 |
+
public function is_callable_function( $func ) {
|
201 |
+
if ( isset( $this->callableFunctions[ $func ] ) ) {
|
202 |
+
return true;
|
203 |
+
}
|
204 |
+
return false;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Method is_callable_function_no_auth()
|
209 |
+
*
|
210 |
+
* Check if the function is the list of callable functions that don't require regular authentication.
|
211 |
+
*
|
212 |
+
* @param string $func Contains the name of the function to check.
|
213 |
+
*
|
214 |
+
* @return bool If callable, return true, if not, return false.
|
215 |
+
*/
|
216 |
+
public function is_callable_function_no_auth( $func ) {
|
217 |
+
if ( isset( $this->callableFunctionsNoAuth[ $func ] ) ) {
|
218 |
+
return true;
|
219 |
+
}
|
220 |
+
return false;
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Method call_function()
|
225 |
+
*
|
226 |
+
* Call ceratin function.
|
227 |
+
*
|
228 |
+
* @param string $func Contains the name of the function to call.
|
229 |
+
*/
|
230 |
+
public function call_function( $func ) {
|
231 |
+
if ( $this->is_callable_function( $func ) ) {
|
232 |
+
call_user_func( array( $this, $this->callableFunctions[ $func ] ) );
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Method call_function_no_auth()
|
238 |
+
*
|
239 |
+
* Call ceratin function without regular authentication if the function is in the $callableFunctionsNoAuth list.
|
240 |
+
*
|
241 |
+
* @param string $func Contains the name of the function to call.
|
242 |
+
*/
|
243 |
+
public function call_function_no_auth( $func ) {
|
244 |
+
if ( $this->is_callable_function_no_auth( $func ) ) {
|
245 |
+
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $func ] ) );
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Method get_site_stats()
|
251 |
+
*
|
252 |
+
* Fire off the get_site_stats() function.
|
253 |
+
*
|
254 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
255 |
+
*/
|
256 |
+
public function get_site_stats() {
|
257 |
+
MainWP_Child_Stats::get_instance()->get_site_stats();
|
258 |
+
}
|
259 |
+
|
260 |
+
/**
|
261 |
+
* Method get_site_stats_no_auth()
|
262 |
+
*
|
263 |
+
* Fire off the get_site_stats_no_auth() function.
|
264 |
+
*
|
265 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats_no_auth()
|
266 |
+
*/
|
267 |
+
public function get_site_stats_no_auth() {
|
268 |
+
MainWP_Child_Stats::get_instance()->get_site_stats_no_auth();
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Method install_plugin_theme()
|
273 |
+
*
|
274 |
+
* Fire off the install_plugin_theme() function.
|
275 |
+
*
|
276 |
+
* @uses \MainWP\Child\MainWP_Child_Install::install_plugin_theme()
|
277 |
+
*/
|
278 |
+
public function install_plugin_theme() {
|
279 |
+
MainWP_Child_Install::get_instance()->install_plugin_theme();
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Method upgrade_wp()
|
284 |
+
*
|
285 |
+
* Fire off the upgrade_wp() function.
|
286 |
+
*
|
287 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_wp()
|
288 |
+
*/
|
289 |
+
public function upgrade_wp() {
|
290 |
+
MainWP_Child_Updates::get_instance()->upgrade_wp();
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* Method upgrade_translation()
|
295 |
+
*
|
296 |
+
* Fire off the upgrade_translation() function.
|
297 |
+
*
|
298 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_translation()
|
299 |
+
*/
|
300 |
+
public function upgrade_translation() {
|
301 |
+
MainWP_Child_Updates::get_instance()->upgrade_translation();
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Method upgrade_plugin_theme()
|
306 |
+
*
|
307 |
+
* Fire off the upgrade_plugin_theme() function.
|
308 |
+
*
|
309 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_plugin_theme()
|
310 |
+
*/
|
311 |
+
public function upgrade_plugin_theme() {
|
312 |
+
MainWP_Child_Updates::get_instance()->upgrade_plugin_theme();
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Method theme_action()
|
317 |
+
*
|
318 |
+
* Fire off the theme_action() function.
|
319 |
+
*
|
320 |
+
* @uses \MainWP\Child\MainWP_Child_Install::theme_action()
|
321 |
+
*/
|
322 |
+
public function theme_action() {
|
323 |
+
MainWP_Child_Install::get_instance()->theme_action();
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Method plugin_action()
|
328 |
+
*
|
329 |
+
* Fire off the plugin_action() function.
|
330 |
+
*
|
331 |
+
* @uses \MainWP\Child\MainWP_Child_Install::plugin_action()
|
332 |
+
*/
|
333 |
+
public function plugin_action() {
|
334 |
+
MainWP_Child_Install::get_instance()->plugin_action();
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Method get_all_plugins()
|
339 |
+
*
|
340 |
+
* Fire off the get_all_plugins() function.
|
341 |
+
*
|
342 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins()
|
343 |
+
*/
|
344 |
+
public function get_all_plugins() {
|
345 |
+
MainWP_Child_Stats::get_instance()->get_all_plugins();
|
346 |
+
}
|
347 |
+
|
348 |
+
/**
|
349 |
+
* Method get_all_themes()
|
350 |
+
*
|
351 |
+
* Fire off the get_all_themes() function.
|
352 |
+
*
|
353 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes()
|
354 |
+
*/
|
355 |
+
public function get_all_themes() {
|
356 |
+
MainWP_Child_Stats::get_instance()->get_all_themes();
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Method get_all_users()
|
361 |
+
*
|
362 |
+
* Fire off the get_all_users() function.
|
363 |
+
*
|
364 |
+
* @uses \MainWP\Child\MainWP_Child_Users::get_all_users()
|
365 |
+
*/
|
366 |
+
public function get_all_users() {
|
367 |
+
MainWP_Child_Users::get_instance()->get_all_users();
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Method user_action()
|
372 |
+
*
|
373 |
+
* Fire off the user_action() function.
|
374 |
+
*
|
375 |
+
* @uses \MainWP\Child\MainWP_Child_Users::user_action()
|
376 |
+
*/
|
377 |
+
public function user_action() {
|
378 |
+
MainWP_Child_Users::get_instance()->user_action();
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Method search_users()
|
383 |
+
*
|
384 |
+
* Fire off the search_users() function.
|
385 |
+
*
|
386 |
+
* @uses \MainWP\Child\MainWP_Child_Users::search_users()
|
387 |
+
*/
|
388 |
+
public function search_users() {
|
389 |
+
MainWP_Child_Users::get_instance()->search_users();
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Method get_all_posts()
|
394 |
+
*
|
395 |
+
* Fire off the get_all_posts() function.
|
396 |
+
*
|
397 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts()
|
398 |
+
*/
|
399 |
+
public function get_all_posts() {
|
400 |
+
MainWP_Child_Posts::get_instance()->get_all_posts();
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Method get_all_pages()
|
405 |
+
*
|
406 |
+
* Fire off the get_all_pages() function.
|
407 |
+
*
|
408 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_pages()
|
409 |
+
*/
|
410 |
+
public function get_all_pages() {
|
411 |
+
MainWP_Child_Posts::get_instance()->get_all_pages();
|
412 |
+
}
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Method comment_action()
|
416 |
+
*
|
417 |
+
* Fire off the comment_action() function.
|
418 |
+
*
|
419 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::comment_action()
|
420 |
+
*/
|
421 |
+
public function comment_action() {
|
422 |
+
MainWP_Child_Comments::get_instance()->comment_action();
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Method get_all_comments()
|
427 |
+
*
|
428 |
+
* Fire off the get_all_comments() function.
|
429 |
+
*
|
430 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::get_all_comments()
|
431 |
+
*/
|
432 |
+
public function get_all_comments() {
|
433 |
+
MainWP_Child_Comments::get_instance()->get_all_comments();
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Method comment_bulk_action()
|
438 |
+
*
|
439 |
+
* Fire off the comment_bulk_action() function.
|
440 |
+
*
|
441 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::comment_bulk_action()
|
442 |
+
*/
|
443 |
+
public function comment_bulk_action() {
|
444 |
+
MainWP_Child_Comments::get_instance()->comment_bulk_action();
|
445 |
+
}
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Method maintenance_site()
|
449 |
+
*
|
450 |
+
* Fire off the maintenance_site() function.
|
451 |
+
*
|
452 |
+
* @uses \MainWP\Child\MainWP_Child_Maintenance::maintenance_site()
|
453 |
+
*/
|
454 |
+
public function maintenance_site() {
|
455 |
+
MainWP_Child_Maintenance::get_instance()->maintenance_site();
|
456 |
+
}
|
457 |
+
|
458 |
+
/**
|
459 |
+
* Method new_post()
|
460 |
+
*
|
461 |
+
* Fire off the new_post() function.
|
462 |
+
*
|
463 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::new_post()
|
464 |
+
*/
|
465 |
+
public function new_post() {
|
466 |
+
MainWP_Child_Posts::get_instance()->new_post();
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Method post_action()
|
471 |
+
*
|
472 |
+
* Fire off the post_action() function.
|
473 |
+
*
|
474 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_action()
|
475 |
+
*/
|
476 |
+
public function post_action() {
|
477 |
+
MainWP_Child_Posts::get_instance()->post_action();
|
478 |
+
}
|
479 |
+
|
480 |
+
/**
|
481 |
+
* Method new_admin_password()
|
482 |
+
*
|
483 |
+
* Fire off the new_admin_password() function.
|
484 |
+
*
|
485 |
+
* @uses \MainWP\Child\MainWP_Child_Users::new_admin_password()
|
486 |
+
*/
|
487 |
+
public function new_admin_password() {
|
488 |
+
MainWP_Child_Users::get_instance()->new_admin_password();
|
489 |
+
}
|
490 |
+
|
491 |
+
/**
|
492 |
+
* Method new_user()
|
493 |
+
*
|
494 |
+
* Fire off the new_user() function.
|
495 |
+
*
|
496 |
+
* @uses \MainWP\Child\MainWP_Child_Users::new_user()
|
497 |
+
*/
|
498 |
+
public function new_user() {
|
499 |
+
MainWP_Child_Users::get_instance()->new_user();
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Method cloneinfo()
|
504 |
+
*
|
505 |
+
* Fire off the cloneinfo() function.
|
506 |
+
*
|
507 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
508 |
+
*/
|
509 |
+
public function cloneinfo() {
|
510 |
+
|
511 |
+
/**
|
512 |
+
* WordPress DB Table Prefix.
|
513 |
+
*
|
514 |
+
* @global string
|
515 |
+
*/
|
516 |
+
global $table_prefix;
|
517 |
+
|
518 |
+
$information['dbCharset'] = DB_CHARSET;
|
519 |
+
$information['dbCollate'] = DB_COLLATE;
|
520 |
+
$information['table_prefix'] = $table_prefix;
|
521 |
+
$information['site_url'] = get_option( 'site_url' );
|
522 |
+
$information['home'] = get_option( 'home' );
|
523 |
+
|
524 |
+
MainWP_Helper::write( $information );
|
525 |
+
}
|
526 |
+
|
527 |
+
/**
|
528 |
+
* Method backup_poll()
|
529 |
+
*
|
530 |
+
* Fire off the backup_poll() function.
|
531 |
+
*
|
532 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_poll()
|
533 |
+
*/
|
534 |
+
public function backup_poll() {
|
535 |
+
MainWP_Backup::get()->backup_poll();
|
536 |
+
}
|
537 |
+
|
538 |
+
/**
|
539 |
+
* Method backup_checkpid()
|
540 |
+
*
|
541 |
+
* Fire off the backup_checkpid() function.
|
542 |
+
*
|
543 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_checkpid()
|
544 |
+
*/
|
545 |
+
public function backup_checkpid() {
|
546 |
+
MainWP_Backup::get()->backup_checkpid();
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* Method backup()
|
551 |
+
*
|
552 |
+
* Fire off the backup() function.
|
553 |
+
*
|
554 |
+
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
555 |
+
*
|
556 |
+
* @return array Action result.
|
557 |
+
*
|
558 |
+
* @uses \MainWP\Child\MainWP_Backup::backup()
|
559 |
+
*/
|
560 |
+
public function backup( $write = true ) {
|
561 |
+
return MainWP_Backup::get()->backup( $write );
|
562 |
+
}
|
563 |
+
|
564 |
+
/**
|
565 |
+
* Method backup_full()
|
566 |
+
*
|
567 |
+
* Fire off the backup_full() function.
|
568 |
+
*
|
569 |
+
* @param string $file_name Contains the backup file name.
|
570 |
+
*
|
571 |
+
* @return array Action result.
|
572 |
+
*
|
573 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_full()
|
574 |
+
*/
|
575 |
+
protected function backup_full( $file_name ) {
|
576 |
+
return MainWP_Backup::get()->backup_full( $file_name );
|
577 |
+
}
|
578 |
+
|
579 |
+
/**
|
580 |
+
* Method backup_db()
|
581 |
+
*
|
582 |
+
* Fire off the backup_db() function.
|
583 |
+
*
|
584 |
+
* @param string $file_name Contains the backup file name.
|
585 |
+
* @param string $file_extension Contains the backup file extension.
|
586 |
+
*
|
587 |
+
* @return array Action result.
|
588 |
+
*
|
589 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_db()
|
590 |
+
*/
|
591 |
+
protected function backup_db( $file_name = '', $file_extension = 'zip' ) {
|
592 |
+
return MainWP_Backup::get()->backup_db( $file_name, $file_extension );
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Method get_site_icon()
|
597 |
+
*
|
598 |
+
* Fire off the get_site_icon() function.
|
599 |
+
*
|
600 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::get_site_icon()
|
601 |
+
*/
|
602 |
+
public function get_site_icon() {
|
603 |
+
MainWP_Child_Misc::get_instance()->get_site_icon();
|
604 |
+
}
|
605 |
+
|
606 |
+
/**
|
607 |
+
* Method get_security_stats()
|
608 |
+
*
|
609 |
+
* Fire off the get_security_stats() function.
|
610 |
+
*
|
611 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::get_security_stats()
|
612 |
+
*/
|
613 |
+
public function get_security_stats() {
|
614 |
+
MainWP_Child_Misc::get_instance()->get_security_stats();
|
615 |
+
}
|
616 |
+
|
617 |
+
/**
|
618 |
+
* Method do_security_fix()
|
619 |
+
*
|
620 |
+
* Fire off the do_security_fix() function.
|
621 |
+
*
|
622 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_fix()
|
623 |
+
*/
|
624 |
+
public function do_security_fix() {
|
625 |
+
MainWP_Child_Misc::get_instance()->do_security_fix();
|
626 |
+
}
|
627 |
+
|
628 |
+
/**
|
629 |
+
* Method do_security_un_fix()
|
630 |
+
*
|
631 |
+
* Fire off the do_security_un_fix() function.
|
632 |
+
*
|
633 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
634 |
+
*/
|
635 |
+
public function do_security_un_fix() {
|
636 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
637 |
+
}
|
638 |
+
|
639 |
+
/**
|
640 |
+
* Method settings_tools()
|
641 |
+
*
|
642 |
+
* Fire off the settings_tools() function.
|
643 |
+
*
|
644 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
645 |
+
*/
|
646 |
+
public function settings_tools() {
|
647 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
648 |
+
}
|
649 |
+
|
650 |
+
/**
|
651 |
+
* Method bulk_settings_manager()
|
652 |
+
*
|
653 |
+
* Fire off the action() function.
|
654 |
+
*
|
655 |
+
* @uses \MainWP\Child\MainWP_Child_Bulk_Settings_Manager::action()
|
656 |
+
*/
|
657 |
+
public function bulk_settings_manager() {
|
658 |
+
MainWP_Child_Bulk_Settings_Manager::instance()->action();
|
659 |
+
}
|
660 |
+
|
661 |
+
/**
|
662 |
+
* Method custom_post_type()
|
663 |
+
*
|
664 |
+
* Fire off the action() function.
|
665 |
+
*
|
666 |
+
* @uses \MainWP\Child\MainWP_Custom_Post_Type::action()
|
667 |
+
*/
|
668 |
+
public function custom_post_type() {
|
669 |
+
MainWP_Custom_Post_Type::instance()->action();
|
670 |
+
}
|
671 |
+
|
672 |
+
/**
|
673 |
+
* Method backup_buddy()
|
674 |
+
*
|
675 |
+
* Fire off the action() function.
|
676 |
+
*
|
677 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::action()
|
678 |
+
*/
|
679 |
+
public function backup_buddy() {
|
680 |
+
MainWP_Child_Back_Up_Buddy::instance()->action();
|
681 |
+
}
|
682 |
+
|
683 |
+
/**
|
684 |
+
* Method vulner_checker()
|
685 |
+
*
|
686 |
+
* Fire off the action() function.
|
687 |
+
*
|
688 |
+
* @uses \MainWP\Child\MainWP_Child_Vulnerability_Checker::action()
|
689 |
+
*/
|
690 |
+
public function vulner_checker() {
|
691 |
+
MainWP_Child_Vulnerability_Checker::instance()->action();
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Method time_capsule()
|
696 |
+
*
|
697 |
+
* Fire off the action() function.
|
698 |
+
*
|
699 |
+
* @uses \MainWP\Child\MainWP_Child_Timecapsule::action()
|
700 |
+
*/
|
701 |
+
public function time_capsule() {
|
702 |
+
MainWP_Child_Timecapsule::instance()->action();
|
703 |
+
}
|
704 |
+
|
705 |
+
/**
|
706 |
+
* Method wp_staging()
|
707 |
+
*
|
708 |
+
* Fire off the action() function.
|
709 |
+
*
|
710 |
+
* @uses \MainWP\Child\MainWP_Child_Staging::action()
|
711 |
+
*/
|
712 |
+
public function wp_staging() {
|
713 |
+
MainWP_Child_Staging::instance()->action();
|
714 |
+
}
|
715 |
+
|
716 |
+
/**
|
717 |
+
* Method extra_execution()
|
718 |
+
*
|
719 |
+
* Additional functions to execute.
|
720 |
+
*
|
721 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
722 |
+
*/
|
723 |
+
public function extra_execution() {
|
724 |
+
$post = $_POST;
|
725 |
+
$information = array();
|
726 |
+
/**
|
727 |
+
* Filter 'mainwp_child_extra_execution'
|
728 |
+
*
|
729 |
+
* Additional functions to execute through the filter.
|
730 |
+
*
|
731 |
+
* @param array $information An array containing the synchronization information.
|
732 |
+
* @param mixed $post Contains the POST request.
|
733 |
+
*
|
734 |
+
* @since 4.0
|
735 |
+
*/
|
736 |
+
$information = apply_filters( 'mainwp_child_extra_execution', $information, $post );
|
737 |
+
MainWP_Helper::write( $information );
|
738 |
+
}
|
739 |
+
|
740 |
+
/**
|
741 |
+
* Method uploader_action()
|
742 |
+
*
|
743 |
+
* Fire off the uploader_action() function.
|
744 |
+
*
|
745 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::uploader_action()
|
746 |
+
*/
|
747 |
+
public function uploader_action() {
|
748 |
+
MainWP_Child_Misc::get_instance()->uploader_action();
|
749 |
+
}
|
750 |
+
|
751 |
+
/**
|
752 |
+
* Method wordpress_seo()
|
753 |
+
*
|
754 |
+
* Fire off the action() function.
|
755 |
+
*/
|
756 |
+
public function wordpress_seo() {
|
757 |
+
MainWP_WordPress_SEO::instance()->action();
|
758 |
+
}
|
759 |
+
|
760 |
+
/**
|
761 |
+
* Method client_report()
|
762 |
+
*
|
763 |
+
* Fire off the action() function.
|
764 |
+
*
|
765 |
+
* @uses \MainWP\Child\MainWP_Client_Report::action()
|
766 |
+
*/
|
767 |
+
public function client_report() {
|
768 |
+
MainWP_Client_Report::instance()->action();
|
769 |
+
}
|
770 |
+
|
771 |
+
/**
|
772 |
+
* Method page_speed()
|
773 |
+
*
|
774 |
+
* Fire off the action() function.
|
775 |
+
*
|
776 |
+
* @uses \MainWP\Child\MainWP_Child_Pagespeed::action()
|
777 |
+
*/
|
778 |
+
public function page_speed() {
|
779 |
+
MainWP_Child_Pagespeed::instance()->action();
|
780 |
+
}
|
781 |
+
|
782 |
+
/**
|
783 |
+
* Method woo_com_status()
|
784 |
+
*
|
785 |
+
* Fire off the action() function.
|
786 |
+
*
|
787 |
+
* @uses \MainWP\Child\MainWP_Child_WooCommerce_Status::action()
|
788 |
+
*/
|
789 |
+
public function woo_com_status() {
|
790 |
+
MainWP_Child_WooCommerce_Status::instance()->action();
|
791 |
+
}
|
792 |
+
|
793 |
+
/**
|
794 |
+
* Method links_checker()
|
795 |
+
*
|
796 |
+
* Fire off the action() function.
|
797 |
+
*
|
798 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker::action()
|
799 |
+
*/
|
800 |
+
public function links_checker() {
|
801 |
+
MainWP_Child_Links_Checker::instance()->action();
|
802 |
+
}
|
803 |
+
|
804 |
+
/**
|
805 |
+
* Method wordfence()
|
806 |
+
*
|
807 |
+
* Fire off the action() function.
|
808 |
+
*
|
809 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::action()
|
810 |
+
*/
|
811 |
+
public function wordfence() {
|
812 |
+
MainWP_Child_Wordfence::instance()->action();
|
813 |
+
}
|
814 |
+
|
815 |
+
/**
|
816 |
+
* Method ithemes()
|
817 |
+
*
|
818 |
+
* Fire off the action() function.
|
819 |
+
*
|
820 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::action()
|
821 |
+
*/
|
822 |
+
public function ithemes() {
|
823 |
+
MainWP_Child_IThemes_Security::instance()->action();
|
824 |
+
}
|
825 |
+
|
826 |
+
/**
|
827 |
+
* Method updraftplus()
|
828 |
+
*
|
829 |
+
* Fire off the action() function.
|
830 |
+
*
|
831 |
+
* @uses \MainWP\Child\MainWP_Child_Updraft_Plus_Backups::action()
|
832 |
+
*/
|
833 |
+
public function updraftplus() {
|
834 |
+
MainWP_Child_Updraft_Plus_Backups::instance()->action();
|
835 |
+
}
|
836 |
+
|
837 |
+
/**
|
838 |
+
* Method wpvivid_backuprestore()
|
839 |
+
*
|
840 |
+
* Fire off the action() function.
|
841 |
+
*
|
842 |
+
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::action()
|
843 |
+
*/
|
844 |
+
public function wpvivid_backuprestore() {
|
845 |
+
MainWP_Child_WPvivid_BackupRestore::instance()->action();
|
846 |
+
}
|
847 |
+
|
848 |
+
/**
|
849 |
+
* Method backup_wp()
|
850 |
+
*
|
851 |
+
* Fire off the action() function.
|
852 |
+
*
|
853 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::action()
|
854 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
855 |
+
*/
|
856 |
+
public function backup_wp() {
|
857 |
+
if ( ! version_compare( phpversion(), '5.3', '>=' ) ) {
|
858 |
+
$error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() );
|
859 |
+
MainWP_Helper::write( array( 'error' => $error ) );
|
860 |
+
}
|
861 |
+
MainWP_Child_Back_Up_WordPress::instance()->action();
|
862 |
+
}
|
863 |
+
|
864 |
+
/**
|
865 |
+
* Method wp_rocket()
|
866 |
+
*
|
867 |
+
* Fire off the action() function.
|
868 |
+
*
|
869 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::action()
|
870 |
+
*/
|
871 |
+
public function wp_rocket() {
|
872 |
+
MainWP_Child_WP_Rocket::instance()->action();
|
873 |
+
}
|
874 |
+
|
875 |
+
/**
|
876 |
+
* Method backwpup()
|
877 |
+
*
|
878 |
+
* Fire off the action() function.
|
879 |
+
*
|
880 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::action()
|
881 |
+
*/
|
882 |
+
public function backwpup() {
|
883 |
+
MainWP_Child_Back_WP_Up::instance()->action();
|
884 |
+
}
|
885 |
+
|
886 |
+
/**
|
887 |
+
* Method delete_backup()
|
888 |
+
*
|
889 |
+
* Delete backup.
|
890 |
+
*
|
891 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
892 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
893 |
+
*/
|
894 |
+
public function delete_backup() {
|
895 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
896 |
+
$backupdir = $dirs[0];
|
897 |
+
|
898 |
+
$file = isset( $_REQUEST['del'] ) ? wp_unslash( $_REQUEST['del'] ) : '';
|
899 |
+
|
900 |
+
if ( file_exists( $backupdir . $file ) ) {
|
901 |
+
unlink( $backupdir . $file );
|
902 |
+
}
|
903 |
+
|
904 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
905 |
+
}
|
906 |
+
|
907 |
+
/**
|
908 |
+
* Method update_child_values()
|
909 |
+
*
|
910 |
+
* Update the MainWP Child site options.
|
911 |
+
*
|
912 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
913 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
914 |
+
*/
|
915 |
+
public function update_child_values() {
|
916 |
+
$unique_id = isset( $_POST['uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['uniqueId'] ) ) : '';
|
917 |
+
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $unique_id );
|
918 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
919 |
+
}
|
920 |
+
|
921 |
+
/**
|
922 |
+
* Method branding_child_plugin()
|
923 |
+
*
|
924 |
+
* Fire off the action() function.
|
925 |
+
*
|
926 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::action()
|
927 |
+
*/
|
928 |
+
public function branding_child_plugin() {
|
929 |
+
MainWP_Child_Branding::instance()->action();
|
930 |
+
}
|
931 |
+
|
932 |
+
/**
|
933 |
+
* Method code_snippet()
|
934 |
+
*
|
935 |
+
* Fire off the code_snippet() function.
|
936 |
+
*
|
937 |
+
* @uses MainWP_Child_Misc::code_snippet()
|
938 |
+
*/
|
939 |
+
public function code_snippet() {
|
940 |
+
MainWP_Child_Misc::get_instance()->code_snippet();
|
941 |
+
}
|
942 |
+
|
943 |
+
/**
|
944 |
+
* Method disconnect()
|
945 |
+
*
|
946 |
+
* Disconnect the child site from the current MainWP Dashboard.
|
947 |
+
*
|
948 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
949 |
+
*/
|
950 |
+
public function disconnect() {
|
951 |
+
|
952 |
+
/**
|
953 |
+
* MainWP Child instance.
|
954 |
+
*
|
955 |
+
* @global object
|
956 |
+
*/
|
957 |
+
global $mainWPChild;
|
958 |
+
|
959 |
+
$mainWPChild->deactivation( false );
|
960 |
+
MainWP_Helper::write( array( 'result' => 'success' ) );
|
961 |
+
}
|
962 |
+
|
963 |
+
|
964 |
+
/**
|
965 |
+
* Method deactivate()
|
966 |
+
*
|
967 |
+
* Deactivate the MainWP Child plugin in the site.
|
968 |
+
*
|
969 |
+
* @uses \MainWP\Child\MainWP_Helper::errpr()
|
970 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
971 |
+
*/
|
972 |
+
public function deactivate() {
|
973 |
+
|
974 |
+
/**
|
975 |
+
* MainWP Child instance.
|
976 |
+
*
|
977 |
+
* @global object
|
978 |
+
*/
|
979 |
+
global $mainWPChild;
|
980 |
+
|
981 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
982 |
+
deactivate_plugins( $mainWPChild->plugin_slug, true );
|
983 |
+
$information = array();
|
984 |
+
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
|
985 |
+
MainWP_Helper::error( 'Plugin still active' );
|
986 |
+
}
|
987 |
+
$information['deactivated'] = true;
|
988 |
+
MainWP_Helper::write( $information );
|
989 |
+
}
|
990 |
+
|
991 |
+
}
|
class/class-mainwp-child-comments.php
CHANGED
@@ -1,231 +1,238 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Comments
|
4 |
-
*
|
5 |
-
* This file handles all Child Site comment actions.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Comments
|
14 |
-
*
|
15 |
-
* Handles all Child Site comment actions.
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Comments {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of the class.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
protected static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Comments and clauses.
|
28 |
-
*
|
29 |
-
* @var string Comments and clauses.
|
30 |
-
*/
|
31 |
-
private $comments_and_clauses;
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Get Class Name.
|
35 |
-
*
|
36 |
-
* @return string
|
37 |
-
*/
|
38 |
-
public static function get_class_name() {
|
39 |
-
return __CLASS__;
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* MainWP_Child_Comments constructor.
|
44 |
-
*
|
45 |
-
* Run any time class is called.
|
46 |
-
*/
|
47 |
-
public function __construct() {
|
48 |
-
$this->comments_and_clauses = '';
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Create a public static instance of ainWP_Child_Comments.
|
53 |
-
*
|
54 |
-
* @return MainWP_Child_Comments|null
|
55 |
-
*/
|
56 |
-
public static function get_instance() {
|
57 |
-
if ( null === self::$instance ) {
|
58 |
-
self::$instance = new self();
|
59 |
-
}
|
60 |
-
return self::$instance;
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
} elseif ( '
|
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 |
-
$outComment
|
220 |
-
$outComment['
|
221 |
-
$outComment['
|
222 |
-
$outComment['
|
223 |
-
$outComment['
|
224 |
-
$
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Comments
|
4 |
+
*
|
5 |
+
* This file handles all Child Site comment actions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Comments
|
14 |
+
*
|
15 |
+
* Handles all Child Site comment actions.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Comments {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
protected static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Comments and clauses.
|
28 |
+
*
|
29 |
+
* @var string Comments and clauses.
|
30 |
+
*/
|
31 |
+
private $comments_and_clauses;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Get Class Name.
|
35 |
+
*
|
36 |
+
* @return string
|
37 |
+
*/
|
38 |
+
public static function get_class_name() {
|
39 |
+
return __CLASS__;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* MainWP_Child_Comments constructor.
|
44 |
+
*
|
45 |
+
* Run any time class is called.
|
46 |
+
*/
|
47 |
+
public function __construct() {
|
48 |
+
$this->comments_and_clauses = '';
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Create a public static instance of ainWP_Child_Comments.
|
53 |
+
*
|
54 |
+
* @return MainWP_Child_Comments|null
|
55 |
+
*/
|
56 |
+
public static function get_instance() {
|
57 |
+
if ( null === self::$instance ) {
|
58 |
+
self::$instance = new self();
|
59 |
+
}
|
60 |
+
return self::$instance;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
|
65 |
+
*
|
66 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker::get_class_name()
|
67 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
68 |
+
*/
|
69 |
+
public function comment_action() {
|
70 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
71 |
+
$commentId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
72 |
+
|
73 |
+
if ( 'approve' === $action ) {
|
74 |
+
wp_set_comment_status( $commentId, 'approve' );
|
75 |
+
} elseif ( 'unapprove' === $action ) {
|
76 |
+
wp_set_comment_status( $commentId, 'hold' );
|
77 |
+
} elseif ( 'spam' === $action ) {
|
78 |
+
wp_spam_comment( $commentId );
|
79 |
+
} elseif ( 'unspam' === $action ) {
|
80 |
+
wp_unspam_comment( $commentId );
|
81 |
+
} elseif ( 'trash' === $action ) {
|
82 |
+
add_action( 'trashed_comment', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_trashed_comment' ), 10, 1 );
|
83 |
+
wp_trash_comment( $commentId );
|
84 |
+
} elseif ( 'restore' === $action ) {
|
85 |
+
wp_untrash_comment( $commentId );
|
86 |
+
} elseif ( 'delete' === $action ) {
|
87 |
+
wp_delete_comment( $commentId, true );
|
88 |
+
} else {
|
89 |
+
$information['status'] = 'FAIL';
|
90 |
+
}
|
91 |
+
|
92 |
+
if ( ! isset( $information['status'] ) ) {
|
93 |
+
$information['status'] = 'SUCCESS';
|
94 |
+
}
|
95 |
+
MainWP_Helper::write( $information );
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* MainWP Child Bulk Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
|
100 |
+
*
|
101 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
102 |
+
*/
|
103 |
+
public function comment_bulk_action() {
|
104 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
105 |
+
$commentIds = isset( $_POST['ids'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['ids'] ) ) ) : array();
|
106 |
+
$information['success'] = 0;
|
107 |
+
foreach ( $commentIds as $commentId ) {
|
108 |
+
if ( $commentId ) {
|
109 |
+
$information['success'] ++;
|
110 |
+
if ( 'approve' === $action ) {
|
111 |
+
wp_set_comment_status( $commentId, 'approve' );
|
112 |
+
} elseif ( 'unapprove' === $action ) {
|
113 |
+
wp_set_comment_status( $commentId, 'hold' );
|
114 |
+
} elseif ( 'spam' === $action ) {
|
115 |
+
wp_spam_comment( $commentId );
|
116 |
+
} elseif ( 'unspam' === $action ) {
|
117 |
+
wp_unspam_comment( $commentId );
|
118 |
+
} elseif ( 'trash' === $action ) {
|
119 |
+
wp_trash_comment( $commentId );
|
120 |
+
} elseif ( 'restore' === $action ) {
|
121 |
+
wp_untrash_comment( $commentId );
|
122 |
+
} elseif ( 'delete' === $action ) {
|
123 |
+
wp_delete_comment( $commentId, true );
|
124 |
+
} else {
|
125 |
+
$information['success']--;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
}
|
129 |
+
MainWP_Helper::write( $information );
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Comment WHERE Clauses.
|
134 |
+
*
|
135 |
+
* @param array $clauses MySQL WHERE Clause.
|
136 |
+
*
|
137 |
+
* @return array $clauses, Array of MySQL WHERE Clauses.
|
138 |
+
*/
|
139 |
+
public function comments_clauses( $clauses ) {
|
140 |
+
if ( $this->comments_and_clauses ) {
|
141 |
+
$clauses['where'] .= ' ' . $this->comments_and_clauses;
|
142 |
+
}
|
143 |
+
|
144 |
+
return $clauses;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Get all comments.
|
149 |
+
*
|
150 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
151 |
+
*/
|
152 |
+
public function get_all_comments() {
|
153 |
+
|
154 |
+
/**
|
155 |
+
* WordPress Database instance.
|
156 |
+
*
|
157 |
+
* @global object $wpdb
|
158 |
+
*/
|
159 |
+
global $wpdb;
|
160 |
+
|
161 |
+
add_filter( 'comments_clauses', array( &$this, 'comments_clauses' ) );
|
162 |
+
|
163 |
+
if ( isset( $_POST['postId'] ) ) {
|
164 |
+
$this->comments_and_clauses .= $wpdb->prepare( " AND $wpdb->comments.comment_post_ID = %d ", sanitize_text_field( wp_unslash( $_POST['postId'] ) ) );
|
165 |
+
} else {
|
166 |
+
if ( isset( $_POST['keyword'] ) && '' !== $_POST['keyword'] ) {
|
167 |
+
$this->comments_and_clauses .= $wpdb->prepare( " AND $wpdb->comments.comment_content LIKE %s ", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
168 |
+
}
|
169 |
+
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
|
170 |
+
$this->comments_and_clauses .= $wpdb->prepare( " AND $wpdb->comments.comment_date > %s ", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) ) );
|
171 |
+
}
|
172 |
+
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
|
173 |
+
$this->comments_and_clauses .= $wpdb->prepare( " AND $wpdb->comments.comment_date < %s ", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) ) );
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
$maxComments = 50;
|
178 |
+
if ( defined( 'MAINWP_CHILD_NR_OF_COMMENTS' ) ) {
|
179 |
+
$maxComments = MAINWP_CHILD_NR_OF_COMMENTS; // to compatible.
|
180 |
+
}
|
181 |
+
|
182 |
+
if ( isset( $_POST['maxRecords'] ) ) {
|
183 |
+
$maxComments = ! empty( $_POST['maxRecords'] ) ? intval( $_POST['maxRecords'] ) : 0;
|
184 |
+
}
|
185 |
+
|
186 |
+
if ( 0 === $maxComments ) {
|
187 |
+
$maxComments = 99999;
|
188 |
+
}
|
189 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
190 |
+
$rslt = $this->get_recent_comments( explode( ',', $status ), $maxComments );
|
191 |
+
$this->comments_and_clauses = '';
|
192 |
+
|
193 |
+
MainWP_Helper::write( $rslt );
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Get recent comments.
|
198 |
+
*
|
199 |
+
* @param array $pAllowedStatuses An array containing allowed comment statuses.
|
200 |
+
* @param int $pCount Number of comments to return.
|
201 |
+
*
|
202 |
+
* @return array $allComments Array of all comments found.
|
203 |
+
*/
|
204 |
+
public function get_recent_comments( $pAllowedStatuses, $pCount ) {
|
205 |
+
if ( ! function_exists( '\get_comment_author_url' ) ) {
|
206 |
+
include_once WPINC . '/comment-template.php';
|
207 |
+
}
|
208 |
+
$allComments = array();
|
209 |
+
|
210 |
+
foreach ( $pAllowedStatuses as $status ) {
|
211 |
+
$params = array( 'status' => $status );
|
212 |
+
if ( 0 !== $pCount ) {
|
213 |
+
$params['number'] = $pCount;
|
214 |
+
}
|
215 |
+
$comments = get_comments( $params );
|
216 |
+
if ( is_array( $comments ) ) {
|
217 |
+
foreach ( $comments as $comment ) {
|
218 |
+
$post = get_post( $comment->comment_post_ID );
|
219 |
+
$outComment = array();
|
220 |
+
$outComment['id'] = $comment->comment_ID;
|
221 |
+
$outComment['status'] = wp_get_comment_status( $comment->comment_ID );
|
222 |
+
$outComment['author'] = $comment->comment_author;
|
223 |
+
$outComment['author_url'] = get_comment_author_url( $comment->comment_ID );
|
224 |
+
$outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID );
|
225 |
+
$outComment['author_email'] = apply_filters( 'comment_email', $comment->comment_author_email );
|
226 |
+
$outComment['postId'] = $comment->comment_post_ID;
|
227 |
+
$outComment['postName'] = $post->post_title;
|
228 |
+
$outComment['comment_count'] = $post->comment_count;
|
229 |
+
$outComment['content'] = $comment->comment_content;
|
230 |
+
$outComment['dts'] = strtotime( $comment->comment_date_gmt );
|
231 |
+
$allComments[] = $outComment;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
return $allComments;
|
237 |
+
}
|
238 |
+
}
|
class/class-mainwp-child-db.php
CHANGED
@@ -1,210 +1,210 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child DB
|
4 |
-
*
|
5 |
-
* This file handles all of the Child Plugin's DB functions.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_DB
|
14 |
-
*
|
15 |
-
* Handles all of the Child Plugin's DB functions.
|
16 |
-
*/
|
17 |
-
class MainWP_Child_DB {
|
18 |
-
|
19 |
-
// phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.DB.PreparedSQL.NotPrepared -- unprepared SQL ok, accessing the database directly to custom database functions.
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Support old & new versions of WordPress (3.9+).
|
23 |
-
*
|
24 |
-
* @return bool|object Instantiated object of \mysqli.
|
25 |
-
*/
|
26 |
-
public static function use_mysqli() {
|
27 |
-
if ( ! function_exists( '\mysqli_connect' ) ) {
|
28 |
-
return false;
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* WordPress Database instance.
|
33 |
-
*
|
34 |
-
* @global object $wpdb
|
35 |
-
*/
|
36 |
-
global $wpdb;
|
37 |
-
|
38 |
-
return ( $wpdb->dbh instanceof \mysqli );
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Run a mysqli query & get a result.
|
43 |
-
*
|
44 |
-
* @param string $query An SQL query.
|
45 |
-
* @param string $link A link identifier.
|
46 |
-
*
|
47 |
-
* @return bool|\mysqli_result|resource For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query()
|
48 |
-
* will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
|
49 |
-
* Returns FALSE on failure.
|
50 |
-
*/
|
51 |
-
public static function to_query( $query, $link ) {
|
52 |
-
if ( self::use_mysqli() ) {
|
53 |
-
return \mysqli_query( $link, $query );
|
54 |
-
} else {
|
55 |
-
return \mysql_query( $query, $link );
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Fetch an array.
|
61 |
-
*
|
62 |
-
* @param array $result A result set identifier.
|
63 |
-
*
|
64 |
-
* @return array|false|null Returns an array of strings that corresponds to the fetched row, or false if there are no more rows.
|
65 |
-
*/
|
66 |
-
public static function fetch_array( $result ) {
|
67 |
-
if ( self::use_mysqli() ) {
|
68 |
-
return \mysqli_fetch_array( $result, MYSQLI_ASSOC );
|
69 |
-
} else {
|
70 |
-
return \mysql_fetch_array( $result, MYSQL_ASSOC );
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Count the number of rows.
|
76 |
-
*
|
77 |
-
* @param array $result A result set identifier returned.
|
78 |
-
*
|
79 |
-
* @return false|int Returns number of rows in the result set.
|
80 |
-
*/
|
81 |
-
public static function num_rows( $result ) {
|
82 |
-
if ( self::use_mysqli() ) {
|
83 |
-
return \mysqli_num_rows( $result );
|
84 |
-
} else {
|
85 |
-
return \mysql_num_rows( $result );
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Connect to Child Site Database.
|
91 |
-
*
|
92 |
-
* @param string $host Can be either a host name or an IP address.
|
93 |
-
* @param string $user The MySQL user name.
|
94 |
-
* @param string $pass The MySQL user password.
|
95 |
-
*
|
96 |
-
* @return false|\mysqli|resource object which represents the connection to a MySQL Server or false if an error occurred.
|
97 |
-
*/
|
98 |
-
public static function connect( $host, $user, $pass ) {
|
99 |
-
if ( self::use_mysqli() ) {
|
100 |
-
return \mysqli_connect( $host, $user, $pass );
|
101 |
-
} else {
|
102 |
-
return \mysql_connect( $host, $user, $pass );
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Select Child Site DB.
|
108 |
-
*
|
109 |
-
* @param string $db Database name.
|
110 |
-
*
|
111 |
-
* @return bool true on success or false on failure.
|
112 |
-
*/
|
113 |
-
public static function select_db( $db ) {
|
114 |
-
if ( self::use_mysqli() ) {
|
115 |
-
|
116 |
-
/**
|
117 |
-
* WordPress Database instance.
|
118 |
-
*
|
119 |
-
* @global object $wpdb
|
120 |
-
*/
|
121 |
-
global $wpdb;
|
122 |
-
|
123 |
-
return \mysqli_select_db( $wpdb->dbh, $db );
|
124 |
-
} else {
|
125 |
-
return \mysql_select_db( $db );
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Get any mysqli errors.
|
131 |
-
*
|
132 |
-
* @return string the error text from the last MySQL function, or '' (empty string) if no error occurred.
|
133 |
-
*/
|
134 |
-
public static function error() {
|
135 |
-
if ( self::use_mysqli() ) {
|
136 |
-
|
137 |
-
/**
|
138 |
-
* WordPress Database instance.
|
139 |
-
*
|
140 |
-
* @global object $wpdb
|
141 |
-
*/
|
142 |
-
global $wpdb;
|
143 |
-
|
144 |
-
return \mysqli_error( $wpdb->dbh );
|
145 |
-
} else {
|
146 |
-
return \mysql_error();
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Escape a given string.
|
152 |
-
*
|
153 |
-
* @param string $value The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
|
154 |
-
*
|
155 |
-
* @return false|string the escaped string, or false on error.
|
156 |
-
*/
|
157 |
-
public static function real_escape_string( $value ) {
|
158 |
-
|
159 |
-
/**
|
160 |
-
* WordPress Database instance.
|
161 |
-
*
|
162 |
-
* @global object $wpdb
|
163 |
-
*/
|
164 |
-
global $wpdb;
|
165 |
-
|
166 |
-
if ( self::use_mysqli() ) {
|
167 |
-
return \mysqli_real_escape_string( $wpdb->dbh, $value );
|
168 |
-
} else {
|
169 |
-
return \mysql_real_escape_string( $value, $wpdb->dbh );
|
170 |
-
}
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Check if $result is an Instantiated object of \mysqli.
|
175 |
-
*
|
176 |
-
* @param resource $result Instantiated object of \mysqli.
|
177 |
-
*
|
178 |
-
* @return resource|bool Instantiated object of \mysqli, true if var is a resource, false otherwise.
|
179 |
-
*/
|
180 |
-
public static function is_result( $result ) {
|
181 |
-
if ( self::use_mysqli() ) {
|
182 |
-
return ( $result instanceof mysqli_result );
|
183 |
-
} else {
|
184 |
-
return is_resource( $result );
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Get the size of the DB.
|
190 |
-
*
|
191 |
-
* @return int|mixed Size of the DB or false on failure.
|
192 |
-
*/
|
193 |
-
public static function get_size() {
|
194 |
-
|
195 |
-
/**
|
196 |
-
* WordPress Database instance.
|
197 |
-
*
|
198 |
-
* @global object $wpdb
|
199 |
-
*/
|
200 |
-
global $wpdb;
|
201 |
-
|
202 |
-
$rows = self::to_query( 'SHOW table STATUS', $wpdb->dbh );
|
203 |
-
$size = 0;
|
204 |
-
while ( $row = self::fetch_array( $rows ) ) {
|
205 |
-
$size += $row['Data_length'];
|
206 |
-
}
|
207 |
-
|
208 |
-
return $size;
|
209 |
-
}
|
210 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child DB
|
4 |
+
*
|
5 |
+
* This file handles all of the Child Plugin's DB functions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_DB
|
14 |
+
*
|
15 |
+
* Handles all of the Child Plugin's DB functions.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_DB {
|
18 |
+
|
19 |
+
// phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.DB.PreparedSQL.NotPrepared -- unprepared SQL ok, accessing the database directly to custom database functions.
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Support old & new versions of WordPress (3.9+).
|
23 |
+
*
|
24 |
+
* @return bool|object Instantiated object of \mysqli.
|
25 |
+
*/
|
26 |
+
public static function use_mysqli() {
|
27 |
+
if ( ! function_exists( '\mysqli_connect' ) ) {
|
28 |
+
return false;
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* WordPress Database instance.
|
33 |
+
*
|
34 |
+
* @global object $wpdb
|
35 |
+
*/
|
36 |
+
global $wpdb;
|
37 |
+
|
38 |
+
return ( $wpdb->dbh instanceof \mysqli );
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Run a mysqli query & get a result.
|
43 |
+
*
|
44 |
+
* @param string $query An SQL query.
|
45 |
+
* @param string $link A link identifier.
|
46 |
+
*
|
47 |
+
* @return bool|\mysqli_result|resource For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query()
|
48 |
+
* will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
|
49 |
+
* Returns FALSE on failure.
|
50 |
+
*/
|
51 |
+
public static function to_query( $query, $link ) {
|
52 |
+
if ( self::use_mysqli() ) {
|
53 |
+
return \mysqli_query( $link, $query );
|
54 |
+
} else {
|
55 |
+
return \mysql_query( $query, $link );
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Fetch an array.
|
61 |
+
*
|
62 |
+
* @param array $result A result set identifier.
|
63 |
+
*
|
64 |
+
* @return array|false|null Returns an array of strings that corresponds to the fetched row, or false if there are no more rows.
|
65 |
+
*/
|
66 |
+
public static function fetch_array( $result ) {
|
67 |
+
if ( self::use_mysqli() ) {
|
68 |
+
return \mysqli_fetch_array( $result, MYSQLI_ASSOC );
|
69 |
+
} else {
|
70 |
+
return \mysql_fetch_array( $result, MYSQL_ASSOC );
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Count the number of rows.
|
76 |
+
*
|
77 |
+
* @param array $result A result set identifier returned.
|
78 |
+
*
|
79 |
+
* @return false|int Returns number of rows in the result set.
|
80 |
+
*/
|
81 |
+
public static function num_rows( $result ) {
|
82 |
+
if ( self::use_mysqli() ) {
|
83 |
+
return \mysqli_num_rows( $result );
|
84 |
+
} else {
|
85 |
+
return \mysql_num_rows( $result );
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Connect to Child Site Database.
|
91 |
+
*
|
92 |
+
* @param string $host Can be either a host name or an IP address.
|
93 |
+
* @param string $user The MySQL user name.
|
94 |
+
* @param string $pass The MySQL user password.
|
95 |
+
*
|
96 |
+
* @return false|\mysqli|resource object which represents the connection to a MySQL Server or false if an error occurred.
|
97 |
+
*/
|
98 |
+
public static function connect( $host, $user, $pass ) {
|
99 |
+
if ( self::use_mysqli() ) {
|
100 |
+
return \mysqli_connect( $host, $user, $pass );
|
101 |
+
} else {
|
102 |
+
return \mysql_connect( $host, $user, $pass );
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Select Child Site DB.
|
108 |
+
*
|
109 |
+
* @param string $db Database name.
|
110 |
+
*
|
111 |
+
* @return bool true on success or false on failure.
|
112 |
+
*/
|
113 |
+
public static function select_db( $db ) {
|
114 |
+
if ( self::use_mysqli() ) {
|
115 |
+
|
116 |
+
/**
|
117 |
+
* WordPress Database instance.
|
118 |
+
*
|
119 |
+
* @global object $wpdb
|
120 |
+
*/
|
121 |
+
global $wpdb;
|
122 |
+
|
123 |
+
return \mysqli_select_db( $wpdb->dbh, $db );
|
124 |
+
} else {
|
125 |
+
return \mysql_select_db( $db );
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Get any mysqli errors.
|
131 |
+
*
|
132 |
+
* @return string the error text from the last MySQL function, or '' (empty string) if no error occurred.
|
133 |
+
*/
|
134 |
+
public static function error() {
|
135 |
+
if ( self::use_mysqli() ) {
|
136 |
+
|
137 |
+
/**
|
138 |
+
* WordPress Database instance.
|
139 |
+
*
|
140 |
+
* @global object $wpdb
|
141 |
+
*/
|
142 |
+
global $wpdb;
|
143 |
+
|
144 |
+
return \mysqli_error( $wpdb->dbh );
|
145 |
+
} else {
|
146 |
+
return \mysql_error();
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Escape a given string.
|
152 |
+
*
|
153 |
+
* @param string $value The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
|
154 |
+
*
|
155 |
+
* @return false|string the escaped string, or false on error.
|
156 |
+
*/
|
157 |
+
public static function real_escape_string( $value ) {
|
158 |
+
|
159 |
+
/**
|
160 |
+
* WordPress Database instance.
|
161 |
+
*
|
162 |
+
* @global object $wpdb
|
163 |
+
*/
|
164 |
+
global $wpdb;
|
165 |
+
|
166 |
+
if ( self::use_mysqli() ) {
|
167 |
+
return \mysqli_real_escape_string( $wpdb->dbh, $value );
|
168 |
+
} else {
|
169 |
+
return \mysql_real_escape_string( $value, $wpdb->dbh );
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Check if $result is an Instantiated object of \mysqli.
|
175 |
+
*
|
176 |
+
* @param resource $result Instantiated object of \mysqli.
|
177 |
+
*
|
178 |
+
* @return resource|bool Instantiated object of \mysqli, true if var is a resource, false otherwise.
|
179 |
+
*/
|
180 |
+
public static function is_result( $result ) {
|
181 |
+
if ( self::use_mysqli() ) {
|
182 |
+
return ( $result instanceof mysqli_result );
|
183 |
+
} else {
|
184 |
+
return is_resource( $result );
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Get the size of the DB.
|
190 |
+
*
|
191 |
+
* @return int|mixed Size of the DB or false on failure.
|
192 |
+
*/
|
193 |
+
public static function get_size() {
|
194 |
+
|
195 |
+
/**
|
196 |
+
* WordPress Database instance.
|
197 |
+
*
|
198 |
+
* @global object $wpdb
|
199 |
+
*/
|
200 |
+
global $wpdb;
|
201 |
+
|
202 |
+
$rows = self::to_query( 'SHOW table STATUS', $wpdb->dbh );
|
203 |
+
$size = 0;
|
204 |
+
while ( $row = self::fetch_array( $rows ) ) {
|
205 |
+
$size += $row['Data_length'];
|
206 |
+
}
|
207 |
+
|
208 |
+
return $size;
|
209 |
+
}
|
210 |
+
}
|
class/class-mainwp-child-install.php
CHANGED
@@ -1,485 +1,499 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Install
|
4 |
-
*
|
5 |
-
* This file handles Plugins and Themes Activate, Deactivate and Delete process.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Install
|
14 |
-
*
|
15 |
-
* Handles Plugins and Themes Activate, Deactivate and Delete process.
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Install {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of MainWP_Child_Install.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
protected static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Get class name.
|
28 |
-
*
|
29 |
-
* @return string __CLASS__ Class name.
|
30 |
-
*/
|
31 |
-
public static function get_class_name() {
|
32 |
-
return __CLASS__;
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
* MainWP_Child_Install constructor
|
37 |
-
*
|
38 |
-
* Run any time class is called.
|
39 |
-
*/
|
40 |
-
public function __construct() {
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Create a public static instance of MainWP_Child_Install.
|
45 |
-
*
|
46 |
-
* @return MainWP_Child_Install|mixed|null
|
47 |
-
*/
|
48 |
-
public static function get_instance() {
|
49 |
-
if ( null === self::$instance ) {
|
50 |
-
self::$instance = new self();
|
51 |
-
}
|
52 |
-
|
53 |
-
return self::$instance;
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Method plugin_action()
|
58 |
-
*
|
59 |
-
* Plugin Activate, Deactivate & Delete actions.
|
60 |
-
*
|
61 |
-
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
62 |
-
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
63 |
-
*
|
64 |
-
* @uses activate_plugin() Attempts activation of plugin in a “sandbox” and redirects on success.
|
65 |
-
* @see https://developer.wordpress.org/reference/functions/activate_plugin/
|
66 |
-
*
|
67 |
-
* @uses deactivate_plugin() Deactivate a single plugin or multiple plugins.
|
68 |
-
* @see https://developer.wordpress.org/reference/functions/deactivate_plugin/
|
69 |
-
*
|
70 |
-
* @uses MainWP_Child_Install::delete_plugins() Delete a plugin from the Child Site.
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
*
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
activate_plugin( $plugin );
|
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 |
-
include_once ABSPATH . '/wp-admin/includes/
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
include_once ABSPATH . '/wp-admin/includes/
|
159 |
-
include_once ABSPATH . '/wp-admin/includes/
|
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 |
-
include_once ABSPATH . '/wp-admin/includes/
|
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 |
-
$information['error']['
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Install
|
4 |
+
*
|
5 |
+
* This file handles Plugins and Themes Activate, Deactivate and Delete process.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Install
|
14 |
+
*
|
15 |
+
* Handles Plugins and Themes Activate, Deactivate and Delete process.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Install {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of MainWP_Child_Install.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
protected static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get class name.
|
28 |
+
*
|
29 |
+
* @return string __CLASS__ Class name.
|
30 |
+
*/
|
31 |
+
public static function get_class_name() {
|
32 |
+
return __CLASS__;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* MainWP_Child_Install constructor
|
37 |
+
*
|
38 |
+
* Run any time class is called.
|
39 |
+
*/
|
40 |
+
public function __construct() {
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_Install.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_Install|mixed|null
|
47 |
+
*/
|
48 |
+
public static function get_instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
+
}
|
52 |
+
|
53 |
+
return self::$instance;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Method plugin_action()
|
58 |
+
*
|
59 |
+
* Plugin Activate, Deactivate & Delete actions.
|
60 |
+
*
|
61 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
62 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
63 |
+
*
|
64 |
+
* @uses activate_plugin() Attempts activation of plugin in a “sandbox” and redirects on success.
|
65 |
+
* @see https://developer.wordpress.org/reference/functions/activate_plugin/
|
66 |
+
*
|
67 |
+
* @uses deactivate_plugin() Deactivate a single plugin or multiple plugins.
|
68 |
+
* @see https://developer.wordpress.org/reference/functions/deactivate_plugin/
|
69 |
+
*
|
70 |
+
* @uses \MainWP\Child\MainWP_Child_Install::delete_plugins() Delete a plugin from the Child Site.
|
71 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
72 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
73 |
+
*/
|
74 |
+
public function plugin_action() {
|
75 |
+
|
76 |
+
/**
|
77 |
+
* MainWP Child instance.
|
78 |
+
*
|
79 |
+
* @global object
|
80 |
+
*/
|
81 |
+
global $mainWPChild;
|
82 |
+
|
83 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
84 |
+
$plugins = isset( $_POST['plugin'] ) ? explode( '||', wp_unslash( $_POST['plugin'] ) ) : '';
|
85 |
+
|
86 |
+
if ( 'activate' === $action ) {
|
87 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
88 |
+
|
89 |
+
foreach ( $plugins as $idx => $plugin ) {
|
90 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
91 |
+
$thePlugin = get_plugin_data( $plugin );
|
92 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
93 |
+
if ( 'quotes-collection/quotes-collection.php' == $plugin ) {
|
94 |
+
activate_plugin( $plugin, '', false, true );
|
95 |
+
} else {
|
96 |
+
activate_plugin( $plugin );
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
}
|
101 |
+
} elseif ( 'deactivate' === $action ) {
|
102 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
103 |
+
|
104 |
+
foreach ( $plugins as $idx => $plugin ) {
|
105 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
106 |
+
$thePlugin = get_plugin_data( $plugin );
|
107 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
108 |
+
deactivate_plugins( $plugin );
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
112 |
+
} elseif ( 'delete' === $action ) {
|
113 |
+
$this->delete_plugins( $plugins );
|
114 |
+
} else {
|
115 |
+
$information['status'] = 'FAIL';
|
116 |
+
}
|
117 |
+
|
118 |
+
if ( ! isset( $information['status'] ) ) {
|
119 |
+
$information['status'] = 'SUCCESS';
|
120 |
+
}
|
121 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
122 |
+
MainWP_Helper::write( $information );
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Method delete_plugins()
|
127 |
+
*
|
128 |
+
* Delete a plugin from the Child Site.
|
129 |
+
*
|
130 |
+
* @param array $plugins An array of plugins to delete.
|
131 |
+
*
|
132 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
133 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
134 |
+
*
|
135 |
+
* @uses deactivate_plugin() Deactivate a single plugin or multiple plugins.
|
136 |
+
* @see https://developer.wordpress.org/reference/functions/deactivate_plugin/
|
137 |
+
*
|
138 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
139 |
+
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
|
140 |
+
*
|
141 |
+
* @uses \MainWP\Child\MainWP_Helper::check_wp_filesystem()
|
142 |
+
*
|
143 |
+
* @used-by \MainWP\Child\MainWP_Child_Install::plugin_action() Plugin Activate, Deactivate & Delete actions.
|
144 |
+
*/
|
145 |
+
private function delete_plugins( $plugins ) {
|
146 |
+
|
147 |
+
/**
|
148 |
+
* MainWP Child instance.
|
149 |
+
*
|
150 |
+
* @global object
|
151 |
+
*/
|
152 |
+
global $mainWPChild;
|
153 |
+
|
154 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
155 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
156 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
157 |
+
}
|
158 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
159 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
160 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
161 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
162 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
|
163 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
|
164 |
+
|
165 |
+
MainWP_Helper::check_wp_filesystem();
|
166 |
+
|
167 |
+
$pluginUpgrader = new \Plugin_Upgrader();
|
168 |
+
|
169 |
+
$all_plugins = get_plugins();
|
170 |
+
foreach ( $plugins as $idx => $plugin ) {
|
171 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
172 |
+
if ( isset( $all_plugins[ $plugin ] ) ) {
|
173 |
+
if ( is_plugin_active( $plugin ) ) {
|
174 |
+
$thePlugin = get_plugin_data( $plugin );
|
175 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
176 |
+
deactivate_plugins( $plugin );
|
177 |
+
}
|
178 |
+
}
|
179 |
+
$tmp['plugin'] = $plugin;
|
180 |
+
if ( true === $pluginUpgrader->delete_old_plugin( null, null, null, $tmp ) ) {
|
181 |
+
$args = array(
|
182 |
+
'action' => 'delete',
|
183 |
+
'Name' => $all_plugins[ $plugin ]['Name'],
|
184 |
+
);
|
185 |
+
do_action( 'mainwp_child_plugin_action', $args );
|
186 |
+
}
|
187 |
+
}
|
188 |
+
}
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Method theme_action()
|
194 |
+
*
|
195 |
+
* Theme Activate, Deactivate & Delete actions.
|
196 |
+
*
|
197 |
+
* @uses wp_get_theme() Gets a WP_Theme object for a theme.
|
198 |
+
* @see https://developer.wordpress.org/reference/functions/wp_get_theme/
|
199 |
+
*
|
200 |
+
* @uses switch_theme() Switches the theme.
|
201 |
+
* @see https://developer.wordpress.org/reference/functions/switch_theme/
|
202 |
+
*
|
203 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
204 |
+
* @uses \MainWP\Child\MainWP_Helper::check_wp_filesystem()
|
205 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
206 |
+
*/
|
207 |
+
public function theme_action() {
|
208 |
+
|
209 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
210 |
+
$theme = isset( $_POST['theme'] ) ? wp_unslash( $_POST['theme'] ) : '';
|
211 |
+
|
212 |
+
if ( 'activate' === $action ) {
|
213 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
214 |
+
$theTheme = wp_get_theme( $theme );
|
215 |
+
if ( null !== $theTheme && '' !== $theTheme ) {
|
216 |
+
switch_theme( $theTheme['Template'], $theTheme['Stylesheet'] );
|
217 |
+
}
|
218 |
+
} elseif ( 'delete' === $action ) {
|
219 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
220 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
221 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
222 |
+
}
|
223 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
224 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
225 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
226 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
227 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
|
228 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
|
229 |
+
|
230 |
+
MainWP_Helper::check_wp_filesystem();
|
231 |
+
|
232 |
+
$themeUpgrader = new \Theme_Upgrader();
|
233 |
+
|
234 |
+
$theme_name = wp_get_theme()->get_stylesheet();
|
235 |
+
$parent = wp_get_theme()->parent();
|
236 |
+
$parent_name = $parent ? $parent->get_stylesheet() : '';
|
237 |
+
|
238 |
+
$themes = explode( '||', $theme );
|
239 |
+
|
240 |
+
$themes = array_filter( $themes );
|
241 |
+
|
242 |
+
if ( count( $themes ) == 1 ) {
|
243 |
+
$themeToDelete = current( $themes );
|
244 |
+
if ( $themeToDelete == $theme_name ) {
|
245 |
+
$information['error']['is_activated_theme'] = $themeToDelete;
|
246 |
+
MainWP_Helper::write( $information );
|
247 |
+
return;
|
248 |
+
} elseif ( $themeToDelete == $parent_name ) {
|
249 |
+
$information['error']['is_activated_parent'] = $themeToDelete;
|
250 |
+
MainWP_Helper::write( $information );
|
251 |
+
return;
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
foreach ( $themes as $idx => $themeToDelete ) {
|
256 |
+
if ( $themeToDelete == $theme_name ) {
|
257 |
+
$information['error']['is_activated_theme'] = $themeToDelete;
|
258 |
+
} elseif ( $themeToDelete == $parent_name ) {
|
259 |
+
$information['error']['is_activated_parent'] = $themeToDelete;
|
260 |
+
}
|
261 |
+
if ( $themeToDelete !== $theme_name && $themeToDelete !== $parent_name ) {
|
262 |
+
$theTheme = wp_get_theme( $themeToDelete );
|
263 |
+
if ( null !== $theTheme && '' !== $theTheme ) {
|
264 |
+
$tmp['theme'] = $theTheme['Template'];
|
265 |
+
if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) {
|
266 |
+
$args = array(
|
267 |
+
'action' => 'delete',
|
268 |
+
'Name' => $theTheme['Name'],
|
269 |
+
);
|
270 |
+
do_action( 'mainwp_child_theme_action', $args );
|
271 |
+
}
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
} else {
|
276 |
+
$information['status'] = 'FAIL';
|
277 |
+
}
|
278 |
+
|
279 |
+
if ( ! isset( $information['status'] ) ) {
|
280 |
+
$information['status'] = 'SUCCESS';
|
281 |
+
}
|
282 |
+
|
283 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
284 |
+
MainWP_Helper::write( $information );
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Method install_plugin_theme()
|
289 |
+
*
|
290 |
+
* Plugin & Theme Installation functions.
|
291 |
+
*
|
292 |
+
* @uses \MainWP\Child\MainWP_Child_Install::require_files() Include necessary files.
|
293 |
+
* @uses \MainWP\Child\MainWP_Child_Install::after_installed() After plugin or theme has been installed.
|
294 |
+
* @uses \MainWP\Child\MainWP_Child_Install::no_ssl_filter_function() Hook to set ssl verify value.
|
295 |
+
* @uses \MainWP\Child\MainWP_Child_Install::try_second_install() Alternative installation method.
|
296 |
+
* @uses \MainWP\Child\MainWP_Helper::check_wp_filesystem()
|
297 |
+
* @uses \MainWP\Child\MainWP_Helper::error()
|
298 |
+
* @uses \MainWP\Child\MainWP_Helper::get_class_name()
|
299 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
300 |
+
*/
|
301 |
+
public function install_plugin_theme() {
|
302 |
+
|
303 |
+
MainWP_Helper::check_wp_filesystem();
|
304 |
+
|
305 |
+
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['url'] ) || ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) || '' === $_POST['url'] ) {
|
306 |
+
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
307 |
+
}
|
308 |
+
|
309 |
+
$this->require_files();
|
310 |
+
|
311 |
+
$urlgot = isset( $_POST['url'] ) ? json_decode( stripslashes( wp_unslash( $_POST['url'] ) ) ) : '';
|
312 |
+
|
313 |
+
$urls = array();
|
314 |
+
if ( ! is_array( $urlgot ) ) {
|
315 |
+
$urls[] = $urlgot;
|
316 |
+
} else {
|
317 |
+
$urls = $urlgot;
|
318 |
+
}
|
319 |
+
|
320 |
+
$install_results = array();
|
321 |
+
$result = array();
|
322 |
+
foreach ( $urls as $url ) {
|
323 |
+
$installer = new \WP_Upgrader();
|
324 |
+
$ssl_verify = true;
|
325 |
+
// @see wp-admin/includes/class-wp-upgrader.php
|
326 |
+
if ( isset( $_POST['sslVerify'] ) && '0' === $_POST['sslVerify'] ) {
|
327 |
+
add_filter( 'http_request_args', array( self::get_class_name(), 'no_ssl_filter_function' ), 99, 2 );
|
328 |
+
$ssl_verify = false;
|
329 |
+
}
|
330 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
331 |
+
|
332 |
+
$result = $installer->run(
|
333 |
+
array(
|
334 |
+
'package' => $url,
|
335 |
+
'destination' => ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
336 |
+
'clear_destination' => ( isset( $_POST['overwrite'] ) && sanitize_text_field( wp_unslash( $_POST['overwrite'] ) ) ),
|
337 |
+
'clear_working' => true,
|
338 |
+
'hook_extra' => array(),
|
339 |
+
)
|
340 |
+
);
|
341 |
+
|
342 |
+
if ( is_wp_error( $result ) ) {
|
343 |
+
if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) {
|
344 |
+
$ssl_verify = false;
|
345 |
+
$result = $this->try_second_install( $url, $installer );
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
350 |
+
if ( false == $ssl_verify ) {
|
351 |
+
remove_filter( 'http_request_args', array( self::get_class_name(), 'no_ssl_filter_function' ), 99 );
|
352 |
+
}
|
353 |
+
$this->after_installed( $result );
|
354 |
+
$basename = basename( rawurldecode( $url ) );
|
355 |
+
$install_results[ $basename ] = is_array( $result ) && isset( $result['destination_name'] ) ? true : false;
|
356 |
+
}
|
357 |
+
|
358 |
+
$information['installation'] = 'SUCCESS';
|
359 |
+
$information['destination_name'] = $result['destination_name'];
|
360 |
+
$information['install_results'] = $install_results;
|
361 |
+
MainWP_Helper::write( $information );
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Method no_ssl_filter_function()
|
366 |
+
*
|
367 |
+
* Hook to set ssl verify value.
|
368 |
+
*
|
369 |
+
* @param array $r Request's array values.
|
370 |
+
* @param string $url URL request.
|
371 |
+
*
|
372 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
373 |
+
*
|
374 |
+
* @return array $r Request's array values.
|
375 |
+
*/
|
376 |
+
public static function no_ssl_filter_function( $r, $url ) {
|
377 |
+
$r['sslverify'] = false;
|
378 |
+
return $r;
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Method require_files()
|
383 |
+
*
|
384 |
+
* Include necessary files.
|
385 |
+
*
|
386 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
387 |
+
*/
|
388 |
+
private function require_files() {
|
389 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
390 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
391 |
+
}
|
392 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
393 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
394 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
395 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Method after_installed()
|
400 |
+
*
|
401 |
+
* After plugin or theme has been installed.
|
402 |
+
*
|
403 |
+
* @param array $result Results array from self::install_plugin_theme().
|
404 |
+
*
|
405 |
+
* @uses wp_cache_set() Saves the data to the cache.
|
406 |
+
* @see https://developer.wordpress.org/reference/functions/wp_cache_set/
|
407 |
+
*
|
408 |
+
* @uses activate_plugin() Attempts activation of plugin in a “sandbox” and redirects on success.
|
409 |
+
* @see https://developer.wordpress.org/reference/functions/activate_plugin/
|
410 |
+
*
|
411 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
412 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
413 |
+
*
|
414 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
415 |
+
*/
|
416 |
+
private function after_installed( $result ) {
|
417 |
+
$args = array(
|
418 |
+
'success' => 1,
|
419 |
+
'action' => 'install',
|
420 |
+
);
|
421 |
+
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
422 |
+
$path = $result['destination'];
|
423 |
+
$fileName = '';
|
424 |
+
wp_cache_set( 'plugins', array(), 'plugins' );
|
425 |
+
foreach ( $result['source_files'] as $srcFile ) {
|
426 |
+
if ( is_dir( $path . $srcFile ) ) {
|
427 |
+
continue;
|
428 |
+
}
|
429 |
+
$thePlugin = get_plugin_data( $path . $srcFile );
|
430 |
+
if ( null !== $thePlugin && '' !== $thePlugin && '' !== $thePlugin['Name'] ) {
|
431 |
+
$args['type'] = 'plugin';
|
432 |
+
$args['Name'] = $thePlugin['Name'];
|
433 |
+
$args['Version'] = $thePlugin['Version'];
|
434 |
+
$args['slug'] = $result['destination_name'] . '/' . $srcFile;
|
435 |
+
$fileName = $srcFile;
|
436 |
+
break;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
if ( ! empty( $fileName ) ) {
|
441 |
+
do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' );
|
442 |
+
do_action( 'mainwp_child_install_plugin_theme', $args );
|
443 |
+
|
444 |
+
if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) {
|
445 |
+
// to fix activate issue.
|
446 |
+
if ( 'quotes-collection/quotes-collection.php' == $args['slug'] ) {
|
447 |
+
activate_plugin( $path . $fileName, '', false, true );
|
448 |
+
} else {
|
449 |
+
activate_plugin( $path . $fileName, '' );
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
453 |
+
} else {
|
454 |
+
$args['type'] = 'theme';
|
455 |
+
$args['slug'] = $result['destination_name'];
|
456 |
+
do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' );
|
457 |
+
do_action( 'mainwp_child_install_plugin_theme', $args );
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Method try_second_install()
|
463 |
+
*
|
464 |
+
* Alternative installation method.
|
465 |
+
*
|
466 |
+
* @return object $result Return error messages or TRUE.
|
467 |
+
*
|
468 |
+
* @param string $url Package URL.
|
469 |
+
* @param object $installer Instance of \WP_Upgrader.
|
470 |
+
*
|
471 |
+
* @uses is_wp_error() Check whether variable is a WordPress Error.
|
472 |
+
* @see https://developer.wordpress.org/reference/functions/is_wp_error/
|
473 |
+
*
|
474 |
+
* @uses \MainWP\Child\MainWP_Helper::error()
|
475 |
+
*
|
476 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
477 |
+
*/
|
478 |
+
private function try_second_install( $url, $installer ) {
|
479 |
+
$result = $installer->run(
|
480 |
+
array(
|
481 |
+
'package' => $url,
|
482 |
+
'destination' => ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
483 |
+
'clear_destination' => ( isset( $_POST['overwrite'] ) && sanitize_text_field( wp_unslash( $_POST['overwrite'] ) ) ),
|
484 |
+
'clear_working' => true,
|
485 |
+
'hook_extra' => array(),
|
486 |
+
)
|
487 |
+
);
|
488 |
+
if ( is_wp_error( $result ) ) {
|
489 |
+
$err_code = $result->get_error_code();
|
490 |
+
if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) {
|
491 |
+
$error = $result->get_error_data();
|
492 |
+
MainWP_Helper::error( $error, $err_code );
|
493 |
+
} else {
|
494 |
+
MainWP_Helper::error( implode( ', ', $error ), $err_code );
|
495 |
+
}
|
496 |
+
}
|
497 |
+
return $result;
|
498 |
+
}
|
499 |
+
}
|
class/class-mainwp-child-ithemes-security.php
CHANGED
@@ -1,1591 +1,1591 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Ithemes Security
|
4 |
-
*
|
5 |
-
* MainWP iThemes Security Extension handler.
|
6 |
-
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
7 |
-
*
|
8 |
-
* @package MainWP\Child
|
9 |
-
*
|
10 |
-
* Credits
|
11 |
-
*
|
12 |
-
* Plugin-Name: iThemes Security
|
13 |
-
* Plugin URI: https://ithemes.com/security
|
14 |
-
* Author: iThemes
|
15 |
-
* Author URI: https://ithemes.com
|
16 |
-
* License: GPLv2
|
17 |
-
*
|
18 |
-
* The code is used for the MainWP iThemes Security Extension
|
19 |
-
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
20 |
-
*/
|
21 |
-
|
22 |
-
namespace MainWP\Child;
|
23 |
-
|
24 |
-
// phpcs:disable -- third party credit code.
|
25 |
-
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Class MainWP_Child_IThemes_Security
|
29 |
-
*/
|
30 |
-
class MainWP_Child_IThemes_Security {
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Public static variable to hold the single instance of MainWP_Child_IThemes_Security.
|
34 |
-
* @var null
|
35 |
-
*/
|
36 |
-
public static $instance = null;
|
37 |
-
|
38 |
-
/**
|
39 |
-
* @var bool Whether or not iThemes Plugin is installed or not. Default: false.
|
40 |
-
*/
|
41 |
-
public $is_plugin_installed = false;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Create a public static instance of MainWP_Child_IThemes_Security.
|
45 |
-
*
|
46 |
-
* @return MainWP_Child_IThemes_Security|null
|
47 |
-
*/
|
48 |
-
public static function instance() {
|
49 |
-
if ( null === self::$instance ) {
|
50 |
-
self::$instance = new self();
|
51 |
-
}
|
52 |
-
return self::$instance;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* MainWP_Child_IThemes_Security constructor.
|
57 |
-
*
|
58 |
-
* Run any time class is called.
|
59 |
-
*
|
60 |
-
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
61 |
-
*/
|
62 |
-
public function __construct() {
|
63 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
64 |
-
if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
|
65 |
-
$this->is_plugin_installed = true;
|
66 |
-
}
|
67 |
-
|
68 |
-
if ( ! $this->is_plugin_installed ) {
|
69 |
-
return;
|
70 |
-
}
|
71 |
-
|
72 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Sync other data from $data[] and merge with $information[]
|
77 |
-
*
|
78 |
-
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
79 |
-
* @param array $data Other data to sync to $information array.
|
80 |
-
* @return array $information Returned information array with both sets of data.
|
81 |
-
*/
|
82 |
-
public function sync_others_data( $information, $data = array() ) {
|
83 |
-
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
84 |
-
try {
|
85 |
-
$information['syncIThemeData'] = array(
|
86 |
-
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
87 |
-
);
|
88 |
-
} catch ( \Exception $e ) {
|
89 |
-
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
|
90 |
-
}
|
91 |
-
}
|
92 |
-
return $information;
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* MainWP iThemes Security Extension actions.
|
97 |
-
*
|
98 |
-
* @uses MainWP_Child_IThemes_Security::set_showhide()
|
99 |
-
* @uses MainWP_Child_IThemes_Security::save_settings()
|
100 |
-
* @uses MainWP_Child_IThemes_Security::whitelist_release()
|
101 |
-
* @uses MainWP_Child_IThemes_Security::backup_db()
|
102 |
-
* @uses MainWP_Child_IThemes_Security::admin_user()
|
103 |
-
* @uses MainWP_Child_IThemes_Security::change_database_prefix()
|
104 |
-
* @uses MainWP_Child_IThemes_Security::reset_api_key()
|
105 |
-
* @uses MainWP_Child_IThemes_Security::malware_scan()
|
106 |
-
* @uses MainWP_Child_IThemes_Security::>purge_logs()
|
107 |
-
* @uses MainWP_Child_IThemes_Security::file_change()
|
108 |
-
* @uses MainWP_Child_IThemes_Security::release_lockout()
|
109 |
-
* @uses MainWP_Child_IThemes_Security::update_module_status()
|
110 |
-
* @uses MainWP_Child_IThemes_Security::wordpress_salts()
|
111 |
-
* @uses MainWP_Child_IThemes_Security::file_permissions()
|
112 |
-
* @uses MainWP_Child_IThemes_Security::reload_backup_exclude()
|
113 |
-
* @uses MainWP_Child_IThemes_Security::security_site()
|
114 |
-
* @uses MainWP_Child_IThemes_Security::activate_network_brute_force()
|
115 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
116 |
-
*/
|
117 |
-
public function action() {
|
118 |
-
$information = array();
|
119 |
-
if ( ! class_exists( '\ITSEC_Core' ) || ! class_exists( '\ITSEC_Modules' ) ) {
|
120 |
-
$information['error'] = 'NO_ITHEME';
|
121 |
-
MainWP_Helper::write( $information );
|
122 |
-
}
|
123 |
-
|
124 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
125 |
-
global $mainwp_itsec_modules_path;
|
126 |
-
|
127 |
-
$mainwp_itsec_modules_path = \ITSEC_Core::get_core_dir() . '/modules/';
|
128 |
-
|
129 |
-
if ( isset( $_POST['mwp_action'] ) ) {
|
130 |
-
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
131 |
-
switch ( $mwp_action ) {
|
132 |
-
case 'set_showhide':
|
133 |
-
$information = $this->set_showhide();
|
134 |
-
break;
|
135 |
-
case 'save_settings':
|
136 |
-
$information = $this->save_settings();
|
137 |
-
break;
|
138 |
-
case 'whitelist_release':
|
139 |
-
$information = $this->whitelist_release();
|
140 |
-
break;
|
141 |
-
case 'backup_db':
|
142 |
-
$information = $this->backup_db();
|
143 |
-
break;
|
144 |
-
case 'admin_user':
|
145 |
-
$information = $this->admin_user();
|
146 |
-
break;
|
147 |
-
case 'database_prefix':
|
148 |
-
$information = $this->change_database_prefix();
|
149 |
-
break;
|
150 |
-
case 'reset_api_key':
|
151 |
-
$information = $this->reset_api_key();
|
152 |
-
break;
|
153 |
-
case 'malware_scan':
|
154 |
-
$information = $this->malware_scan();
|
155 |
-
break;
|
156 |
-
case 'clear_all_logs':
|
157 |
-
$information = $this->purge_logs();
|
158 |
-
break;
|
159 |
-
case 'file_change':
|
160 |
-
$information = $this->file_change();
|
161 |
-
break;
|
162 |
-
case 'release_lockout':
|
163 |
-
$information = $this->release_lockout();
|
164 |
-
break;
|
165 |
-
case 'module_status':
|
166 |
-
$information = $this->update_module_status();
|
167 |
-
break;
|
168 |
-
case 'wordpress_salts':
|
169 |
-
$information = $this->wordpress_salts();
|
170 |
-
break;
|
171 |
-
case 'file_permissions':
|
172 |
-
$information = $this->file_permissions();
|
173 |
-
break;
|
174 |
-
case 'reload_backup_exclude':
|
175 |
-
$information = $this->reload_backup_exclude();
|
176 |
-
break;
|
177 |
-
case 'security_site':
|
178 |
-
$information = $this->security_site();
|
179 |
-
break;
|
180 |
-
case 'activate_network_brute_force':
|
181 |
-
$information = $this->activate_network_brute_force();
|
182 |
-
break;
|
183 |
-
}
|
184 |
-
}
|
185 |
-
MainWP_Helper::write( $information );
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Set show or hide UpdraftPlus Plugin from Admin & plugins list.
|
190 |
-
*
|
191 |
-
* @return array $information Return results.
|
192 |
-
*
|
193 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
194 |
-
*/
|
195 |
-
public function set_showhide() {
|
196 |
-
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
197 |
-
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
198 |
-
$information['result'] = 'success';
|
199 |
-
|
200 |
-
return $information;
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Initiate iThemes settings.
|
205 |
-
*
|
206 |
-
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
207 |
-
*/
|
208 |
-
public function ithemes_init() {
|
209 |
-
if ( ! $this->is_plugin_installed ) {
|
210 |
-
return;
|
211 |
-
}
|
212 |
-
|
213 |
-
if ( 'hide' === get_option( 'mainwp_ithemes_hide_plugin' ) ) {
|
214 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
215 |
-
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
216 |
-
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
217 |
-
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
218 |
-
if ( isset( $_GET['page'] ) && ( 'itsec' == $_GET['page'] || 'itsec-security-check' == $_GET['page'] ) ) {
|
219 |
-
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
220 |
-
exit();
|
221 |
-
}
|
222 |
-
}
|
223 |
-
}
|
224 |
-
|
225 |
-
/**
|
226 |
-
* iThemes Security Admin initiation.
|
227 |
-
*/
|
228 |
-
public function admin_init() {
|
229 |
-
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Remove iThemes Security from plugins page.
|
234 |
-
*
|
235 |
-
* @param array $plugins All plugins array.
|
236 |
-
*
|
237 |
-
* @return array $plugins All plugins array with iThemes Security removed.
|
238 |
-
*/
|
239 |
-
public function all_plugins( $plugins ) {
|
240 |
-
foreach ( $plugins as $key => $value ) {
|
241 |
-
$plugin_slug = basename( $key, '.php' );
|
242 |
-
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
243 |
-
unset( $plugins[ $key ] );
|
244 |
-
}
|
245 |
-
}
|
246 |
-
|
247 |
-
return $plugins;
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Remove iThemes Security plugin from WP Admin menu.
|
252 |
-
*/
|
253 |
-
public function remove_menu() {
|
254 |
-
remove_menu_page( 'itsec' );
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* Custom admin CSS.
|
259 |
-
*/
|
260 |
-
public function custom_admin_css() {
|
261 |
-
?>
|
262 |
-
<style type="text/css">
|
263 |
-
#wp-admin-bar-itsec_admin_bar_menu{
|
264 |
-
display: none !important;
|
265 |
-
}
|
266 |
-
</style>
|
267 |
-
<?php
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Save UpdraftPlus settings.
|
272 |
-
*
|
273 |
-
* @return array[] $return Return Error message or Success Message.
|
274 |
-
*
|
275 |
-
* @uses \ITSEC_Lib::get_server()
|
276 |
-
* @uses \ITSEC_Lib::get_ssl_support_probability()
|
277 |
-
* @uses \ITSEC_Lib_Config_File::get_server_config()
|
278 |
-
* @uses \ITSEC_Lib_Config_File::get_wp_config()
|
279 |
-
* @uses \ITSEC_Modules::get_default()
|
280 |
-
* @uses \ITSEC_Modules::get_setting()
|
281 |
-
* @uses MainWP_Child_IThemes_Security::get_lockouts()
|
282 |
-
* @uses MainWP_Child_IThemes_Security::validate_directory()
|
283 |
-
* @uses MainWP_Child_IThemes_Security::activate_api_key()
|
284 |
-
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
285 |
-
* @uses MainWP_Child_IThemes_Security::get_available_admin_users_and_roles()
|
286 |
-
*/
|
287 |
-
public function save_settings() {
|
288 |
-
|
289 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
290 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
291 |
-
}
|
292 |
-
|
293 |
-
$_itsec_modules = array(
|
294 |
-
'global',
|
295 |
-
'away-mode',
|
296 |
-
'backup',
|
297 |
-
'hide-backend',
|
298 |
-
'ipcheck',
|
299 |
-
'ban-users',
|
300 |
-
'brute-force',
|
301 |
-
'file-change',
|
302 |
-
'404-detection',
|
303 |
-
'network-brute-force',
|
304 |
-
'ssl',
|
305 |
-
'password-requirements',
|
306 |
-
'system-tweaks',
|
307 |
-
'wordpress-tweaks',
|
308 |
-
'multisite-tweaks',
|
309 |
-
'notification-center',
|
310 |
-
);
|
311 |
-
|
312 |
-
$require_permalinks = false;
|
313 |
-
$updated = false;
|
314 |
-
$errors = array();
|
315 |
-
$nbf_settings = array();
|
316 |
-
|
317 |
-
$update_settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
318 |
-
|
319 |
-
foreach ( $update_settings as $module => $settings ) {
|
320 |
-
$do_not_save = false;
|
321 |
-
if ( in_array( $module, $_itsec_modules ) ) {
|
322 |
-
if ( 'wordpress-salts' == $module ) {
|
323 |
-
$settings['last_generated'] = \ITSEC_Modules::get_setting( $module, 'last_generated' );
|
324 |
-
} elseif ( 'global' == $module ) {
|
325 |
-
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file' );
|
326 |
-
foreach ( $keep_olds as $key ) {
|
327 |
-
$settings[ $key ] = \ITSEC_Modules::get_setting( $module, $key );
|
328 |
-
}
|
329 |
-
|
330 |
-
if ( ! isset( $settings['log_location'] ) || empty( $settings['log_location'] ) ) {
|
331 |
-
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
332 |
-
} else {
|
333 |
-
$result = $this->validate_directory( 'log_location', $settings['log_location'] );
|
334 |
-
if ( true !== $result ) {
|
335 |
-
$errors[] = $result;
|
336 |
-
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
337 |
-
}
|
338 |
-
}
|
339 |
-
} elseif ( 'backup' == $module ) {
|
340 |
-
if ( ! isset( $settings['location'] ) || empty( $settings['location'] ) ) {
|
341 |
-
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
342 |
-
} else {
|
343 |
-
$result = $this->validate_directory( 'location', $settings['location'] );
|
344 |
-
if ( true !== $result ) {
|
345 |
-
$errors[] = $result;
|
346 |
-
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
347 |
-
}
|
348 |
-
}
|
349 |
-
if ( ! isset( $settings['exclude'] ) ) {
|
350 |
-
$settings['exclude'] = \ITSEC_Modules::get_setting( $module, 'exclude' );
|
351 |
-
|
352 |
-
}
|
353 |
-
} elseif ( 'hide-backend' == $module ) {
|
354 |
-
if ( isset( $settings['enabled'] ) && ! empty( $settings['enabled'] ) ) {
|
355 |
-
$permalink_structure = get_option( 'permalink_structure', false );
|
356 |
-
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
357 |
-
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'mainwp-child' );
|
358 |
-
$require_permalinks = true;
|
359 |
-
$do_not_save = true;
|
360 |
-
}
|
361 |
-
}
|
362 |
-
} elseif ( 'network-brute-force' == $module ) {
|
363 |
-
|
364 |
-
if ( isset( $settings['email'] ) ) {
|
365 |
-
$result = $this->activate_api_key( $settings );
|
366 |
-
if ( false === $result ) {
|
367 |
-
$nbf_settings = $settings;
|
368 |
-
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
369 |
-
} else {
|
370 |
-
$nbf_settings = $result;
|
371 |
-
}
|
372 |
-
} else {
|
373 |
-
$previous_settings = \ITSEC_Modules::get_settings( $module );
|
374 |
-
if ( isset( $settings['enable_ban'] ) ) {
|
375 |
-
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
376 |
-
$nbf_settings = $previous_settings;
|
377 |
-
} else {
|
378 |
-
$do_not_save = true;
|
379 |
-
$nbf_settings = $previous_settings;
|
380 |
-
}
|
381 |
-
}
|
382 |
-
$settings = $nbf_settings;
|
383 |
-
} elseif ( 'notification-center' == $module ) {
|
384 |
-
$current_settings = \ITSEC_Modules::get_settings( $module );
|
385 |
-
if ( isset( $settings['notifications'] ) ) {
|
386 |
-
$update_fields = array( 'schedule', 'enabled', 'subject' );
|
387 |
-
if ( isset( $_POST['is_individual'] ) && $_POST['is_individual'] ) {
|
388 |
-
$update_fields = array_merge( $update_fields, array( 'user_list', 'email_list' ) );
|
389 |
-
}
|
390 |
-
foreach ( $settings['notifications'] as $key => $val ) {
|
391 |
-
foreach ( $update_fields as $field ) {
|
392 |
-
if ( isset( $val[ $field ] ) ) {
|
393 |
-
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
|
394 |
-
}
|
395 |
-
}
|
396 |
-
}
|
397 |
-
$updated = true;
|
398 |
-
\ITSEC_Modules::set_settings( $module, $current_settings );
|
399 |
-
}
|
400 |
-
continue;
|
401 |
-
}
|
402 |
-
|
403 |
-
if ( ! $do_not_save ) {
|
404 |
-
\ITSEC_Modules::set_settings( $module, $settings );
|
405 |
-
$updated = true;
|
406 |
-
}
|
407 |
-
}
|
408 |
-
}
|
409 |
-
|
410 |
-
if ( isset( $update_settings['itsec_active_modules'] ) ) {
|
411 |
-
$current_val = get_site_option( 'itsec_active_modules', array() );
|
412 |
-
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) {
|
413 |
-
$current_val[ $mod ] = $val;
|
414 |
-
}
|
415 |
-
update_site_option( 'itsec_active_modules', $current_val );
|
416 |
-
}
|
417 |
-
|
418 |
-
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
419 |
-
|
420 |
-
$values = array(
|
421 |
-
'permalink_structure' => get_option( 'permalink_structure' ),
|
422 |
-
'is_multisite' => is_multisite() ? 1 : 0,
|
423 |
-
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
424 |
-
'server_nginx' => ( \ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
425 |
-
'has_ssl' => \ITSEC_Lib::get_ssl_support_probability(),
|
426 |
-
'jquery_version' => \ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
|
427 |
-
'server_rules' => \ITSEC_Lib_Config_File::get_server_config(),
|
428 |
-
'config_rules' => \ITSEC_Lib_Config_File::get_wp_config(),
|
429 |
-
'lockouts_host' => $this->get_lockouts( 'host', true ),
|
430 |
-
'lockouts_user' => $this->get_lockouts( 'user', true ),
|
431 |
-
'lockouts_username' => $this->get_lockouts( 'username', true ),
|
432 |
-
'default_log_location' => \ITSEC_Modules::get_default( 'global', 'log_location' ),
|
433 |
-
'default_location' => \ITSEC_Modules::get_default( 'backup', 'location' ),
|
434 |
-
'excludable_tables' => $this->get_excludable_tables(),
|
435 |
-
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
436 |
-
);
|
437 |
-
|
438 |
-
$return = array(
|
439 |
-
'site_status' => $values,
|
440 |
-
);
|
441 |
-
|
442 |
-
if ( $require_permalinks ) {
|
443 |
-
$return['require_permalinks'] = 1;
|
444 |
-
}
|
445 |
-
|
446 |
-
$return['nbf_settings'] = $nbf_settings;
|
447 |
-
|
448 |
-
if ( ! empty( $errors ) ) {
|
449 |
-
$return['extra_message'] = $errors;
|
450 |
-
}
|
451 |
-
|
452 |
-
if ( $updated ) {
|
453 |
-
$return['result'] = 'success';
|
454 |
-
} else {
|
455 |
-
$return['error'] = __( 'Not Updated', 'mainwp-child' );
|
456 |
-
}
|
457 |
-
|
458 |
-
return $return;
|
459 |
-
}
|
460 |
-
|
461 |
-
/**
|
462 |
-
* Activate network brute force.
|
463 |
-
*
|
464 |
-
* @return array $information Results array.
|
465 |
-
*
|
466 |
-
* @uses \ITSEC_Modules::get_settings()
|
467 |
-
* @uses \ITSEC_Modules::activate()
|
468 |
-
*/
|
469 |
-
public static function activate_network_brute_force() {
|
470 |
-
$data = isset( $_POST['data'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
471 |
-
$information = array();
|
472 |
-
if ( is_array( $data ) ) {
|
473 |
-
$settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
474 |
-
$settings['email'] = $data['email'];
|
475 |
-
$settings['updates_optin'] = $data['updates_optin'];
|
476 |
-
$settings['api_nag'] = false;
|
477 |
-
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $settings );
|
478 |
-
if ( is_wp_error( $results ) ) {
|
479 |
-
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
480 |
-
} elseif ( $results['saved'] ) {
|
481 |
-
\ITSEC_Modules::activate( 'network-brute-force' );
|
482 |
-
$nbf_settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
483 |
-
}
|
484 |
-
}
|
485 |
-
if ( null !== $nbf_settings ) {
|
486 |
-
$information['nbf_settings'] = $nbf_settings;
|
487 |
-
$information['result'] = 'success';
|
488 |
-
}
|
489 |
-
return $information;
|
490 |
-
}
|
491 |
-
|
492 |
-
/**
|
493 |
-
* Validate directory.
|
494 |
-
*
|
495 |
-
* @param string $name Input name.
|
496 |
-
* @param string $folder Folder.
|
497 |
-
*
|
498 |
-
* @return bool|string Return TRUE on success or Error message on failure.
|
499 |
-
*
|
500 |
-
* @uses \ITSEC_Lib_Directory::is_dir()
|
501 |
-
* @uses \ITSEC_Lib_Directory::create()
|
502 |
-
* @uses \ITSEC_Lib_Directory::is_writable()
|
503 |
-
* @uses \ITSEC_Lib_Directory::add_file_listing_protection()
|
504 |
-
*/
|
505 |
-
private function validate_directory( $name, $folder ) {
|
506 |
-
require_once \ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
|
507 |
-
$error = null;
|
508 |
-
if ( ! \ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
509 |
-
$result = \ITSEC_Lib_Directory::create( $folder );
|
510 |
-
|
511 |
-
if ( is_wp_error( $result ) ) {
|
512 |
-
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', 'mainwp-child' ), $name, $result->get_error_message() );
|
513 |
-
}
|
514 |
-
}
|
515 |
-
|
516 |
-
if ( empty( $error ) && ! \ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
517 |
-
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', 'mainwp-child' ), $name );
|
518 |
-
}
|
519 |
-
|
520 |
-
if ( empty( $error ) ) {
|
521 |
-
\ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
522 |
-
return true;
|
523 |
-
} else {
|
524 |
-
return $error;
|
525 |
-
}
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Activate api key.
|
530 |
-
*
|
531 |
-
* @param array $settings Setting array.
|
532 |
-
*
|
533 |
-
* @return array|bool Return $settings array or FALSE on failure.
|
534 |
-
*
|
535 |
-
* @uses \ITSEC_Network_Brute_Force_Utilities::get_api_key()
|
536 |
-
* @uses \ITSEC_Network_Brute_Force_Utilities::activate_api_key()
|
537 |
-
* @uses \ITSEC_Response::reload_module()
|
538 |
-
*/
|
539 |
-
private function activate_api_key( $settings ) {
|
540 |
-
|
541 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
542 |
-
global $mainwp_itsec_modules_path;
|
543 |
-
|
544 |
-
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
|
545 |
-
|
546 |
-
$key = \ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
|
547 |
-
if ( is_wp_error( $key ) ) {
|
548 |
-
return false;
|
549 |
-
} else {
|
550 |
-
$secret = \ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
551 |
-
|
552 |
-
if ( is_wp_error( $secret ) ) {
|
553 |
-
return false;
|
554 |
-
} else {
|
555 |
-
$settings['api_key'] = $key;
|
556 |
-
$settings['api_secret'] = $secret;
|
557 |
-
|
558 |
-
$settings['api_nag'] = false;
|
559 |
-
|
560 |
-
\ITSEC_Response::reload_module( 'network-brute-force' );
|
561 |
-
}
|
562 |
-
}
|
563 |
-
unset( $settings['email'] );
|
564 |
-
return $settings;
|
565 |
-
}
|
566 |
-
|
567 |
-
/**
|
568 |
-
* Backup status.
|
569 |
-
*
|
570 |
-
* @return int $status 1, 2, 3 or 4
|
571 |
-
* (1) Is not a multisite installation, backupbuddy_api exists & Scheduled backups are >=1
|
572 |
-
* (2) Is not multisite and backupbuddy_api exists
|
573 |
-
* (3) Has backup = true & schedualed backup = true
|
574 |
-
* (4) Has backup = true.
|
575 |
-
*
|
576 |
-
* @uses \backupbuddy_api::getSchedules()
|
577 |
-
* @uses MainWP_Child_IThemes_Security::has_backup()
|
578 |
-
* @uses MainWP_Child_IThemes_Security::scheduled_backup()
|
579 |
-
* @uses MainWP_Child_IThemes_Security::has_backup()
|
580 |
-
*
|
581 |
-
*/
|
582 |
-
public function backup_status() {
|
583 |
-
$status = 0;
|
584 |
-
if ( ! is_multisite() && class_exists( '\backupbuddy_api' ) && count( \backupbuddy_api::getSchedules() ) >= 1 ) {
|
585 |
-
$status = 1;
|
586 |
-
} elseif ( ! is_multisite() && class_exists( '\backupbuddy_api' ) ) {
|
587 |
-
$status = 2;
|
588 |
-
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
589 |
-
$status = 3;
|
590 |
-
} elseif ( $this->has_backup() === true ) {
|
591 |
-
$status = 4;
|
592 |
-
}
|
593 |
-
|
594 |
-
return $status;
|
595 |
-
}
|
596 |
-
|
597 |
-
/**
|
598 |
-
* Check if backup exists.
|
599 |
-
*
|
600 |
-
* @return bool TRUE|FALSE
|
601 |
-
*/
|
602 |
-
public function has_backup() {
|
603 |
-
$has_backup = false;
|
604 |
-
|
605 |
-
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
606 |
-
}
|
607 |
-
|
608 |
-
/**
|
609 |
-
* Check if there is a shedualed backup.
|
610 |
-
*
|
611 |
-
* @return bool TRUE|FALSE.
|
612 |
-
*/
|
613 |
-
public function scheduled_backup() {
|
614 |
-
$sceduled_backup = false;
|
615 |
-
|
616 |
-
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
617 |
-
}
|
618 |
-
|
619 |
-
/**
|
620 |
-
* Whitelist Dashboard IP address.
|
621 |
-
*
|
622 |
-
* @return array|string[] Response array.
|
623 |
-
*/
|
624 |
-
public function whitelist() {
|
625 |
-
|
626 |
-
/** @global array $itsec_globals itsec globals. */
|
627 |
-
global $itsec_globals;
|
628 |
-
|
629 |
-
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
|
630 |
-
$add_temp = false;
|
631 |
-
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
632 |
-
if ( false !== $temp_ip ) {
|
633 |
-
if ( ( $temp_ip['exp'] < $itsec_globals['current_time'] ) || ( $temp_ip['exp'] !== $ip ) ) {
|
634 |
-
delete_site_option( 'itsec_temp_whitelist_ip' );
|
635 |
-
$add_temp = true;
|
636 |
-
}
|
637 |
-
} else {
|
638 |
-
$add_temp = true;
|
639 |
-
}
|
640 |
-
|
641 |
-
if ( false === $add_temp ) {
|
642 |
-
return array( 'error' => 'Not Updated' );
|
643 |
-
} else {
|
644 |
-
$response = array(
|
645 |
-
'ip' => $ip,
|
646 |
-
'exp' => $itsec_globals['current_time'] + 86400,
|
647 |
-
);
|
648 |
-
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
649 |
-
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
650 |
-
$response['message1'] = __( 'Your IP Address', 'mainwp-child' );
|
651 |
-
$response['message2'] = __( 'is whitelisted for', 'mainwp-child' );
|
652 |
-
|
653 |
-
return $response;
|
654 |
-
}
|
655 |
-
}
|
656 |
-
|
657 |
-
/**
|
658 |
-
* Whitelist release.
|
659 |
-
*
|
660 |
-
* @return string Return 'Success'.
|
661 |
-
*/
|
662 |
-
public function whitelist_release() {
|
663 |
-
delete_site_option( 'itsec_temp_whitelist_ip' );
|
664 |
-
|
665 |
-
return 'success';
|
666 |
-
}
|
667 |
-
|
668 |
-
/**
|
669 |
-
* Backup Database.
|
670 |
-
*
|
671 |
-
* @return array $return Return results array.
|
672 |
-
*
|
673 |
-
* @uses \ITSEC_Backup()
|
674 |
-
* @uses \ITSEC_Backup::run()
|
675 |
-
* @uses \ITSEC_Backup::do_backup()
|
676 |
-
* @uses \ITSEC_Response::get_error_strings()
|
677 |
-
*/
|
678 |
-
public function backup_db() {
|
679 |
-
|
680 |
-
/**
|
681 |
-
* @global string $mainwp_itsec_modules_path MainWP itsec modules path.
|
682 |
-
* @global object $itsec_backup ITsec backup class.
|
683 |
-
*/
|
684 |
-
global $itsec_backup, $mainwp_itsec_modules_path;
|
685 |
-
|
686 |
-
if ( ! isset( $itsec_backup ) ) {
|
687 |
-
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
|
688 |
-
$itsec_backup = new \ITSEC_Backup();
|
689 |
-
$itsec_backup->run();
|
690 |
-
}
|
691 |
-
|
692 |
-
$return = array();
|
693 |
-
|
694 |
-
$str_error = '';
|
695 |
-
$result = $itsec_backup->do_backup( true );
|
696 |
-
|
697 |
-
if ( is_wp_error( $result ) ) {
|
698 |
-
$errors = \ITSEC_Response::get_error_strings( $result );
|
699 |
-
|
700 |
-
foreach ( $errors as $error ) {
|
701 |
-
$str_error .= $error . '<br />';
|
702 |
-
}
|
703 |
-
} elseif ( is_string( $result ) ) {
|
704 |
-
$return['result'] = 'success';
|
705 |
-
$return['message'] = $result;
|
706 |
-
} else {
|
707 |
-
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'mainwp-child' ), gettype( $result ) );
|
708 |
-
}
|
709 |
-
|
710 |
-
if ( ! empty( $str_error ) ) {
|
711 |
-
$return['error'] = $str_error;
|
712 |
-
}
|
713 |
-
|
714 |
-
return $return;
|
715 |
-
}
|
716 |
-
|
717 |
-
|
718 |
-
/**
|
719 |
-
* Update WordPress Salts.
|
720 |
-
*
|
721 |
-
* @return array $return Return results array.
|
722 |
-
*
|
723 |
-
* @uses \ITSEC_WordPress_Salts_Utilities::generate_new_salts()
|
724 |
-
* @uses \ITSEC_Response::get_error_strings()
|
725 |
-
* @uses \ITSEC_Core::get_current_time_gmt()
|
726 |
-
* @uses \ITSEC_Modules::set_setting()
|
727 |
-
*/
|
728 |
-
private function wordpress_salts() {
|
729 |
-
|
730 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
731 |
-
global $mainwp_itsec_modules_path;
|
732 |
-
|
733 |
-
if ( ! class_exists( '\ITSEC_WordPress_Salts_Utilities' ) ) {
|
734 |
-
require $mainwp_itsec_modules_path . 'salts/utilities.php';
|
735 |
-
}
|
736 |
-
$result = \ITSEC_WordPress_Salts_Utilities::generate_new_salts();
|
737 |
-
$str_error = '';
|
738 |
-
if ( is_wp_error( $result ) ) {
|
739 |
-
$errors = \ITSEC_Response::get_error_strings( $result );
|
740 |
-
|
741 |
-
foreach ( $errors as $error ) {
|
742 |
-
$str_error .= $error . '<br />';
|
743 |
-
}
|
744 |
-
} else {
|
745 |
-
$return['result'] = 'success';
|
746 |
-
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'mainwp-child' );
|
747 |
-
$last_generated = \ITSEC_Core::get_current_time_gmt();
|
748 |
-
\ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
749 |
-
}
|
750 |
-
if ( ! empty( $str_error ) ) {
|
751 |
-
$return['error'] = $str_error;
|
752 |
-
}
|
753 |
-
return $return;
|
754 |
-
}
|
755 |
-
|
756 |
-
/**
|
757 |
-
* Update file permissions.
|
758 |
-
*
|
759 |
-
* @return array Return results table html.
|
760 |
-
*
|
761 |
-
* @uses \ITSEC_Core::get_wp_upload_dir()
|
762 |
-
* @uses \ITSEC_Lib_Config_File::get_wp_config_file_path()
|
763 |
-
* @uses \ITSEC_Lib_Config_File::get_server_config_file_path()
|
764 |
-
*/
|
765 |
-
private function file_permissions() {
|
766 |
-
|
767 |
-
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
768 |
-
|
769 |
-
$wp_upload_dir = \ITSEC_Core::get_wp_upload_dir();
|
770 |
-
|
771 |
-
$path_data = array(
|
772 |
-
array(
|
773 |
-
ABSPATH,
|
774 |
-
0755,
|
775 |
-
),
|
776 |
-
array(
|
777 |
-
ABSPATH . WPINC,
|
778 |
-
0755,
|
779 |
-
),
|
780 |
-
array(
|
781 |
-
ABSPATH . 'wp-admin',
|
782 |
-
0755,
|
783 |
-
),
|
784 |
-
array(
|
785 |
-
ABSPATH . 'wp-admin/js',
|
786 |
-
0755,
|
787 |
-
),
|
788 |
-
array(
|
789 |
-
WP_CONTENT_DIR,
|
790 |
-
0755,
|
791 |
-
),
|
792 |
-
array(
|
793 |
-
get_theme_root(),
|
794 |
-
0755,
|
795 |
-
),
|
796 |
-
array(
|
797 |
-
WP_PLUGIN_DIR,
|
798 |
-
0755,
|
799 |
-
),
|
800 |
-
array(
|
801 |
-
$wp_upload_dir['basedir'],
|
802 |
-
0755,
|
803 |
-
),
|
804 |
-
array(
|
805 |
-
\ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
806 |
-
0444,
|
807 |
-
),
|
808 |
-
array(
|
809 |
-
\ITSEC_Lib_Config_File::get_server_config_file_path(),
|
810 |
-
0444,
|
811 |
-
),
|
812 |
-
);
|
813 |
-
|
814 |
-
$rows = array();
|
815 |
-
|
816 |
-
foreach ( $path_data as $path ) {
|
817 |
-
$row = array();
|
818 |
-
|
819 |
-
list( $path, $suggested_permissions ) = $path;
|
820 |
-
|
821 |
-
$display_path = preg_replace( '/^' . preg_quote( ABSPATH, '/' ) . '/', '', $path );
|
822 |
-
$display_path = ltrim( $display_path, '/' );
|
823 |
-
|
824 |
-
if ( empty( $display_path ) ) {
|
825 |
-
$display_path = '/';
|
826 |
-
}
|
827 |
-
|
828 |
-
$row[] = $display_path;
|
829 |
-
$row[] = sprintf( '%o', $suggested_permissions );
|
830 |
-
|
831 |
-
$permissions = fileperms( $path ) & 0777;
|
832 |
-
$row[] = sprintf( '%o', $permissions );
|
833 |
-
|
834 |
-
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
835 |
-
$row[] = __( 'WARNING', 'mainwp-child' );
|
836 |
-
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
837 |
-
} else {
|
838 |
-
$row[] = __( 'OK', 'mainwp-child' );
|
839 |
-
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
840 |
-
}
|
841 |
-
|
842 |
-
$rows[] = $row;
|
843 |
-
}
|
844 |
-
|
845 |
-
$class = 'entry-row';
|
846 |
-
ob_start();
|
847 |
-
?>
|
848 |
-
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php esc_attr_e( 'Reload File Permissions Details', 'mainwp-child' ); ?>"></p>
|
849 |
-
<table class="widefat">
|
850 |
-
<thead>
|
851 |
-
<tr>
|
852 |
-
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
853 |
-
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
854 |
-
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
855 |
-
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
856 |
-
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
857 |
-
</tr>
|
858 |
-
</thead>
|
859 |
-
<tfoot>
|
860 |
-
<tr>
|
861 |
-
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
862 |
-
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
863 |
-
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
864 |
-
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
865 |
-
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
866 |
-
</tr>
|
867 |
-
</tfoot>
|
868 |
-
<tbody>
|
869 |
-
<?php foreach ( $rows as $row ) : ?>
|
870 |
-
<tr class="<?php echo $class; ?>">
|
871 |
-
<?php foreach ( $row as $column ) : ?>
|
872 |
-
<td><?php echo $column; ?></td>
|
873 |
-
<?php endforeach; ?>
|
874 |
-
</tr>
|
875 |
-
<?php $class = ( 'entry-row' === $class ) ? 'entry-row alternate' : 'entry-row'; ?>
|
876 |
-
<?php endforeach; ?>
|
877 |
-
</tbody>
|
878 |
-
</table>
|
879 |
-
<br />
|
880 |
-
<?php
|
881 |
-
$html = ob_get_clean();
|
882 |
-
return array( 'html' => $html );
|
883 |
-
}
|
884 |
-
|
885 |
-
/**
|
886 |
-
* Run File Change scanner.
|
887 |
-
*
|
888 |
-
* @return array $return results array.
|
889 |
-
*
|
890 |
-
* @uses \ITSEC_File_Change_Scanner::run_scan()
|
891 |
-
*/
|
892 |
-
public function file_change() {
|
893 |
-
|
894 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
895 |
-
global $mainwp_itsec_modules_path;
|
896 |
-
|
897 |
-
if ( ! class_exists( '\ITSEC_File_Change_Scanner' ) ) {
|
898 |
-
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
|
899 |
-
}
|
900 |
-
$result = \ITSEC_File_Change_Scanner::run_scan( false );
|
901 |
-
if ( false === $result || true === $result || -1 === $result ) {
|
902 |
-
$return['result'] = 'success';
|
903 |
-
$return['scan_result'] = $result;
|
904 |
-
}
|
905 |
-
return $return;
|
906 |
-
}
|
907 |
-
|
908 |
-
/**
|
909 |
-
* Update admin user.
|
910 |
-
*
|
911 |
-
* @return array Return Success or Fail.
|
912 |
-
*
|
913 |
-
* @uses \ITSEC_Lib::user_id_exists()
|
914 |
-
* @uses MainWP_Child_IThemes_Security::change_admin_user()
|
915 |
-
*/
|
916 |
-
public function admin_user() {
|
917 |
-
|
918 |
-
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
919 |
-
|
920 |
-
if ( ! is_array( $settings ) ) {
|
921 |
-
$settings = array();
|
922 |
-
}
|
923 |
-
|
924 |
-
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
|
925 |
-
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
|
926 |
-
|
927 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
928 |
-
|
929 |
-
/** @global object $itsec_globals ITsec globals. */
|
930 |
-
global $itsec_globals;
|
931 |
-
|
932 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
933 |
-
}
|
934 |
-
|
935 |
-
$username_exists = username_exists( 'admin' );
|
936 |
-
$user_id_exists = \ITSEC_Lib::user_id_exists( 1 );
|
937 |
-
$msg = '';
|
938 |
-
if ( strlen( $new_username ) >= 1 ) {
|
939 |
-
|
940 |
-
/** @global string $current_user Current user global variable. */
|
941 |
-
global $current_user;
|
942 |
-
|
943 |
-
if ( ! $username_exists ) {
|
944 |
-
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
945 |
-
} elseif ( 'admin' == $current_user->user_login ) {
|
946 |
-
$return['result'] = 'CHILD_ADMIN';
|
947 |
-
return $return;
|
948 |
-
}
|
949 |
-
}
|
950 |
-
|
951 |
-
if ( true === $change_id && ! $user_id_exists ) {
|
952 |
-
if ( ! empty( $msg ) ) {
|
953 |
-
$msg .= '<br/>';
|
954 |
-
}
|
955 |
-
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
956 |
-
}
|
957 |
-
|
958 |
-
$admin_success = true;
|
959 |
-
$return = array();
|
960 |
-
|
961 |
-
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
962 |
-
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
963 |
-
} elseif ( true === $change_id && $user_id_exists ) {
|
964 |
-
$admin_success = $this->change_admin_user( null, $change_id );
|
965 |
-
}
|
966 |
-
|
967 |
-
$return['message'] = $msg;
|
968 |
-
if ( false === $admin_success ) {
|
969 |
-
$return['result'] = 'fail';
|
970 |
-
} else {
|
971 |
-
$return['result'] = 'success';
|
972 |
-
}
|
973 |
-
return $return;
|
974 |
-
}
|
975 |
-
|
976 |
-
/**
|
977 |
-
* Change admin user.
|
978 |
-
*
|
979 |
-
* @param string $username Username to update to. Default: null.
|
980 |
-
* @param bool $id User Id found. Default: false.
|
981 |
-
* @return bool Return TRUE on success and FALSE on failure.
|
982 |
-
*
|
983 |
-
* @uses \ITSEC_Core::get_itsec_files()
|
984 |
-
* @uses \ITSEC_Core::get_itsec_files::release_file_lock()
|
985 |
-
*/
|
986 |
-
private function change_admin_user($username = null, $id = false ) {
|
987 |
-
|
988 |
-
/** @global object $wpdb WordPress Database */
|
989 |
-
global $wpdb;
|
990 |
-
|
991 |
-
$itsec_files = \ITSEC_Core::get_itsec_files();
|
992 |
-
|
993 |
-
$new_user = sanitize_text_field( $username );
|
994 |
-
|
995 |
-
$user_object = get_user_by( 'id', '1' );
|
996 |
-
|
997 |
-
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) {
|
998 |
-
|
999 |
-
if ( true === $id ) {
|
1000 |
-
|
1001 |
-
$user_login = $new_user;
|
1002 |
-
|
1003 |
-
} else {
|
1004 |
-
|
1005 |
-
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
1006 |
-
|
1007 |
-
if ( is_multisite() ) {
|
1008 |
-
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1009 |
-
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1010 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
|
1011 |
-
}
|
1012 |
-
|
1013 |
-
wp_clear_auth_cookie();
|
1014 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1015 |
-
|
1016 |
-
return true;
|
1017 |
-
|
1018 |
-
}
|
1019 |
-
} elseif ( null !== $username ) {
|
1020 |
-
|
1021 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1022 |
-
|
1023 |
-
return false;
|
1024 |
-
|
1025 |
-
} else {
|
1026 |
-
|
1027 |
-
$user_login = $user_object->user_login;
|
1028 |
-
|
1029 |
-
}
|
1030 |
-
|
1031 |
-
if ( true === $id ) {
|
1032 |
-
|
1033 |
-
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
|
1034 |
-
|
1035 |
-
$wpdb->insert(
|
1036 |
-
$wpdb->users,
|
1037 |
-
array(
|
1038 |
-
'user_login' => $user_login,
|
1039 |
-
'user_pass' => $user_object->user_pass,
|
1040 |
-
'user_nicename' => $user_object->user_nicename,
|
1041 |
-
'user_email' => $user_object->user_email,
|
1042 |
-
'user_url' => $user_object->user_url,
|
1043 |
-
'user_registered' => $user_object->user_registered,
|
1044 |
-
'user_activation_key' => $user_object->user_activation_key,
|
1045 |
-
'user_status' => $user_object->user_status,
|
1046 |
-
'display_name' => $user_object->display_name,
|
1047 |
-
)
|
1048 |
-
);
|
1049 |
-
|
1050 |
-
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) {
|
1051 |
-
|
1052 |
-
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1053 |
-
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1054 |
-
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
|
1055 |
-
|
1056 |
-
}
|
1057 |
-
|
1058 |
-
$new_user = $wpdb->insert_id;
|
1059 |
-
|
1060 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
|
1061 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1062 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1063 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
|
1064 |
-
|
1065 |
-
wp_clear_auth_cookie();
|
1066 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1067 |
-
|
1068 |
-
return true;
|
1069 |
-
|
1070 |
-
}
|
1071 |
-
|
1072 |
-
return false;
|
1073 |
-
}
|
1074 |
-
|
1075 |
-
/**
|
1076 |
-
* Build WP_config rules.
|
1077 |
-
*
|
1078 |
-
* @param array $rules_array Config rules array.
|
1079 |
-
* @param null $input New directory input.
|
1080 |
-
*
|
1081 |
-
* @return array Return $rules_array.
|
1082 |
-
*/
|
1083 |
-
public function build_wpconfig_rules( $rules_array, $input = null ) {
|
1084 |
-
if ( null === $input ) {
|
1085 |
-
return $rules_array;
|
1086 |
-
}
|
1087 |
-
|
1088 |
-
$new_dir = trailingslashit( ABSPATH ) . $input;
|
1089 |
-
|
1090 |
-
$rules[] = array(
|
1091 |
-
'type' => 'add',
|
1092 |
-
'search_text' => '//Do not delete these. Doing so WILL break your site.',
|
1093 |
-
'rule' => '//Do not delete these. Doing so WILL break your site.',
|
1094 |
-
);
|
1095 |
-
|
1096 |
-
$rules[] = array(
|
1097 |
-
'type' => 'add',
|
1098 |
-
'search_text' => 'WP_CONTENT_URL',
|
1099 |
-
'rule' => "define( 'WP_CONTENT_URL', '" . trailingslashit( get_option( 'siteurl' ) ) . $input . "' );",
|
1100 |
-
);
|
1101 |
-
|
1102 |
-
$rules[] = array(
|
1103 |
-
'type' => 'add',
|
1104 |
-
'search_text' => 'WP_CONTENT_DIR',
|
1105 |
-
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
1106 |
-
);
|
1107 |
-
|
1108 |
-
$rules_array[] = array(
|
1109 |
-
'type' => 'wpconfig',
|
1110 |
-
'name' => 'Content Directory',
|
1111 |
-
'rules' => $rules,
|
1112 |
-
);
|
1113 |
-
|
1114 |
-
return $rules_array;
|
1115 |
-
}
|
1116 |
-
|
1117 |
-
|
1118 |
-
/**
|
1119 |
-
* Change database prefix.
|
1120 |
-
*
|
1121 |
-
* @return array $return Return response array.
|
1122 |
-
*
|
1123 |
-
* @uses \ITSEC_Database_Prefix_Utility::change_database_prefix()
|
1124 |
-
* @uses \ITSEC_Response::get_error_strings()
|
1125 |
-
* @uses \ITSEC_Response::reload_module()
|
1126 |
-
*/
|
1127 |
-
public function change_database_prefix() {
|
1128 |
-
|
1129 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1130 |
-
global $mainwp_itsec_modules_path;
|
1131 |
-
|
1132 |
-
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
|
1133 |
-
$str_error = '';
|
1134 |
-
$return = array();
|
1135 |
-
|
1136 |
-
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
1137 |
-
$result = \ITSEC_Database_Prefix_Utility::change_database_prefix();
|
1138 |
-
$return = $result['errors'];
|
1139 |
-
if ( is_array( $result['errors'] ) ) {
|
1140 |
-
foreach ( $result['errors'] as $error ) {
|
1141 |
-
$arr_errors = \ITSEC_Response::get_error_strings( $error );
|
1142 |
-
foreach ( $arr_errors as $er ) {
|
1143 |
-
$str_error .= $er . '<br />';
|
1144 |
-
}
|
1145 |
-
}
|
1146 |
-
}
|
1147 |
-
|
1148 |
-
\ITSEC_Response::reload_module( 'database-prefix' );
|
1149 |
-
|
1150 |
-
if ( false === $result['new_prefix'] ) {
|
1151 |
-
$return['error'] = $str_error;
|
1152 |
-
} else {
|
1153 |
-
$return['result'] = 'success';
|
1154 |
-
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'mainwp-child' ), $result['new_prefix'] );
|
1155 |
-
|
1156 |
-
}
|
1157 |
-
}
|
1158 |
-
return $return;
|
1159 |
-
}
|
1160 |
-
|
1161 |
-
/**
|
1162 |
-
* Update API key.
|
1163 |
-
*
|
1164 |
-
* @return array $return Return response array. Success or nochange.
|
1165 |
-
*/
|
1166 |
-
public function api_key() {
|
1167 |
-
$settings = get_site_option( 'itsec_ipcheck' );
|
1168 |
-
if ( ! is_array( $settings ) ) {
|
1169 |
-
$settings = array();
|
1170 |
-
}
|
1171 |
-
$settings['reset'] = true;
|
1172 |
-
$return = array();
|
1173 |
-
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
1174 |
-
$return['result'] = 'success';
|
1175 |
-
} else {
|
1176 |
-
$return['result'] = 'nochange';
|
1177 |
-
}
|
1178 |
-
|
1179 |
-
return $return;
|
1180 |
-
}
|
1181 |
-
|
1182 |
-
/**
|
1183 |
-
* Reset api key.
|
1184 |
-
*
|
1185 |
-
* @return array $information Return response array.
|
1186 |
-
*
|
1187 |
-
* @uses \ITSEC_Modules::get_defaults()
|
1188 |
-
* @uses \ITSEC_Modules::set_defaults()
|
1189 |
-
* @uses \ITSEC_Response::set_response()
|
1190 |
-
* @uses \ITSEC_Response::add_errors()
|
1191 |
-
* @uses \ITSEC_Response::add_messages()
|
1192 |
-
*/
|
1193 |
-
public function reset_api_key() {
|
1194 |
-
|
1195 |
-
$defaults = \ITSEC_Modules::get_defaults( 'network-brute-force' );
|
1196 |
-
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
|
1197 |
-
|
1198 |
-
\ITSEC_Response::set_response( $results['saved'] );
|
1199 |
-
\ITSEC_Response::add_errors( $results['errors'] );
|
1200 |
-
\ITSEC_Response::add_messages( $results['messages'] );
|
1201 |
-
|
1202 |
-
$information = array();
|
1203 |
-
if ( $results['saved'] ) {
|
1204 |
-
$information['result'] = 'success';
|
1205 |
-
$information['nbf_settings'] = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
1206 |
-
} elseif ( empty( $results['errors'] ) ) {
|
1207 |
-
$information['error_reset_api'] = 1;
|
1208 |
-
}
|
1209 |
-
return $information;
|
1210 |
-
}
|
1211 |
-
|
1212 |
-
/**
|
1213 |
-
* Malware scan.
|
1214 |
-
*
|
1215 |
-
* @return array $response Return response array.
|
1216 |
-
*
|
1217 |
-
* @uses \ITSEC_Core::current_user_can_manage()
|
1218 |
-
* @uses \ITSEC_Malware_Scanner::scan()
|
1219 |
-
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1220 |
-
*/
|
1221 |
-
public function malware_scan() {
|
1222 |
-
|
1223 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1224 |
-
global $mainwp_itsec_modules_path;
|
1225 |
-
|
1226 |
-
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1227 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1228 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1229 |
-
}
|
1230 |
-
|
1231 |
-
$response = array();
|
1232 |
-
if ( ! \ITSEC_Core::current_user_can_manage() ) {
|
1233 |
-
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
1234 |
-
} else {
|
1235 |
-
$results = \ITSEC_Malware_Scanner::scan();
|
1236 |
-
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1237 |
-
}
|
1238 |
-
|
1239 |
-
return $response;
|
1240 |
-
}
|
1241 |
-
|
1242 |
-
/**
|
1243 |
-
* Get malware scan results.
|
1244 |
-
*
|
1245 |
-
* @return array $response Return response array.
|
1246 |
-
*
|
1247 |
-
* @uses \ITSEC_Malware_Scanner::scan()
|
1248 |
-
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1249 |
-
*/
|
1250 |
-
public function malware_get_scan_results() {
|
1251 |
-
|
1252 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1253 |
-
global $mainwp_itsec_modules_path;
|
1254 |
-
|
1255 |
-
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1256 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1257 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1258 |
-
}
|
1259 |
-
$response = array();
|
1260 |
-
$results = \ITSEC_Malware_Scanner::scan();
|
1261 |
-
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1262 |
-
return $response;
|
1263 |
-
}
|
1264 |
-
|
1265 |
-
/**
|
1266 |
-
* Purge logs.
|
1267 |
-
*
|
1268 |
-
* @return string[] Return response array.
|
1269 |
-
*/
|
1270 |
-
public function purge_logs() {
|
1271 |
-
|
1272 |
-
/** @global object $wpdb WordPress Database object. */
|
1273 |
-
global $wpdb;
|
1274 |
-
|
1275 |
-
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
1276 |
-
|
1277 |
-
return array( 'result' => 'success' );
|
1278 |
-
}
|
1279 |
-
|
1280 |
-
|
1281 |
-
/**
|
1282 |
-
* Get lockouts.
|
1283 |
-
*
|
1284 |
-
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1285 |
-
* @param bool $current TRUE if current. Default: FALSE.
|
1286 |
-
*
|
1287 |
-
* @return array $output Return response array.
|
1288 |
-
*
|
1289 |
-
* @uses MainWP_Child_IThemes_Security::get_lockouts_int()
|
1290 |
-
*/
|
1291 |
-
public function get_lockouts( $type = 'all', $current = false ) {
|
1292 |
-
|
1293 |
-
/**
|
1294 |
-
* @global object $wpdb WordPress Database object.
|
1295 |
-
* @global object $itsec_globals itsec globals.
|
1296 |
-
*/
|
1297 |
-
global $wpdb, $itsec_globals;
|
1298 |
-
|
1299 |
-
if ( 'all' !== $type || true === $current ) {
|
1300 |
-
$where = ' WHERE ';
|
1301 |
-
} else {
|
1302 |
-
$where = '';
|
1303 |
-
}
|
1304 |
-
|
1305 |
-
switch ( $type ) {
|
1306 |
-
|
1307 |
-
case 'host':
|
1308 |
-
$type_statement = "`lockout_host` IS NOT NULL && `lockout_host` != ''";
|
1309 |
-
break;
|
1310 |
-
case 'user':
|
1311 |
-
$type_statement = '`lockout_user` != 0';
|
1312 |
-
break;
|
1313 |
-
case 'username':
|
1314 |
-
$type_statement = "`lockout_username` IS NOT NULL && `lockout_username` != ''";
|
1315 |
-
break;
|
1316 |
-
default:
|
1317 |
-
$type_statement = '';
|
1318 |
-
break;
|
1319 |
-
|
1320 |
-
}
|
1321 |
-
|
1322 |
-
if ( true === $current ) {
|
1323 |
-
|
1324 |
-
if ( '' !== $type_statement ) {
|
1325 |
-
$and = ' AND ';
|
1326 |
-
} else {
|
1327 |
-
$and = '';
|
1328 |
-
}
|
1329 |
-
|
1330 |
-
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" . gmdate( 'Y-m-d H:i:s', $itsec_globals['current_time_gmt'] ) . "'";
|
1331 |
-
|
1332 |
-
} else {
|
1333 |
-
|
1334 |
-
$active = '';
|
1335 |
-
|
1336 |
-
}
|
1337 |
-
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
1338 |
-
|
1339 |
-
return $this->get_lockouts_int( $results, $type );
|
1340 |
-
}
|
1341 |
-
|
1342 |
-
/**
|
1343 |
-
* Initiate get lockouts.
|
1344 |
-
*
|
1345 |
-
* @param array $results Results from MainWP_Child_IThemes_Security::get_lockouts()
|
1346 |
-
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1347 |
-
*
|
1348 |
-
* @return array $output Return response array.
|
1349 |
-
*/
|
1350 |
-
private function get_lockouts_int($results, $type ){
|
1351 |
-
|
1352 |
-
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1353 |
-
switch ( $type ) {
|
1354 |
-
case 'host':
|
1355 |
-
foreach ( $results as $val ) {
|
1356 |
-
$output[] = array(
|
1357 |
-
'lockout_id' => $val['lockout_id'],
|
1358 |
-
'lockout_host' => $val['lockout_host'],
|
1359 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1360 |
-
);
|
1361 |
-
}
|
1362 |
-
break;
|
1363 |
-
case 'user':
|
1364 |
-
foreach ( $results as $val ) {
|
1365 |
-
$output[] = array(
|
1366 |
-
'lockout_id' => $val['lockout_id'],
|
1367 |
-
'lockout_user' => $val['lockout_user'],
|
1368 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1369 |
-
);
|
1370 |
-
}
|
1371 |
-
break;
|
1372 |
-
case 'username':
|
1373 |
-
foreach ( $results as $val ) {
|
1374 |
-
$output[] = array(
|
1375 |
-
'lockout_id' => $val['lockout_id'],
|
1376 |
-
'lockout_username' => $val['lockout_username'],
|
1377 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1378 |
-
);
|
1379 |
-
}
|
1380 |
-
break;
|
1381 |
-
default:
|
1382 |
-
break;
|
1383 |
-
}
|
1384 |
-
}
|
1385 |
-
|
1386 |
-
return $output;
|
1387 |
-
|
1388 |
-
}
|
1389 |
-
|
1390 |
-
/**
|
1391 |
-
* Release lockout.
|
1392 |
-
*
|
1393 |
-
* @return string[] Return results array.
|
1394 |
-
*
|
1395 |
-
* @uses \ITSEC_Lib::clear_caches()
|
1396 |
-
*/
|
1397 |
-
public function release_lockout() {
|
1398 |
-
|
1399 |
-
/** @global object $wpdb WordPress Database. */
|
1400 |
-
global $wpdb;
|
1401 |
-
|
1402 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
1403 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
1404 |
-
}
|
1405 |
-
|
1406 |
-
$lockout_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['lockout_ids'] ) );
|
1407 |
-
if ( ! is_array( $lockout_ids ) ) {
|
1408 |
-
$lockout_ids = array();
|
1409 |
-
}
|
1410 |
-
|
1411 |
-
$type = 'updated';
|
1412 |
-
$message = __( 'The selected lockouts have been cleared.', 'mainwp-child' );
|
1413 |
-
|
1414 |
-
foreach ( $lockout_ids as $value ) {
|
1415 |
-
$wpdb->update(
|
1416 |
-
$wpdb->base_prefix . 'itsec_lockouts',
|
1417 |
-
array(
|
1418 |
-
'lockout_active' => 0,
|
1419 |
-
),
|
1420 |
-
array(
|
1421 |
-
'lockout_id' => intval( $value ),
|
1422 |
-
)
|
1423 |
-
);
|
1424 |
-
}
|
1425 |
-
|
1426 |
-
\ITSEC_Lib::clear_caches();
|
1427 |
-
|
1428 |
-
if ( ! is_multisite() ) {
|
1429 |
-
if ( ! function_exists( 'add_settings_error' ) ) {
|
1430 |
-
require_once ABSPATH . '/wp-admin/includes/template.php';
|
1431 |
-
}
|
1432 |
-
|
1433 |
-
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
1434 |
-
}
|
1435 |
-
|
1436 |
-
return array(
|
1437 |
-
'result' => 'success',
|
1438 |
-
);
|
1439 |
-
}
|
1440 |
-
|
1441 |
-
/**
|
1442 |
-
* Update module status.
|
1443 |
-
*
|
1444 |
-
* @return string[] Return response array.
|
1445 |
-
*/
|
1446 |
-
public function update_module_status() {
|
1447 |
-
|
1448 |
-
$active_modules = isset( $_POST['active_modules'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['active_modules'] ) ) : array();
|
1449 |
-
|
1450 |
-
if ( ! is_array( $active_modules ) ) {
|
1451 |
-
$active_modules = array();
|
1452 |
-
}
|
1453 |
-
|
1454 |
-
$current_val = get_site_option( 'itsec_active_modules', array() );
|
1455 |
-
foreach ( $active_modules as $mod => $val ) {
|
1456 |
-
$current_val[ $mod ] = $val;
|
1457 |
-
}
|
1458 |
-
|
1459 |
-
update_site_option( 'itsec_active_modules', $current_val );
|
1460 |
-
return array( 'result' => 'success' );
|
1461 |
-
}
|
1462 |
-
|
1463 |
-
/**
|
1464 |
-
* Reload excluded backups table.
|
1465 |
-
*
|
1466 |
-
* @return array Return response array.
|
1467 |
-
*
|
1468 |
-
* @uses \ITSEC_Modules::get_setting()
|
1469 |
-
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
1470 |
-
*/
|
1471 |
-
private function reload_backup_exclude() {
|
1472 |
-
return array(
|
1473 |
-
'exclude' => \ITSEC_Modules::get_setting( 'backup', 'exclude' ),
|
1474 |
-
'excludable_tables' => $this->get_excludable_tables(),
|
1475 |
-
'result' => 'success',
|
1476 |
-
);
|
1477 |
-
}
|
1478 |
-
|
1479 |
-
/**
|
1480 |
-
* Get excludable backups table.
|
1481 |
-
*
|
1482 |
-
* @return array $excludes Return response array.
|
1483 |
-
*
|
1484 |
-
* @uses \ITSEC_Modules::get_setting()
|
1485 |
-
*/
|
1486 |
-
private function get_excludable_tables() {
|
1487 |
-
|
1488 |
-
/** @global object $wpdb WordPress Database. */
|
1489 |
-
global $wpdb;
|
1490 |
-
|
1491 |
-
$all_sites = \ITSEC_Modules::get_setting( 'backup', 'all_sites' );
|
1492 |
-
$ignored_tables = array(
|
1493 |
-
'commentmeta',
|
1494 |
-
'comments',
|
1495 |
-
'links',
|
1496 |
-
'options',
|
1497 |
-
'postmeta',
|
1498 |
-
'posts',
|
1499 |
-
'term_relationships',
|
1500 |
-
'term_taxonomy',
|
1501 |
-
'terms',
|
1502 |
-
'usermeta',
|
1503 |
-
'users',
|
1504 |
-
);
|
1505 |
-
|
1506 |
-
if ( $all_sites ) {
|
1507 |
-
$query = 'SHOW TABLES';
|
1508 |
-
} else {
|
1509 |
-
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1510 |
-
}
|
1511 |
-
|
1512 |
-
$tables = $wpdb->get_results( $query, ARRAY_N ); // phpcs:ignore -- safe query.
|
1513 |
-
$excludes = array();
|
1514 |
-
|
1515 |
-
foreach ( $tables as $table ) {
|
1516 |
-
$short_table = substr( $table[0], strlen( $wpdb->prefix ) );
|
1517 |
-
|
1518 |
-
if ( in_array( $short_table, $ignored_tables ) ) {
|
1519 |
-
continue;
|
1520 |
-
}
|
1521 |
-
|
1522 |
-
$excludes[ $short_table ] = $table[0];
|
1523 |
-
}
|
1524 |
-
|
1525 |
-
return $excludes;
|
1526 |
-
}
|
1527 |
-
|
1528 |
-
/**
|
1529 |
-
* Get security check results.
|
1530 |
-
*
|
1531 |
-
* @return array Return response array.
|
1532 |
-
*
|
1533 |
-
* @uses \ITSEC_Security_Check_Scanner::get_results()
|
1534 |
-
* @uses \ITSEC_Security_Check_Feedback_Renderer::render(
|
1535 |
-
*/
|
1536 |
-
private function security_site() {
|
1537 |
-
|
1538 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1539 |
-
global $mainwp_itsec_modules_path;
|
1540 |
-
|
1541 |
-
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
|
1542 |
-
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
|
1543 |
-
$results = \ITSEC_Security_Check_Scanner::get_results();
|
1544 |
-
ob_start();
|
1545 |
-
\ITSEC_Security_Check_Feedback_Renderer::render( $results );
|
1546 |
-
$response = ob_get_clean();
|
1547 |
-
return array(
|
1548 |
-
'result' => 'success',
|
1549 |
-
'response' => $response,
|
1550 |
-
);
|
1551 |
-
}
|
1552 |
-
|
1553 |
-
/**
|
1554 |
-
* Get available admin users and roles.
|
1555 |
-
*
|
1556 |
-
* @return array[] Return response array.phpdoc
|
1557 |
-
*
|
1558 |
-
* @uses \WP_Roles()
|
1559 |
-
*/
|
1560 |
-
public function get_available_admin_users_and_roles() {
|
1561 |
-
if ( is_callable( 'wp_roles' ) ) {
|
1562 |
-
$roles = wp_roles();
|
1563 |
-
} else {
|
1564 |
-
$roles = new \WP_Roles();
|
1565 |
-
}
|
1566 |
-
|
1567 |
-
$available_roles = array();
|
1568 |
-
$available_users = array();
|
1569 |
-
|
1570 |
-
foreach ( $roles->roles as $role => $details ) {
|
1571 |
-
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1572 |
-
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
|
1573 |
-
|
1574 |
-
$users = get_users( array( 'role' => $role ) );
|
1575 |
-
|
1576 |
-
foreach ( $users as $user ) {
|
1577 |
-
/* translators: 1: user display name, 2: user login */
|
1578 |
-
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', 'mainwp-child' ), $user->display_name, $user->user_login );
|
1579 |
-
}
|
1580 |
-
}
|
1581 |
-
}
|
1582 |
-
|
1583 |
-
natcasesort( $available_users );
|
1584 |
-
|
1585 |
-
return array(
|
1586 |
-
'users' => $available_users,
|
1587 |
-
'roles' => $available_roles,
|
1588 |
-
);
|
1589 |
-
}
|
1590 |
-
|
1591 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Ithemes Security
|
4 |
+
*
|
5 |
+
* MainWP iThemes Security Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*
|
10 |
+
* Credits
|
11 |
+
*
|
12 |
+
* Plugin-Name: iThemes Security
|
13 |
+
* Plugin URI: https://ithemes.com/security
|
14 |
+
* Author: iThemes
|
15 |
+
* Author URI: https://ithemes.com
|
16 |
+
* License: GPLv2
|
17 |
+
*
|
18 |
+
* The code is used for the MainWP iThemes Security Extension
|
19 |
+
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
20 |
+
*/
|
21 |
+
|
22 |
+
namespace MainWP\Child;
|
23 |
+
|
24 |
+
// phpcs:disable -- third party credit code.
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Class MainWP_Child_IThemes_Security
|
29 |
+
*/
|
30 |
+
class MainWP_Child_IThemes_Security {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Public static variable to hold the single instance of MainWP_Child_IThemes_Security.
|
34 |
+
* @var null
|
35 |
+
*/
|
36 |
+
public static $instance = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var bool Whether or not iThemes Plugin is installed or not. Default: false.
|
40 |
+
*/
|
41 |
+
public $is_plugin_installed = false;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_IThemes_Security.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_IThemes_Security|null
|
47 |
+
*/
|
48 |
+
public static function instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
+
}
|
52 |
+
return self::$instance;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* MainWP_Child_IThemes_Security constructor.
|
57 |
+
*
|
58 |
+
* Run any time class is called.
|
59 |
+
*
|
60 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
61 |
+
*/
|
62 |
+
public function __construct() {
|
63 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
64 |
+
if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
|
65 |
+
$this->is_plugin_installed = true;
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( ! $this->is_plugin_installed ) {
|
69 |
+
return;
|
70 |
+
}
|
71 |
+
|
72 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Sync other data from $data[] and merge with $information[]
|
77 |
+
*
|
78 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
79 |
+
* @param array $data Other data to sync to $information array.
|
80 |
+
* @return array $information Returned information array with both sets of data.
|
81 |
+
*/
|
82 |
+
public function sync_others_data( $information, $data = array() ) {
|
83 |
+
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
84 |
+
try {
|
85 |
+
$information['syncIThemeData'] = array(
|
86 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
87 |
+
);
|
88 |
+
} catch ( \Exception $e ) {
|
89 |
+
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
|
90 |
+
}
|
91 |
+
}
|
92 |
+
return $information;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* MainWP iThemes Security Extension actions.
|
97 |
+
*
|
98 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::set_showhide()
|
99 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::save_settings()
|
100 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::whitelist_release()
|
101 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::backup_db()
|
102 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::admin_user()
|
103 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::change_database_prefix()
|
104 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reset_api_key()
|
105 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::malware_scan()
|
106 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::>purge_logs()
|
107 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_change()
|
108 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::release_lockout()
|
109 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::update_module_status()
|
110 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::wordpress_salts()
|
111 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_permissions()
|
112 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reload_backup_exclude()
|
113 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::security_site()
|
114 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::activate_network_brute_force()
|
115 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
116 |
+
*/
|
117 |
+
public function action() {
|
118 |
+
$information = array();
|
119 |
+
if ( ! class_exists( '\ITSEC_Core' ) || ! class_exists( '\ITSEC_Modules' ) ) {
|
120 |
+
$information['error'] = 'NO_ITHEME';
|
121 |
+
MainWP_Helper::write( $information );
|
122 |
+
}
|
123 |
+
|
124 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
125 |
+
global $mainwp_itsec_modules_path;
|
126 |
+
|
127 |
+
$mainwp_itsec_modules_path = \ITSEC_Core::get_core_dir() . '/modules/';
|
128 |
+
|
129 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
130 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
131 |
+
switch ( $mwp_action ) {
|
132 |
+
case 'set_showhide':
|
133 |
+
$information = $this->set_showhide();
|
134 |
+
break;
|
135 |
+
case 'save_settings':
|
136 |
+
$information = $this->save_settings();
|
137 |
+
break;
|
138 |
+
case 'whitelist_release':
|
139 |
+
$information = $this->whitelist_release();
|
140 |
+
break;
|
141 |
+
case 'backup_db':
|
142 |
+
$information = $this->backup_db();
|
143 |
+
break;
|
144 |
+
case 'admin_user':
|
145 |
+
$information = $this->admin_user();
|
146 |
+
break;
|
147 |
+
case 'database_prefix':
|
148 |
+
$information = $this->change_database_prefix();
|
149 |
+
break;
|
150 |
+
case 'reset_api_key':
|
151 |
+
$information = $this->reset_api_key();
|
152 |
+
break;
|
153 |
+
case 'malware_scan':
|
154 |
+
$information = $this->malware_scan();
|
155 |
+
break;
|
156 |
+
case 'clear_all_logs':
|
157 |
+
$information = $this->purge_logs();
|
158 |
+
break;
|
159 |
+
case 'file_change':
|
160 |
+
$information = $this->file_change();
|
161 |
+
break;
|
162 |
+
case 'release_lockout':
|
163 |
+
$information = $this->release_lockout();
|
164 |
+
break;
|
165 |
+
case 'module_status':
|
166 |
+
$information = $this->update_module_status();
|
167 |
+
break;
|
168 |
+
case 'wordpress_salts':
|
169 |
+
$information = $this->wordpress_salts();
|
170 |
+
break;
|
171 |
+
case 'file_permissions':
|
172 |
+
$information = $this->file_permissions();
|
173 |
+
break;
|
174 |
+
case 'reload_backup_exclude':
|
175 |
+
$information = $this->reload_backup_exclude();
|
176 |
+
break;
|
177 |
+
case 'security_site':
|
178 |
+
$information = $this->security_site();
|
179 |
+
break;
|
180 |
+
case 'activate_network_brute_force':
|
181 |
+
$information = $this->activate_network_brute_force();
|
182 |
+
break;
|
183 |
+
}
|
184 |
+
}
|
185 |
+
MainWP_Helper::write( $information );
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Set show or hide UpdraftPlus Plugin from Admin & plugins list.
|
190 |
+
*
|
191 |
+
* @return array $information Return results.
|
192 |
+
*
|
193 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
194 |
+
*/
|
195 |
+
public function set_showhide() {
|
196 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
197 |
+
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
198 |
+
$information['result'] = 'success';
|
199 |
+
|
200 |
+
return $information;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Initiate iThemes settings.
|
205 |
+
*
|
206 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
207 |
+
*/
|
208 |
+
public function ithemes_init() {
|
209 |
+
if ( ! $this->is_plugin_installed ) {
|
210 |
+
return;
|
211 |
+
}
|
212 |
+
|
213 |
+
if ( 'hide' === get_option( 'mainwp_ithemes_hide_plugin' ) ) {
|
214 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
215 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
216 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
217 |
+
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
218 |
+
if ( isset( $_GET['page'] ) && ( 'itsec' == $_GET['page'] || 'itsec-security-check' == $_GET['page'] ) ) {
|
219 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
220 |
+
exit();
|
221 |
+
}
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* iThemes Security Admin initiation.
|
227 |
+
*/
|
228 |
+
public function admin_init() {
|
229 |
+
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Remove iThemes Security from plugins page.
|
234 |
+
*
|
235 |
+
* @param array $plugins All plugins array.
|
236 |
+
*
|
237 |
+
* @return array $plugins All plugins array with iThemes Security removed.
|
238 |
+
*/
|
239 |
+
public function all_plugins( $plugins ) {
|
240 |
+
foreach ( $plugins as $key => $value ) {
|
241 |
+
$plugin_slug = basename( $key, '.php' );
|
242 |
+
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
243 |
+
unset( $plugins[ $key ] );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
return $plugins;
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Remove iThemes Security plugin from WP Admin menu.
|
252 |
+
*/
|
253 |
+
public function remove_menu() {
|
254 |
+
remove_menu_page( 'itsec' );
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Custom admin CSS.
|
259 |
+
*/
|
260 |
+
public function custom_admin_css() {
|
261 |
+
?>
|
262 |
+
<style type="text/css">
|
263 |
+
#wp-admin-bar-itsec_admin_bar_menu{
|
264 |
+
display: none !important;
|
265 |
+
}
|
266 |
+
</style>
|
267 |
+
<?php
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Save UpdraftPlus settings.
|
272 |
+
*
|
273 |
+
* @return array[] $return Return Error message or Success Message.
|
274 |
+
*
|
275 |
+
* @uses \ITSEC_Lib::get_server()
|
276 |
+
* @uses \ITSEC_Lib::get_ssl_support_probability()
|
277 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config()
|
278 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config()
|
279 |
+
* @uses \ITSEC_Modules::get_default()
|
280 |
+
* @uses \ITSEC_Modules::get_setting()
|
281 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts()
|
282 |
+
* @uses MainWP_Child_IThemes_Security::validate_directory()
|
283 |
+
* @uses MainWP_Child_IThemes_Security::activate_api_key()
|
284 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
285 |
+
* @uses MainWP_Child_IThemes_Security::get_available_admin_users_and_roles()
|
286 |
+
*/
|
287 |
+
public function save_settings() {
|
288 |
+
|
289 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
290 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
291 |
+
}
|
292 |
+
|
293 |
+
$_itsec_modules = array(
|
294 |
+
'global',
|
295 |
+
'away-mode',
|
296 |
+
'backup',
|
297 |
+
'hide-backend',
|
298 |
+
'ipcheck',
|
299 |
+
'ban-users',
|
300 |
+
'brute-force',
|
301 |
+
'file-change',
|
302 |
+
'404-detection',
|
303 |
+
'network-brute-force',
|
304 |
+
'ssl',
|
305 |
+
'password-requirements',
|
306 |
+
'system-tweaks',
|
307 |
+
'wordpress-tweaks',
|
308 |
+
'multisite-tweaks',
|
309 |
+
'notification-center',
|
310 |
+
);
|
311 |
+
|
312 |
+
$require_permalinks = false;
|
313 |
+
$updated = false;
|
314 |
+
$errors = array();
|
315 |
+
$nbf_settings = array();
|
316 |
+
|
317 |
+
$update_settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
318 |
+
|
319 |
+
foreach ( $update_settings as $module => $settings ) {
|
320 |
+
$do_not_save = false;
|
321 |
+
if ( in_array( $module, $_itsec_modules ) ) {
|
322 |
+
if ( 'wordpress-salts' == $module ) {
|
323 |
+
$settings['last_generated'] = \ITSEC_Modules::get_setting( $module, 'last_generated' );
|
324 |
+
} elseif ( 'global' == $module ) {
|
325 |
+
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file' );
|
326 |
+
foreach ( $keep_olds as $key ) {
|
327 |
+
$settings[ $key ] = \ITSEC_Modules::get_setting( $module, $key );
|
328 |
+
}
|
329 |
+
|
330 |
+
if ( ! isset( $settings['log_location'] ) || empty( $settings['log_location'] ) ) {
|
331 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
332 |
+
} else {
|
333 |
+
$result = $this->validate_directory( 'log_location', $settings['log_location'] );
|
334 |
+
if ( true !== $result ) {
|
335 |
+
$errors[] = $result;
|
336 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
337 |
+
}
|
338 |
+
}
|
339 |
+
} elseif ( 'backup' == $module ) {
|
340 |
+
if ( ! isset( $settings['location'] ) || empty( $settings['location'] ) ) {
|
341 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
342 |
+
} else {
|
343 |
+
$result = $this->validate_directory( 'location', $settings['location'] );
|
344 |
+
if ( true !== $result ) {
|
345 |
+
$errors[] = $result;
|
346 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
347 |
+
}
|
348 |
+
}
|
349 |
+
if ( ! isset( $settings['exclude'] ) ) {
|
350 |
+
$settings['exclude'] = \ITSEC_Modules::get_setting( $module, 'exclude' );
|
351 |
+
|
352 |
+
}
|
353 |
+
} elseif ( 'hide-backend' == $module ) {
|
354 |
+
if ( isset( $settings['enabled'] ) && ! empty( $settings['enabled'] ) ) {
|
355 |
+
$permalink_structure = get_option( 'permalink_structure', false );
|
356 |
+
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
357 |
+
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'mainwp-child' );
|
358 |
+
$require_permalinks = true;
|
359 |
+
$do_not_save = true;
|
360 |
+
}
|
361 |
+
}
|
362 |
+
} elseif ( 'network-brute-force' == $module ) {
|
363 |
+
|
364 |
+
if ( isset( $settings['email'] ) ) {
|
365 |
+
$result = $this->activate_api_key( $settings );
|
366 |
+
if ( false === $result ) {
|
367 |
+
$nbf_settings = $settings;
|
368 |
+
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
369 |
+
} else {
|
370 |
+
$nbf_settings = $result;
|
371 |
+
}
|
372 |
+
} else {
|
373 |
+
$previous_settings = \ITSEC_Modules::get_settings( $module );
|
374 |
+
if ( isset( $settings['enable_ban'] ) ) {
|
375 |
+
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
376 |
+
$nbf_settings = $previous_settings;
|
377 |
+
} else {
|
378 |
+
$do_not_save = true;
|
379 |
+
$nbf_settings = $previous_settings;
|
380 |
+
}
|
381 |
+
}
|
382 |
+
$settings = $nbf_settings;
|
383 |
+
} elseif ( 'notification-center' == $module ) {
|
384 |
+
$current_settings = \ITSEC_Modules::get_settings( $module );
|
385 |
+
if ( isset( $settings['notifications'] ) ) {
|
386 |
+
$update_fields = array( 'schedule', 'enabled', 'subject' );
|
387 |
+
if ( isset( $_POST['is_individual'] ) && $_POST['is_individual'] ) {
|
388 |
+
$update_fields = array_merge( $update_fields, array( 'user_list', 'email_list' ) );
|
389 |
+
}
|
390 |
+
foreach ( $settings['notifications'] as $key => $val ) {
|
391 |
+
foreach ( $update_fields as $field ) {
|
392 |
+
if ( isset( $val[ $field ] ) ) {
|
393 |
+
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
|
394 |
+
}
|
395 |
+
}
|
396 |
+
}
|
397 |
+
$updated = true;
|
398 |
+
\ITSEC_Modules::set_settings( $module, $current_settings );
|
399 |
+
}
|
400 |
+
continue;
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( ! $do_not_save ) {
|
404 |
+
\ITSEC_Modules::set_settings( $module, $settings );
|
405 |
+
$updated = true;
|
406 |
+
}
|
407 |
+
}
|
408 |
+
}
|
409 |
+
|
410 |
+
if ( isset( $update_settings['itsec_active_modules'] ) ) {
|
411 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
412 |
+
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) {
|
413 |
+
$current_val[ $mod ] = $val;
|
414 |
+
}
|
415 |
+
update_site_option( 'itsec_active_modules', $current_val );
|
416 |
+
}
|
417 |
+
|
418 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
419 |
+
|
420 |
+
$values = array(
|
421 |
+
'permalink_structure' => get_option( 'permalink_structure' ),
|
422 |
+
'is_multisite' => is_multisite() ? 1 : 0,
|
423 |
+
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
424 |
+
'server_nginx' => ( \ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
425 |
+
'has_ssl' => \ITSEC_Lib::get_ssl_support_probability(),
|
426 |
+
'jquery_version' => \ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
|
427 |
+
'server_rules' => \ITSEC_Lib_Config_File::get_server_config(),
|
428 |
+
'config_rules' => \ITSEC_Lib_Config_File::get_wp_config(),
|
429 |
+
'lockouts_host' => $this->get_lockouts( 'host', true ),
|
430 |
+
'lockouts_user' => $this->get_lockouts( 'user', true ),
|
431 |
+
'lockouts_username' => $this->get_lockouts( 'username', true ),
|
432 |
+
'default_log_location' => \ITSEC_Modules::get_default( 'global', 'log_location' ),
|
433 |
+
'default_location' => \ITSEC_Modules::get_default( 'backup', 'location' ),
|
434 |
+
'excludable_tables' => $this->get_excludable_tables(),
|
435 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
436 |
+
);
|
437 |
+
|
438 |
+
$return = array(
|
439 |
+
'site_status' => $values,
|
440 |
+
);
|
441 |
+
|
442 |
+
if ( $require_permalinks ) {
|
443 |
+
$return['require_permalinks'] = 1;
|
444 |
+
}
|
445 |
+
|
446 |
+
$return['nbf_settings'] = $nbf_settings;
|
447 |
+
|
448 |
+
if ( ! empty( $errors ) ) {
|
449 |
+
$return['extra_message'] = $errors;
|
450 |
+
}
|
451 |
+
|
452 |
+
if ( $updated ) {
|
453 |
+
$return['result'] = 'success';
|
454 |
+
} else {
|
455 |
+
$return['error'] = __( 'Not Updated', 'mainwp-child' );
|
456 |
+
}
|
457 |
+
|
458 |
+
return $return;
|
459 |
+
}
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Activate network brute force.
|
463 |
+
*
|
464 |
+
* @return array $information Results array.
|
465 |
+
*
|
466 |
+
* @uses \ITSEC_Modules::get_settings()
|
467 |
+
* @uses \ITSEC_Modules::activate()
|
468 |
+
*/
|
469 |
+
public static function activate_network_brute_force() {
|
470 |
+
$data = isset( $_POST['data'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
471 |
+
$information = array();
|
472 |
+
if ( is_array( $data ) ) {
|
473 |
+
$settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
474 |
+
$settings['email'] = $data['email'];
|
475 |
+
$settings['updates_optin'] = $data['updates_optin'];
|
476 |
+
$settings['api_nag'] = false;
|
477 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $settings );
|
478 |
+
if ( is_wp_error( $results ) ) {
|
479 |
+
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
480 |
+
} elseif ( $results['saved'] ) {
|
481 |
+
\ITSEC_Modules::activate( 'network-brute-force' );
|
482 |
+
$nbf_settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
483 |
+
}
|
484 |
+
}
|
485 |
+
if ( null !== $nbf_settings ) {
|
486 |
+
$information['nbf_settings'] = $nbf_settings;
|
487 |
+
$information['result'] = 'success';
|
488 |
+
}
|
489 |
+
return $information;
|
490 |
+
}
|
491 |
+
|
492 |
+
/**
|
493 |
+
* Validate directory.
|
494 |
+
*
|
495 |
+
* @param string $name Input name.
|
496 |
+
* @param string $folder Folder.
|
497 |
+
*
|
498 |
+
* @return bool|string Return TRUE on success or Error message on failure.
|
499 |
+
*
|
500 |
+
* @uses \ITSEC_Lib_Directory::is_dir()
|
501 |
+
* @uses \ITSEC_Lib_Directory::create()
|
502 |
+
* @uses \ITSEC_Lib_Directory::is_writable()
|
503 |
+
* @uses \ITSEC_Lib_Directory::add_file_listing_protection()
|
504 |
+
*/
|
505 |
+
private function validate_directory( $name, $folder ) {
|
506 |
+
require_once \ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
|
507 |
+
$error = null;
|
508 |
+
if ( ! \ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
509 |
+
$result = \ITSEC_Lib_Directory::create( $folder );
|
510 |
+
|
511 |
+
if ( is_wp_error( $result ) ) {
|
512 |
+
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', 'mainwp-child' ), $name, $result->get_error_message() );
|
513 |
+
}
|
514 |
+
}
|
515 |
+
|
516 |
+
if ( empty( $error ) && ! \ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
517 |
+
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', 'mainwp-child' ), $name );
|
518 |
+
}
|
519 |
+
|
520 |
+
if ( empty( $error ) ) {
|
521 |
+
\ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
522 |
+
return true;
|
523 |
+
} else {
|
524 |
+
return $error;
|
525 |
+
}
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Activate api key.
|
530 |
+
*
|
531 |
+
* @param array $settings Setting array.
|
532 |
+
*
|
533 |
+
* @return array|bool Return $settings array or FALSE on failure.
|
534 |
+
*
|
535 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::get_api_key()
|
536 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::activate_api_key()
|
537 |
+
* @uses \ITSEC_Response::reload_module()
|
538 |
+
*/
|
539 |
+
private function activate_api_key( $settings ) {
|
540 |
+
|
541 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
542 |
+
global $mainwp_itsec_modules_path;
|
543 |
+
|
544 |
+
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
|
545 |
+
|
546 |
+
$key = \ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
|
547 |
+
if ( is_wp_error( $key ) ) {
|
548 |
+
return false;
|
549 |
+
} else {
|
550 |
+
$secret = \ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
551 |
+
|
552 |
+
if ( is_wp_error( $secret ) ) {
|
553 |
+
return false;
|
554 |
+
} else {
|
555 |
+
$settings['api_key'] = $key;
|
556 |
+
$settings['api_secret'] = $secret;
|
557 |
+
|
558 |
+
$settings['api_nag'] = false;
|
559 |
+
|
560 |
+
\ITSEC_Response::reload_module( 'network-brute-force' );
|
561 |
+
}
|
562 |
+
}
|
563 |
+
unset( $settings['email'] );
|
564 |
+
return $settings;
|
565 |
+
}
|
566 |
+
|
567 |
+
/**
|
568 |
+
* Backup status.
|
569 |
+
*
|
570 |
+
* @return int $status 1, 2, 3 or 4
|
571 |
+
* (1) Is not a multisite installation, backupbuddy_api exists & Scheduled backups are >=1
|
572 |
+
* (2) Is not multisite and backupbuddy_api exists
|
573 |
+
* (3) Has backup = true & schedualed backup = true
|
574 |
+
* (4) Has backup = true.
|
575 |
+
*
|
576 |
+
* @uses \backupbuddy_api::getSchedules()
|
577 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
578 |
+
* @uses MainWP_Child_IThemes_Security::scheduled_backup()
|
579 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
580 |
+
*
|
581 |
+
*/
|
582 |
+
public function backup_status() {
|
583 |
+
$status = 0;
|
584 |
+
if ( ! is_multisite() && class_exists( '\backupbuddy_api' ) && count( \backupbuddy_api::getSchedules() ) >= 1 ) {
|
585 |
+
$status = 1;
|
586 |
+
} elseif ( ! is_multisite() && class_exists( '\backupbuddy_api' ) ) {
|
587 |
+
$status = 2;
|
588 |
+
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
589 |
+
$status = 3;
|
590 |
+
} elseif ( $this->has_backup() === true ) {
|
591 |
+
$status = 4;
|
592 |
+
}
|
593 |
+
|
594 |
+
return $status;
|
595 |
+
}
|
596 |
+
|
597 |
+
/**
|
598 |
+
* Check if backup exists.
|
599 |
+
*
|
600 |
+
* @return bool TRUE|FALSE
|
601 |
+
*/
|
602 |
+
public function has_backup() {
|
603 |
+
$has_backup = false;
|
604 |
+
|
605 |
+
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
606 |
+
}
|
607 |
+
|
608 |
+
/**
|
609 |
+
* Check if there is a shedualed backup.
|
610 |
+
*
|
611 |
+
* @return bool TRUE|FALSE.
|
612 |
+
*/
|
613 |
+
public function scheduled_backup() {
|
614 |
+
$sceduled_backup = false;
|
615 |
+
|
616 |
+
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
617 |
+
}
|
618 |
+
|
619 |
+
/**
|
620 |
+
* Whitelist Dashboard IP address.
|
621 |
+
*
|
622 |
+
* @return array|string[] Response array.
|
623 |
+
*/
|
624 |
+
public function whitelist() {
|
625 |
+
|
626 |
+
/** @global array $itsec_globals itsec globals. */
|
627 |
+
global $itsec_globals;
|
628 |
+
|
629 |
+
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
|
630 |
+
$add_temp = false;
|
631 |
+
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
632 |
+
if ( false !== $temp_ip ) {
|
633 |
+
if ( ( $temp_ip['exp'] < $itsec_globals['current_time'] ) || ( $temp_ip['exp'] !== $ip ) ) {
|
634 |
+
delete_site_option( 'itsec_temp_whitelist_ip' );
|
635 |
+
$add_temp = true;
|
636 |
+
}
|
637 |
+
} else {
|
638 |
+
$add_temp = true;
|
639 |
+
}
|
640 |
+
|
641 |
+
if ( false === $add_temp ) {
|
642 |
+
return array( 'error' => 'Not Updated' );
|
643 |
+
} else {
|
644 |
+
$response = array(
|
645 |
+
'ip' => $ip,
|
646 |
+
'exp' => $itsec_globals['current_time'] + 86400,
|
647 |
+
);
|
648 |
+
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
649 |
+
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
650 |
+
$response['message1'] = __( 'Your IP Address', 'mainwp-child' );
|
651 |
+
$response['message2'] = __( 'is whitelisted for', 'mainwp-child' );
|
652 |
+
|
653 |
+
return $response;
|
654 |
+
}
|
655 |
+
}
|
656 |
+
|
657 |
+
/**
|
658 |
+
* Whitelist release.
|
659 |
+
*
|
660 |
+
* @return string Return 'Success'.
|
661 |
+
*/
|
662 |
+
public function whitelist_release() {
|
663 |
+
delete_site_option( 'itsec_temp_whitelist_ip' );
|
664 |
+
|
665 |
+
return 'success';
|
666 |
+
}
|
667 |
+
|
668 |
+
/**
|
669 |
+
* Backup Database.
|
670 |
+
*
|
671 |
+
* @return array $return Return results array.
|
672 |
+
*
|
673 |
+
* @uses \ITSEC_Backup()
|
674 |
+
* @uses \ITSEC_Backup::run()
|
675 |
+
* @uses \ITSEC_Backup::do_backup()
|
676 |
+
* @uses \ITSEC_Response::get_error_strings()
|
677 |
+
*/
|
678 |
+
public function backup_db() {
|
679 |
+
|
680 |
+
/**
|
681 |
+
* @global string $mainwp_itsec_modules_path MainWP itsec modules path.
|
682 |
+
* @global object $itsec_backup ITsec backup class.
|
683 |
+
*/
|
684 |
+
global $itsec_backup, $mainwp_itsec_modules_path;
|
685 |
+
|
686 |
+
if ( ! isset( $itsec_backup ) ) {
|
687 |
+
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
|
688 |
+
$itsec_backup = new \ITSEC_Backup();
|
689 |
+
$itsec_backup->run();
|
690 |
+
}
|
691 |
+
|
692 |
+
$return = array();
|
693 |
+
|
694 |
+
$str_error = '';
|
695 |
+
$result = $itsec_backup->do_backup( true );
|
696 |
+
|
697 |
+
if ( is_wp_error( $result ) ) {
|
698 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
699 |
+
|
700 |
+
foreach ( $errors as $error ) {
|
701 |
+
$str_error .= $error . '<br />';
|
702 |
+
}
|
703 |
+
} elseif ( is_string( $result ) ) {
|
704 |
+
$return['result'] = 'success';
|
705 |
+
$return['message'] = $result;
|
706 |
+
} else {
|
707 |
+
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'mainwp-child' ), gettype( $result ) );
|
708 |
+
}
|
709 |
+
|
710 |
+
if ( ! empty( $str_error ) ) {
|
711 |
+
$return['error'] = $str_error;
|
712 |
+
}
|
713 |
+
|
714 |
+
return $return;
|
715 |
+
}
|
716 |
+
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Update WordPress Salts.
|
720 |
+
*
|
721 |
+
* @return array $return Return results array.
|
722 |
+
*
|
723 |
+
* @uses \ITSEC_WordPress_Salts_Utilities::generate_new_salts()
|
724 |
+
* @uses \ITSEC_Response::get_error_strings()
|
725 |
+
* @uses \ITSEC_Core::get_current_time_gmt()
|
726 |
+
* @uses \ITSEC_Modules::set_setting()
|
727 |
+
*/
|
728 |
+
private function wordpress_salts() {
|
729 |
+
|
730 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
731 |
+
global $mainwp_itsec_modules_path;
|
732 |
+
|
733 |
+
if ( ! class_exists( '\ITSEC_WordPress_Salts_Utilities' ) ) {
|
734 |
+
require $mainwp_itsec_modules_path . 'salts/utilities.php';
|
735 |
+
}
|
736 |
+
$result = \ITSEC_WordPress_Salts_Utilities::generate_new_salts();
|
737 |
+
$str_error = '';
|
738 |
+
if ( is_wp_error( $result ) ) {
|
739 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
740 |
+
|
741 |
+
foreach ( $errors as $error ) {
|
742 |
+
$str_error .= $error . '<br />';
|
743 |
+
}
|
744 |
+
} else {
|
745 |
+
$return['result'] = 'success';
|
746 |
+
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'mainwp-child' );
|
747 |
+
$last_generated = \ITSEC_Core::get_current_time_gmt();
|
748 |
+
\ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
749 |
+
}
|
750 |
+
if ( ! empty( $str_error ) ) {
|
751 |
+
$return['error'] = $str_error;
|
752 |
+
}
|
753 |
+
return $return;
|
754 |
+
}
|
755 |
+
|
756 |
+
/**
|
757 |
+
* Update file permissions.
|
758 |
+
*
|
759 |
+
* @return array Return results table html.
|
760 |
+
*
|
761 |
+
* @uses \ITSEC_Core::get_wp_upload_dir()
|
762 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config_file_path()
|
763 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config_file_path()
|
764 |
+
*/
|
765 |
+
private function file_permissions() {
|
766 |
+
|
767 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
768 |
+
|
769 |
+
$wp_upload_dir = \ITSEC_Core::get_wp_upload_dir();
|
770 |
+
|
771 |
+
$path_data = array(
|
772 |
+
array(
|
773 |
+
ABSPATH,
|
774 |
+
0755,
|
775 |
+
),
|
776 |
+
array(
|
777 |
+
ABSPATH . WPINC,
|
778 |
+
0755,
|
779 |
+
),
|
780 |
+
array(
|
781 |
+
ABSPATH . 'wp-admin',
|
782 |
+
0755,
|
783 |
+
),
|
784 |
+
array(
|
785 |
+
ABSPATH . 'wp-admin/js',
|
786 |
+
0755,
|
787 |
+
),
|
788 |
+
array(
|
789 |
+
WP_CONTENT_DIR,
|
790 |
+
0755,
|
791 |
+
),
|
792 |
+
array(
|
793 |
+
get_theme_root(),
|
794 |
+
0755,
|
795 |
+
),
|
796 |
+
array(
|
797 |
+
WP_PLUGIN_DIR,
|
798 |
+
0755,
|
799 |
+
),
|
800 |
+
array(
|
801 |
+
$wp_upload_dir['basedir'],
|
802 |
+
0755,
|
803 |
+
),
|
804 |
+
array(
|
805 |
+
\ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
806 |
+
0444,
|
807 |
+
),
|
808 |
+
array(
|
809 |
+
\ITSEC_Lib_Config_File::get_server_config_file_path(),
|
810 |
+
0444,
|
811 |
+
),
|
812 |
+
);
|
813 |
+
|
814 |
+
$rows = array();
|
815 |
+
|
816 |
+
foreach ( $path_data as $path ) {
|
817 |
+
$row = array();
|
818 |
+
|
819 |
+
list( $path, $suggested_permissions ) = $path;
|
820 |
+
|
821 |
+
$display_path = preg_replace( '/^' . preg_quote( ABSPATH, '/' ) . '/', '', $path );
|
822 |
+
$display_path = ltrim( $display_path, '/' );
|
823 |
+
|
824 |
+
if ( empty( $display_path ) ) {
|
825 |
+
$display_path = '/';
|
826 |
+
}
|
827 |
+
|
828 |
+
$row[] = $display_path;
|
829 |
+
$row[] = sprintf( '%o', $suggested_permissions );
|
830 |
+
|
831 |
+
$permissions = fileperms( $path ) & 0777;
|
832 |
+
$row[] = sprintf( '%o', $permissions );
|
833 |
+
|
834 |
+
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
835 |
+
$row[] = __( 'WARNING', 'mainwp-child' );
|
836 |
+
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
837 |
+
} else {
|
838 |
+
$row[] = __( 'OK', 'mainwp-child' );
|
839 |
+
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
840 |
+
}
|
841 |
+
|
842 |
+
$rows[] = $row;
|
843 |
+
}
|
844 |
+
|
845 |
+
$class = 'entry-row';
|
846 |
+
ob_start();
|
847 |
+
?>
|
848 |
+
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php esc_attr_e( 'Reload File Permissions Details', 'mainwp-child' ); ?>"></p>
|
849 |
+
<table class="widefat">
|
850 |
+
<thead>
|
851 |
+
<tr>
|
852 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
853 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
854 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
855 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
856 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
857 |
+
</tr>
|
858 |
+
</thead>
|
859 |
+
<tfoot>
|
860 |
+
<tr>
|
861 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
862 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
863 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
864 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
865 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
866 |
+
</tr>
|
867 |
+
</tfoot>
|
868 |
+
<tbody>
|
869 |
+
<?php foreach ( $rows as $row ) : ?>
|
870 |
+
<tr class="<?php echo $class; ?>">
|
871 |
+
<?php foreach ( $row as $column ) : ?>
|
872 |
+
<td><?php echo $column; ?></td>
|
873 |
+
<?php endforeach; ?>
|
874 |
+
</tr>
|
875 |
+
<?php $class = ( 'entry-row' === $class ) ? 'entry-row alternate' : 'entry-row'; ?>
|
876 |
+
<?php endforeach; ?>
|
877 |
+
</tbody>
|
878 |
+
</table>
|
879 |
+
<br />
|
880 |
+
<?php
|
881 |
+
$html = ob_get_clean();
|
882 |
+
return array( 'html' => $html );
|
883 |
+
}
|
884 |
+
|
885 |
+
/**
|
886 |
+
* Run File Change scanner.
|
887 |
+
*
|
888 |
+
* @return array $return results array.
|
889 |
+
*
|
890 |
+
* @uses \ITSEC_File_Change_Scanner::run_scan()
|
891 |
+
*/
|
892 |
+
public function file_change() {
|
893 |
+
|
894 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
895 |
+
global $mainwp_itsec_modules_path;
|
896 |
+
|
897 |
+
if ( ! class_exists( '\ITSEC_File_Change_Scanner' ) ) {
|
898 |
+
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
|
899 |
+
}
|
900 |
+
$result = \ITSEC_File_Change_Scanner::run_scan( false );
|
901 |
+
if ( false === $result || true === $result || -1 === $result ) {
|
902 |
+
$return['result'] = 'success';
|
903 |
+
$return['scan_result'] = $result;
|
904 |
+
}
|
905 |
+
return $return;
|
906 |
+
}
|
907 |
+
|
908 |
+
/**
|
909 |
+
* Update admin user.
|
910 |
+
*
|
911 |
+
* @return array Return Success or Fail.
|
912 |
+
*
|
913 |
+
* @uses \ITSEC_Lib::user_id_exists()
|
914 |
+
* @uses MainWP_Child_IThemes_Security::change_admin_user()
|
915 |
+
*/
|
916 |
+
public function admin_user() {
|
917 |
+
|
918 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
919 |
+
|
920 |
+
if ( ! is_array( $settings ) ) {
|
921 |
+
$settings = array();
|
922 |
+
}
|
923 |
+
|
924 |
+
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
|
925 |
+
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
|
926 |
+
|
927 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
928 |
+
|
929 |
+
/** @global object $itsec_globals ITsec globals. */
|
930 |
+
global $itsec_globals;
|
931 |
+
|
932 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
933 |
+
}
|
934 |
+
|
935 |
+
$username_exists = username_exists( 'admin' );
|
936 |
+
$user_id_exists = \ITSEC_Lib::user_id_exists( 1 );
|
937 |
+
$msg = '';
|
938 |
+
if ( strlen( $new_username ) >= 1 ) {
|
939 |
+
|
940 |
+
/** @global string $current_user Current user global variable. */
|
941 |
+
global $current_user;
|
942 |
+
|
943 |
+
if ( ! $username_exists ) {
|
944 |
+
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
945 |
+
} elseif ( 'admin' == $current_user->user_login ) {
|
946 |
+
$return['result'] = 'CHILD_ADMIN';
|
947 |
+
return $return;
|
948 |
+
}
|
949 |
+
}
|
950 |
+
|
951 |
+
if ( true === $change_id && ! $user_id_exists ) {
|
952 |
+
if ( ! empty( $msg ) ) {
|
953 |
+
$msg .= '<br/>';
|
954 |
+
}
|
955 |
+
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
956 |
+
}
|
957 |
+
|
958 |
+
$admin_success = true;
|
959 |
+
$return = array();
|
960 |
+
|
961 |
+
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
962 |
+
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
963 |
+
} elseif ( true === $change_id && $user_id_exists ) {
|
964 |
+
$admin_success = $this->change_admin_user( null, $change_id );
|
965 |
+
}
|
966 |
+
|
967 |
+
$return['message'] = $msg;
|
968 |
+
if ( false === $admin_success ) {
|
969 |
+
$return['result'] = 'fail';
|
970 |
+
} else {
|
971 |
+
$return['result'] = 'success';
|
972 |
+
}
|
973 |
+
return $return;
|
974 |
+
}
|
975 |
+
|
976 |
+
/**
|
977 |
+
* Change admin user.
|
978 |
+
*
|
979 |
+
* @param string $username Username to update to. Default: null.
|
980 |
+
* @param bool $id User Id found. Default: false.
|
981 |
+
* @return bool Return TRUE on success and FALSE on failure.
|
982 |
+
*
|
983 |
+
* @uses \ITSEC_Core::get_itsec_files()
|
984 |
+
* @uses \ITSEC_Core::get_itsec_files::release_file_lock()
|
985 |
+
*/
|
986 |
+
private function change_admin_user($username = null, $id = false ) {
|
987 |
+
|
988 |
+
/** @global object $wpdb WordPress Database */
|
989 |
+
global $wpdb;
|
990 |
+
|
991 |
+
$itsec_files = \ITSEC_Core::get_itsec_files();
|
992 |
+
|
993 |
+
$new_user = sanitize_text_field( $username );
|
994 |
+
|
995 |
+
$user_object = get_user_by( 'id', '1' );
|
996 |
+
|
997 |
+
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) {
|
998 |
+
|
999 |
+
if ( true === $id ) {
|
1000 |
+
|
1001 |
+
$user_login = $new_user;
|
1002 |
+
|
1003 |
+
} else {
|
1004 |
+
|
1005 |
+
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
1006 |
+
|
1007 |
+
if ( is_multisite() ) {
|
1008 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1009 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1010 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
wp_clear_auth_cookie();
|
1014 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1015 |
+
|
1016 |
+
return true;
|
1017 |
+
|
1018 |
+
}
|
1019 |
+
} elseif ( null !== $username ) {
|
1020 |
+
|
1021 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1022 |
+
|
1023 |
+
return false;
|
1024 |
+
|
1025 |
+
} else {
|
1026 |
+
|
1027 |
+
$user_login = $user_object->user_login;
|
1028 |
+
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
if ( true === $id ) {
|
1032 |
+
|
1033 |
+
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
|
1034 |
+
|
1035 |
+
$wpdb->insert(
|
1036 |
+
$wpdb->users,
|
1037 |
+
array(
|
1038 |
+
'user_login' => $user_login,
|
1039 |
+
'user_pass' => $user_object->user_pass,
|
1040 |
+
'user_nicename' => $user_object->user_nicename,
|
1041 |
+
'user_email' => $user_object->user_email,
|
1042 |
+
'user_url' => $user_object->user_url,
|
1043 |
+
'user_registered' => $user_object->user_registered,
|
1044 |
+
'user_activation_key' => $user_object->user_activation_key,
|
1045 |
+
'user_status' => $user_object->user_status,
|
1046 |
+
'display_name' => $user_object->display_name,
|
1047 |
+
)
|
1048 |
+
);
|
1049 |
+
|
1050 |
+
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) {
|
1051 |
+
|
1052 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1053 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1054 |
+
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
|
1055 |
+
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
$new_user = $wpdb->insert_id;
|
1059 |
+
|
1060 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
|
1061 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1062 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1063 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
|
1064 |
+
|
1065 |
+
wp_clear_auth_cookie();
|
1066 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1067 |
+
|
1068 |
+
return true;
|
1069 |
+
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
return false;
|
1073 |
+
}
|
1074 |
+
|
1075 |
+
/**
|
1076 |
+
* Build WP_config rules.
|
1077 |
+
*
|
1078 |
+
* @param array $rules_array Config rules array.
|
1079 |
+
* @param null $input New directory input.
|
1080 |
+
*
|
1081 |
+
* @return array Return $rules_array.
|
1082 |
+
*/
|
1083 |
+
public function build_wpconfig_rules( $rules_array, $input = null ) {
|
1084 |
+
if ( null === $input ) {
|
1085 |
+
return $rules_array;
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
$new_dir = trailingslashit( ABSPATH ) . $input;
|
1089 |
+
|
1090 |
+
$rules[] = array(
|
1091 |
+
'type' => 'add',
|
1092 |
+
'search_text' => '//Do not delete these. Doing so WILL break your site.',
|
1093 |
+
'rule' => '//Do not delete these. Doing so WILL break your site.',
|
1094 |
+
);
|
1095 |
+
|
1096 |
+
$rules[] = array(
|
1097 |
+
'type' => 'add',
|
1098 |
+
'search_text' => 'WP_CONTENT_URL',
|
1099 |
+
'rule' => "define( 'WP_CONTENT_URL', '" . trailingslashit( get_option( 'siteurl' ) ) . $input . "' );",
|
1100 |
+
);
|
1101 |
+
|
1102 |
+
$rules[] = array(
|
1103 |
+
'type' => 'add',
|
1104 |
+
'search_text' => 'WP_CONTENT_DIR',
|
1105 |
+
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
1106 |
+
);
|
1107 |
+
|
1108 |
+
$rules_array[] = array(
|
1109 |
+
'type' => 'wpconfig',
|
1110 |
+
'name' => 'Content Directory',
|
1111 |
+
'rules' => $rules,
|
1112 |
+
);
|
1113 |
+
|
1114 |
+
return $rules_array;
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
|
1118 |
+
/**
|
1119 |
+
* Change database prefix.
|
1120 |
+
*
|
1121 |
+
* @return array $return Return response array.
|
1122 |
+
*
|
1123 |
+
* @uses \ITSEC_Database_Prefix_Utility::change_database_prefix()
|
1124 |
+
* @uses \ITSEC_Response::get_error_strings()
|
1125 |
+
* @uses \ITSEC_Response::reload_module()
|
1126 |
+
*/
|
1127 |
+
public function change_database_prefix() {
|
1128 |
+
|
1129 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1130 |
+
global $mainwp_itsec_modules_path;
|
1131 |
+
|
1132 |
+
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
|
1133 |
+
$str_error = '';
|
1134 |
+
$return = array();
|
1135 |
+
|
1136 |
+
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
1137 |
+
$result = \ITSEC_Database_Prefix_Utility::change_database_prefix();
|
1138 |
+
$return = $result['errors'];
|
1139 |
+
if ( is_array( $result['errors'] ) ) {
|
1140 |
+
foreach ( $result['errors'] as $error ) {
|
1141 |
+
$arr_errors = \ITSEC_Response::get_error_strings( $error );
|
1142 |
+
foreach ( $arr_errors as $er ) {
|
1143 |
+
$str_error .= $er . '<br />';
|
1144 |
+
}
|
1145 |
+
}
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
\ITSEC_Response::reload_module( 'database-prefix' );
|
1149 |
+
|
1150 |
+
if ( false === $result['new_prefix'] ) {
|
1151 |
+
$return['error'] = $str_error;
|
1152 |
+
} else {
|
1153 |
+
$return['result'] = 'success';
|
1154 |
+
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'mainwp-child' ), $result['new_prefix'] );
|
1155 |
+
|
1156 |
+
}
|
1157 |
+
}
|
1158 |
+
return $return;
|
1159 |
+
}
|
1160 |
+
|
1161 |
+
/**
|
1162 |
+
* Update API key.
|
1163 |
+
*
|
1164 |
+
* @return array $return Return response array. Success or nochange.
|
1165 |
+
*/
|
1166 |
+
public function api_key() {
|
1167 |
+
$settings = get_site_option( 'itsec_ipcheck' );
|
1168 |
+
if ( ! is_array( $settings ) ) {
|
1169 |
+
$settings = array();
|
1170 |
+
}
|
1171 |
+
$settings['reset'] = true;
|
1172 |
+
$return = array();
|
1173 |
+
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
1174 |
+
$return['result'] = 'success';
|
1175 |
+
} else {
|
1176 |
+
$return['result'] = 'nochange';
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
return $return;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
/**
|
1183 |
+
* Reset api key.
|
1184 |
+
*
|
1185 |
+
* @return array $information Return response array.
|
1186 |
+
*
|
1187 |
+
* @uses \ITSEC_Modules::get_defaults()
|
1188 |
+
* @uses \ITSEC_Modules::set_defaults()
|
1189 |
+
* @uses \ITSEC_Response::set_response()
|
1190 |
+
* @uses \ITSEC_Response::add_errors()
|
1191 |
+
* @uses \ITSEC_Response::add_messages()
|
1192 |
+
*/
|
1193 |
+
public function reset_api_key() {
|
1194 |
+
|
1195 |
+
$defaults = \ITSEC_Modules::get_defaults( 'network-brute-force' );
|
1196 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
|
1197 |
+
|
1198 |
+
\ITSEC_Response::set_response( $results['saved'] );
|
1199 |
+
\ITSEC_Response::add_errors( $results['errors'] );
|
1200 |
+
\ITSEC_Response::add_messages( $results['messages'] );
|
1201 |
+
|
1202 |
+
$information = array();
|
1203 |
+
if ( $results['saved'] ) {
|
1204 |
+
$information['result'] = 'success';
|
1205 |
+
$information['nbf_settings'] = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
1206 |
+
} elseif ( empty( $results['errors'] ) ) {
|
1207 |
+
$information['error_reset_api'] = 1;
|
1208 |
+
}
|
1209 |
+
return $information;
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
/**
|
1213 |
+
* Malware scan.
|
1214 |
+
*
|
1215 |
+
* @return array $response Return response array.
|
1216 |
+
*
|
1217 |
+
* @uses \ITSEC_Core::current_user_can_manage()
|
1218 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1219 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1220 |
+
*/
|
1221 |
+
public function malware_scan() {
|
1222 |
+
|
1223 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1224 |
+
global $mainwp_itsec_modules_path;
|
1225 |
+
|
1226 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1227 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1228 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1229 |
+
}
|
1230 |
+
|
1231 |
+
$response = array();
|
1232 |
+
if ( ! \ITSEC_Core::current_user_can_manage() ) {
|
1233 |
+
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
1234 |
+
} else {
|
1235 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1236 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1237 |
+
}
|
1238 |
+
|
1239 |
+
return $response;
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
/**
|
1243 |
+
* Get malware scan results.
|
1244 |
+
*
|
1245 |
+
* @return array $response Return response array.
|
1246 |
+
*
|
1247 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1248 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1249 |
+
*/
|
1250 |
+
public function malware_get_scan_results() {
|
1251 |
+
|
1252 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1253 |
+
global $mainwp_itsec_modules_path;
|
1254 |
+
|
1255 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1256 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1257 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1258 |
+
}
|
1259 |
+
$response = array();
|
1260 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1261 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1262 |
+
return $response;
|
1263 |
+
}
|
1264 |
+
|
1265 |
+
/**
|
1266 |
+
* Purge logs.
|
1267 |
+
*
|
1268 |
+
* @return string[] Return response array.
|
1269 |
+
*/
|
1270 |
+
public function purge_logs() {
|
1271 |
+
|
1272 |
+
/** @global object $wpdb WordPress Database object. */
|
1273 |
+
global $wpdb;
|
1274 |
+
|
1275 |
+
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
1276 |
+
|
1277 |
+
return array( 'result' => 'success' );
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
|
1281 |
+
/**
|
1282 |
+
* Get lockouts.
|
1283 |
+
*
|
1284 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1285 |
+
* @param bool $current TRUE if current. Default: FALSE.
|
1286 |
+
*
|
1287 |
+
* @return array $output Return response array.
|
1288 |
+
*
|
1289 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts_int()
|
1290 |
+
*/
|
1291 |
+
public function get_lockouts( $type = 'all', $current = false ) {
|
1292 |
+
|
1293 |
+
/**
|
1294 |
+
* @global object $wpdb WordPress Database object.
|
1295 |
+
* @global object $itsec_globals itsec globals.
|
1296 |
+
*/
|
1297 |
+
global $wpdb, $itsec_globals;
|
1298 |
+
|
1299 |
+
if ( 'all' !== $type || true === $current ) {
|
1300 |
+
$where = ' WHERE ';
|
1301 |
+
} else {
|
1302 |
+
$where = '';
|
1303 |
+
}
|
1304 |
+
|
1305 |
+
switch ( $type ) {
|
1306 |
+
|
1307 |
+
case 'host':
|
1308 |
+
$type_statement = "`lockout_host` IS NOT NULL && `lockout_host` != ''";
|
1309 |
+
break;
|
1310 |
+
case 'user':
|
1311 |
+
$type_statement = '`lockout_user` != 0';
|
1312 |
+
break;
|
1313 |
+
case 'username':
|
1314 |
+
$type_statement = "`lockout_username` IS NOT NULL && `lockout_username` != ''";
|
1315 |
+
break;
|
1316 |
+
default:
|
1317 |
+
$type_statement = '';
|
1318 |
+
break;
|
1319 |
+
|
1320 |
+
}
|
1321 |
+
|
1322 |
+
if ( true === $current ) {
|
1323 |
+
|
1324 |
+
if ( '' !== $type_statement ) {
|
1325 |
+
$and = ' AND ';
|
1326 |
+
} else {
|
1327 |
+
$and = '';
|
1328 |
+
}
|
1329 |
+
|
1330 |
+
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" . gmdate( 'Y-m-d H:i:s', $itsec_globals['current_time_gmt'] ) . "'";
|
1331 |
+
|
1332 |
+
} else {
|
1333 |
+
|
1334 |
+
$active = '';
|
1335 |
+
|
1336 |
+
}
|
1337 |
+
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
1338 |
+
|
1339 |
+
return $this->get_lockouts_int( $results, $type );
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
/**
|
1343 |
+
* Initiate get lockouts.
|
1344 |
+
*
|
1345 |
+
* @param array $results Results from MainWP_Child_IThemes_Security::get_lockouts()
|
1346 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1347 |
+
*
|
1348 |
+
* @return array $output Return response array.
|
1349 |
+
*/
|
1350 |
+
private function get_lockouts_int($results, $type ){
|
1351 |
+
|
1352 |
+
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1353 |
+
switch ( $type ) {
|
1354 |
+
case 'host':
|
1355 |
+
foreach ( $results as $val ) {
|
1356 |
+
$output[] = array(
|
1357 |
+
'lockout_id' => $val['lockout_id'],
|
1358 |
+
'lockout_host' => $val['lockout_host'],
|
1359 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1360 |
+
);
|
1361 |
+
}
|
1362 |
+
break;
|
1363 |
+
case 'user':
|
1364 |
+
foreach ( $results as $val ) {
|
1365 |
+
$output[] = array(
|
1366 |
+
'lockout_id' => $val['lockout_id'],
|
1367 |
+
'lockout_user' => $val['lockout_user'],
|
1368 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1369 |
+
);
|
1370 |
+
}
|
1371 |
+
break;
|
1372 |
+
case 'username':
|
1373 |
+
foreach ( $results as $val ) {
|
1374 |
+
$output[] = array(
|
1375 |
+
'lockout_id' => $val['lockout_id'],
|
1376 |
+
'lockout_username' => $val['lockout_username'],
|
1377 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1378 |
+
);
|
1379 |
+
}
|
1380 |
+
break;
|
1381 |
+
default:
|
1382 |
+
break;
|
1383 |
+
}
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
return $output;
|
1387 |
+
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
/**
|
1391 |
+
* Release lockout.
|
1392 |
+
*
|
1393 |
+
* @return string[] Return results array.
|
1394 |
+
*
|
1395 |
+
* @uses \ITSEC_Lib::clear_caches()
|
1396 |
+
*/
|
1397 |
+
public function release_lockout() {
|
1398 |
+
|
1399 |
+
/** @global object $wpdb WordPress Database. */
|
1400 |
+
global $wpdb;
|
1401 |
+
|
1402 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
1403 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
$lockout_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['lockout_ids'] ) );
|
1407 |
+
if ( ! is_array( $lockout_ids ) ) {
|
1408 |
+
$lockout_ids = array();
|
1409 |
+
}
|
1410 |
+
|
1411 |
+
$type = 'updated';
|
1412 |
+
$message = __( 'The selected lockouts have been cleared.', 'mainwp-child' );
|
1413 |
+
|
1414 |
+
foreach ( $lockout_ids as $value ) {
|
1415 |
+
$wpdb->update(
|
1416 |
+
$wpdb->base_prefix . 'itsec_lockouts',
|
1417 |
+
array(
|
1418 |
+
'lockout_active' => 0,
|
1419 |
+
),
|
1420 |
+
array(
|
1421 |
+
'lockout_id' => intval( $value ),
|
1422 |
+
)
|
1423 |
+
);
|
1424 |
+
}
|
1425 |
+
|
1426 |
+
\ITSEC_Lib::clear_caches();
|
1427 |
+
|
1428 |
+
if ( ! is_multisite() ) {
|
1429 |
+
if ( ! function_exists( 'add_settings_error' ) ) {
|
1430 |
+
require_once ABSPATH . '/wp-admin/includes/template.php';
|
1431 |
+
}
|
1432 |
+
|
1433 |
+
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
1434 |
+
}
|
1435 |
+
|
1436 |
+
return array(
|
1437 |
+
'result' => 'success',
|
1438 |
+
);
|
1439 |
+
}
|
1440 |
+
|
1441 |
+
/**
|
1442 |
+
* Update module status.
|
1443 |
+
*
|
1444 |
+
* @return string[] Return response array.
|
1445 |
+
*/
|
1446 |
+
public function update_module_status() {
|
1447 |
+
|
1448 |
+
$active_modules = isset( $_POST['active_modules'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['active_modules'] ) ) : array();
|
1449 |
+
|
1450 |
+
if ( ! is_array( $active_modules ) ) {
|
1451 |
+
$active_modules = array();
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
1455 |
+
foreach ( $active_modules as $mod => $val ) {
|
1456 |
+
$current_val[ $mod ] = $val;
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
update_site_option( 'itsec_active_modules', $current_val );
|
1460 |
+
return array( 'result' => 'success' );
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
/**
|
1464 |
+
* Reload excluded backups table.
|
1465 |
+
*
|
1466 |
+
* @return array Return response array.
|
1467 |
+
*
|
1468 |
+
* @uses \ITSEC_Modules::get_setting()
|
1469 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
1470 |
+
*/
|
1471 |
+
private function reload_backup_exclude() {
|
1472 |
+
return array(
|
1473 |
+
'exclude' => \ITSEC_Modules::get_setting( 'backup', 'exclude' ),
|
1474 |
+
'excludable_tables' => $this->get_excludable_tables(),
|
1475 |
+
'result' => 'success',
|
1476 |
+
);
|
1477 |
+
}
|
1478 |
+
|
1479 |
+
/**
|
1480 |
+
* Get excludable backups table.
|
1481 |
+
*
|
1482 |
+
* @return array $excludes Return response array.
|
1483 |
+
*
|
1484 |
+
* @uses \ITSEC_Modules::get_setting()
|
1485 |
+
*/
|
1486 |
+
private function get_excludable_tables() {
|
1487 |
+
|
1488 |
+
/** @global object $wpdb WordPress Database. */
|
1489 |
+
global $wpdb;
|
1490 |
+
|
1491 |
+
$all_sites = \ITSEC_Modules::get_setting( 'backup', 'all_sites' );
|
1492 |
+
$ignored_tables = array(
|
1493 |
+
'commentmeta',
|
1494 |
+
'comments',
|
1495 |
+
'links',
|
1496 |
+
'options',
|
1497 |
+
'postmeta',
|
1498 |
+
'posts',
|
1499 |
+
'term_relationships',
|
1500 |
+
'term_taxonomy',
|
1501 |
+
'terms',
|
1502 |
+
'usermeta',
|
1503 |
+
'users',
|
1504 |
+
);
|
1505 |
+
|
1506 |
+
if ( $all_sites ) {
|
1507 |
+
$query = 'SHOW TABLES';
|
1508 |
+
} else {
|
1509 |
+
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1510 |
+
}
|
1511 |
+
|
1512 |
+
$tables = $wpdb->get_results( $query, ARRAY_N ); // phpcs:ignore -- safe query.
|
1513 |
+
$excludes = array();
|
1514 |
+
|
1515 |
+
foreach ( $tables as $table ) {
|
1516 |
+
$short_table = substr( $table[0], strlen( $wpdb->prefix ) );
|
1517 |
+
|
1518 |
+
if ( in_array( $short_table, $ignored_tables ) ) {
|
1519 |
+
continue;
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
$excludes[ $short_table ] = $table[0];
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
return $excludes;
|
1526 |
+
}
|
1527 |
+
|
1528 |
+
/**
|
1529 |
+
* Get security check results.
|
1530 |
+
*
|
1531 |
+
* @return array Return response array.
|
1532 |
+
*
|
1533 |
+
* @uses \ITSEC_Security_Check_Scanner::get_results()
|
1534 |
+
* @uses \ITSEC_Security_Check_Feedback_Renderer::render(
|
1535 |
+
*/
|
1536 |
+
private function security_site() {
|
1537 |
+
|
1538 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1539 |
+
global $mainwp_itsec_modules_path;
|
1540 |
+
|
1541 |
+
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
|
1542 |
+
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
|
1543 |
+
$results = \ITSEC_Security_Check_Scanner::get_results();
|
1544 |
+
ob_start();
|
1545 |
+
\ITSEC_Security_Check_Feedback_Renderer::render( $results );
|
1546 |
+
$response = ob_get_clean();
|
1547 |
+
return array(
|
1548 |
+
'result' => 'success',
|
1549 |
+
'response' => $response,
|
1550 |
+
);
|
1551 |
+
}
|
1552 |
+
|
1553 |
+
/**
|
1554 |
+
* Get available admin users and roles.
|
1555 |
+
*
|
1556 |
+
* @return array[] Return response array.phpdoc
|
1557 |
+
*
|
1558 |
+
* @uses \WP_Roles()
|
1559 |
+
*/
|
1560 |
+
public function get_available_admin_users_and_roles() {
|
1561 |
+
if ( is_callable( 'wp_roles' ) ) {
|
1562 |
+
$roles = wp_roles();
|
1563 |
+
} else {
|
1564 |
+
$roles = new \WP_Roles();
|
1565 |
+
}
|
1566 |
+
|
1567 |
+
$available_roles = array();
|
1568 |
+
$available_users = array();
|
1569 |
+
|
1570 |
+
foreach ( $roles->roles as $role => $details ) {
|
1571 |
+
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1572 |
+
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
|
1573 |
+
|
1574 |
+
$users = get_users( array( 'role' => $role ) );
|
1575 |
+
|
1576 |
+
foreach ( $users as $user ) {
|
1577 |
+
/* translators: 1: user display name, 2: user login */
|
1578 |
+
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', 'mainwp-child' ), $user->display_name, $user->user_login );
|
1579 |
+
}
|
1580 |
+
}
|
1581 |
+
}
|
1582 |
+
|
1583 |
+
natcasesort( $available_users );
|
1584 |
+
|
1585 |
+
return array(
|
1586 |
+
'users' => $available_users,
|
1587 |
+
'roles' => $available_roles,
|
1588 |
+
);
|
1589 |
+
}
|
1590 |
+
|
1591 |
+
}
|
class/class-mainwp-child-links-checker.php
CHANGED
@@ -1,854 +1,876 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Links Checker
|
4 |
-
*
|
5 |
-
* This file handles all of the actions for the Broken Link Checker Extension.
|
6 |
-
*
|
7 |
-
* @deprecated This Extension has been Retired @since January 2020
|
8 |
-
* @link https://mainwp.com/retired-extensions/
|
9 |
-
*/
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Credits
|
13 |
-
*
|
14 |
-
* Plugin-Name: Broken Link Checker
|
15 |
-
* Plugin URI: https://wordpress.org/plugins/broken-link-checker/
|
16 |
-
* Author: Janis Elsts, Vladimir Prelovac
|
17 |
-
*
|
18 |
-
* The code is used for the MainWP Broken Links Checker Extension (Retired Extension)
|
19 |
-
*/
|
20 |
-
|
21 |
-
namespace MainWP\Child;
|
22 |
-
|
23 |
-
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Class MainWP_Child_Links_Checker
|
27 |
-
*/
|
28 |
-
class MainWP_Child_Links_Checker {
|
29 |
-
|
30 |
-
/**
|
31 |
-
* @static
|
32 |
-
* @var null Holds the Public static instance of MainWP_Child_Links_Checker.
|
33 |
-
*/
|
34 |
-
public static $instance = null;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* @var bool Whether or not the Broken Links Checker Extension is installed. Default: false.
|
38 |
-
*/
|
39 |
-
public $is_plugin_installed = false;
|
40 |
-
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Get Class Name
|
44 |
-
*
|
45 |
-
* @return string __CLASS__
|
46 |
-
*/
|
47 |
-
public static function get_class_name() {
|
48 |
-
return __CLASS__;
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Create a public static instance of MainWP_Child_Links_Checker.
|
53 |
-
*
|
54 |
-
* @return MainWP_Child_Links_Checker|null
|
55 |
-
*/
|
56 |
-
public static function instance() {
|
57 |
-
if ( null === self::$instance ) {
|
58 |
-
self::$instance = new self();
|
59 |
-
}
|
60 |
-
|
61 |
-
return self::$instance;
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* MainWP_Child_Links_Checker constructor.
|
66 |
-
*
|
67 |
-
* Run any time class is called.
|
68 |
-
*/
|
69 |
-
public function __construct() {
|
70 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
71 |
-
if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) {
|
72 |
-
$this->is_plugin_installed = true;
|
73 |
-
}
|
74 |
-
|
75 |
-
if ( ! $this->is_plugin_installed ) {
|
76 |
-
return;
|
77 |
-
}
|
78 |
-
|
79 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* MainWP Broken Links Checker actions: set_showhide, sync_data, sync_links_data, edit_link,
|
84 |
-
* unlink, set_dismiss, discard, save_settings, force_recheck.
|
85 |
-
*/
|
86 |
-
public function action() {
|
87 |
-
$information = array();
|
88 |
-
if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) {
|
89 |
-
$information['error'] = 'NO_BROKENLINKSCHECKER';
|
90 |
-
MainWP_Helper::write( $information );
|
91 |
-
}
|
92 |
-
blc_init();
|
93 |
-
|
94 |
-
MainWP_Helper::update_option( 'mainwp_linkschecker_ext_enabled', 'Y', 'yes' );
|
95 |
-
try {
|
96 |
-
if ( isset( $_POST['mwp_action'] ) ) {
|
97 |
-
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
98 |
-
switch ( $mwp_action ) {
|
99 |
-
case 'set_showhide':
|
100 |
-
$information = $this->set_showhide();
|
101 |
-
break;
|
102 |
-
case 'sync_data':
|
103 |
-
$information = $this->get_sync_data();
|
104 |
-
break;
|
105 |
-
case 'sync_links_data':
|
106 |
-
$information = $this->get_links_data();
|
107 |
-
break;
|
108 |
-
case 'edit_link':
|
109 |
-
$information = $this->edit_link();
|
110 |
-
break;
|
111 |
-
case 'unlink':
|
112 |
-
$information = $this->unlink();
|
113 |
-
break;
|
114 |
-
case 'set_dismiss':
|
115 |
-
$information = $this->set_link_dismissed();
|
116 |
-
break;
|
117 |
-
case 'discard':
|
118 |
-
$information = $this->discard();
|
119 |
-
break;
|
120 |
-
case 'save_settings':
|
121 |
-
$information = $this->save_settings();
|
122 |
-
break;
|
123 |
-
case 'force_recheck':
|
124 |
-
$information = $this->force_recheck();
|
125 |
-
break;
|
126 |
-
}
|
127 |
-
}
|
128 |
-
MainWP_Helper::write( $information );
|
129 |
-
} catch ( \Exception $e ) {
|
130 |
-
MainWP_Helper::write( array( 'error' => $e->getMessage() ) );
|
131 |
-
}
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* MainWP Broken links checker init.
|
136 |
-
*/
|
137 |
-
public function init() {
|
138 |
-
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
139 |
-
return;
|
140 |
-
}
|
141 |
-
|
142 |
-
if ( get_option( 'mainwp_linkschecker_hide_plugin' ) === 'hide' ) {
|
143 |
-
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) );
|
144 |
-
add_filter( 'update_footer', array( &$this, 'update_footer' ), 15 );
|
145 |
-
}
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Method hook_trashed_comment().
|
150 |
-
*
|
151 |
-
* @param $comment_id Comment ID.
|
152 |
-
*/
|
153 |
-
public static function hook_trashed_comment( $comment_id ) {
|
154 |
-
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
155 |
-
return;
|
156 |
-
}
|
157 |
-
|
158 |
-
if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) {
|
159 |
-
return;
|
160 |
-
}
|
161 |
-
blc_init();
|
162 |
-
$container = \blcContainerHelper::get_container( array( 'comment', $comment_id ) );
|
163 |
-
$container->delete();
|
164 |
-
blc_cleanup_links();
|
165 |
-
}
|
166 |
-
|
167 |
-
/**
|
168 |
-
* Save Settings.
|
169 |
-
*
|
170 |
-
* @return array Return $information response array.
|
171 |
-
*/
|
172 |
-
public function save_settings() {
|
173 |
-
$information = array();
|
174 |
-
$check_threshold = isset( $_POST['check_threshold'] ) ? intval( wp_unslash( $_POST['check_threshold'] ) ) : 0;
|
175 |
-
if ( $check_threshold > 0 ) {
|
176 |
-
$conf = blc_get_configuration();
|
177 |
-
$conf->options['check_threshold'] = $check_threshold;
|
178 |
-
$conf->save_options();
|
179 |
-
}
|
180 |
-
$information['result'] = 'SUCCESS';
|
181 |
-
return $information;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Force link recheck.
|
186 |
-
*
|
187 |
-
* @return array Return $information response array.
|
188 |
-
*/
|
189 |
-
public function force_recheck() {
|
190 |
-
$this->initiate_recheck();
|
191 |
-
$information = array();
|
192 |
-
$information['result'] = 'SUCCESS';
|
193 |
-
|
194 |
-
return $information;
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Initiate link recheck.
|
199 |
-
*/
|
200 |
-
public function initiate_recheck() {
|
201 |
-
|
202 |
-
/** @global object $wpdb wpdb */
|
203 |
-
global $wpdb;
|
204 |
-
|
205 |
-
// Delete all discovered instances.
|
206 |
-
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
|
207 |
-
|
208 |
-
// Delete all discovered links.
|
209 |
-
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
|
210 |
-
|
211 |
-
// Mark all posts, custom fields and bookmarks for processing.
|
212 |
-
blc_resynch( true );
|
213 |
-
}
|
214 |
-
|
215 |
-
|
216 |
-
/**
|
217 |
-
* Method hook_post_deleted().
|
218 |
-
*
|
219 |
-
* @param $post_id Post ID.
|
220 |
-
*/
|
221 |
-
public static function hook_post_deleted( $post_id ) {
|
222 |
-
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
223 |
-
return;
|
224 |
-
}
|
225 |
-
|
226 |
-
if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) {
|
227 |
-
return;
|
228 |
-
}
|
229 |
-
blc_init();
|
230 |
-
|
231 |
-
// Get the container type matching the type of the deleted post.
|
232 |
-
$post = get_post( $post_id );
|
233 |
-
if ( ! $post ) {
|
234 |
-
return;
|
235 |
-
}
|
236 |
-
// Get the associated container object.
|
237 |
-
$post_container = \blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
|
238 |
-
|
239 |
-
if ( $post_container ) {
|
240 |
-
// Delete it.
|
241 |
-
$post_container->delete();
|
242 |
-
// Clean up any dangling links.
|
243 |
-
blc_cleanup_links();
|
244 |
-
}
|
245 |
-
}
|
246 |
-
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Method hide_plugin().
|
250 |
-
*
|
251 |
-
* @param $plugins Plugins array.
|
252 |
-
* @return mixed $plugins array.
|
253 |
-
*/
|
254 |
-
public function hide_plugin( $plugins ) {
|
255 |
-
foreach ( $plugins as $key => $value ) {
|
256 |
-
$plugin_slug = basename( $key, '.php' );
|
257 |
-
if ( 'broken-link-checker' === $plugin_slug ) {
|
258 |
-
unset( $plugins[ $key ] );
|
259 |
-
}
|
260 |
-
}
|
261 |
-
|
262 |
-
return $plugins;
|
263 |
-
}
|
264 |
-
|
265 |
-
/**
|
266 |
-
* Method update_footer().
|
267 |
-
*
|
268 |
-
* @param $text Test to add to footer.
|
269 |
-
* @return string Footer html.
|
270 |
-
*/
|
271 |
-
public function update_footer( $text ) {
|
272 |
-
?>
|
273 |
-
<script>
|
274 |
-
jQuery( document ).ready( function () {
|
275 |
-
jQuery( '#menu-tools a[href="tools.php?page=view-broken-links"]' ).closest( 'li' ).remove();
|
276 |
-
jQuery( '#menu-settings a[href="options-general.php?page=link-checker-settings"]' ).closest( 'li' ).remove();
|
277 |
-
} );
|
278 |
-
</script>
|
279 |
-
<?php
|
280 |
-
return $text;
|
281 |
-
}
|
282 |
-
|
283 |
-
|
284 |
-
/**
|
285 |
-
* Show or hide the Broken links checker plugin.
|
286 |
-
*
|
287 |
-
* @return array Return $information response array.
|
288 |
-
*/
|
289 |
-
public function set_showhide() {
|
290 |
-
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
291 |
-
MainWP_Helper::update_option( 'mainwp_linkschecker_hide_plugin', $hide );
|
292 |
-
$information['result'] = 'SUCCESS';
|
293 |
-
|
294 |
-
return $information;
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Sync other broken links data.
|
299 |
-
*
|
300 |
-
* @param array $information Array of information to sync.
|
301 |
-
* @param array $data Array of data.
|
302 |
-
* @return array Return $information response array.
|
303 |
-
*/
|
304 |
-
public function sync_others_data( $information, $data = array() ) {
|
305 |
-
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
|
306 |
-
try {
|
307 |
-
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
|
308 |
-
} catch ( \Exception $e ) {
|
309 |
-
// ok!
|
310 |
-
}
|
311 |
-
}
|
312 |
-
return $information;
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* Get synced link data.
|
317 |
-
*
|
318 |
-
* @param string $strategy Sync method.
|
319 |
-
* @return array Return $information response array.
|
320 |
-
*/
|
321 |
-
public function get_sync_data( $strategy = '' ) {
|
322 |
-
$information = array();
|
323 |
-
$data = $this->get_count_links();
|
324 |
-
if ( is_array( $data ) ) {
|
325 |
-
$information['data'] = $data;
|
326 |
-
}
|
327 |
-
return $information;
|
328 |
-
}
|
329 |
-
|
330 |
-
/**
|
331 |
-
* Get links data.
|
332 |
-
*
|
333 |
-
* @return array[]|void Return $information response array or void on failure.
|
334 |
-
* @throws Exception Error exception.
|
335 |
-
*/
|
336 |
-
public function get_links_data() {
|
337 |
-
|
338 |
-
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
339 |
-
return;
|
340 |
-
}
|
341 |
-
|
342 |
-
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
|
343 |
-
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
|
344 |
-
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
345 |
-
|
346 |
-
require_once $file_path1;
|
347 |
-
require_once $file_path2;
|
348 |
-
|
349 |
-
MainWP_Helper::check_classes_exists( '\blcLinkQuery' );
|
350 |
-
MainWP_Helper::check_methods( '\blcLinkQuery', 'getInstance' );
|
351 |
-
|
352 |
-
$blc_link_query = \blcLinkQuery::getInstance();
|
353 |
-
|
354 |
-
MainWP_Helper::check_methods( $blc_link_query, 'get_filter_links' );
|
355 |
-
|
356 |
-
$total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
|
357 |
-
|
358 |
-
$max_results = isset( $_POST['max_results'] ) ? intval( wp_unslash( $_POST['max_results'] ) ) : 50;
|
359 |
-
$offset = isset( $_POST['offset'] ) ? intval( wp_unslash( $_POST['offset'] ) ) : 0;
|
360 |
-
|
361 |
-
$params = array(
|
362 |
-
array( 'load_instances' => true ),
|
363 |
-
'max_results' => $max_results,
|
364 |
-
);
|
365 |
-
|
366 |
-
if ( empty( $offset ) ) {
|
367 |
-
$first_sync = true;
|
368 |
-
} else {
|
369 |
-
$params['offset'] = $offset;
|
370 |
-
}
|
371 |
-
|
372 |
-
$link_data = $this->links_checker_data( $params );
|
373 |
-
|
374 |
-
$total_sync = 0;
|
375 |
-
if ( $offset ) {
|
376 |
-
$total_sync = $offset;
|
377 |
-
}
|
378 |
-
$total_sync += ( is_array( $link_data ) ? count( $link_data ) : 0 );
|
379 |
-
|
380 |
-
$information = array( 'links_data' => $link_data );
|
381 |
-
|
382 |
-
if ( $first_sync ) {
|
383 |
-
$information['data'] = $this->get_count_links();
|
384 |
-
}
|
385 |
-
|
386 |
-
if ( $total > $offset + $max_results ) {
|
387 |
-
$information['sync_offset'] = $offset + $max_results;
|
388 |
-
} else {
|
389 |
-
$information['last_sync'] = 1;
|
390 |
-
$information['total_sync'] = $total_sync;
|
391 |
-
$information['data'] = $this->get_count_links();
|
392 |
-
}
|
393 |
-
|
394 |
-
$information['result'] = 'success';
|
395 |
-
return $information;
|
396 |
-
}
|
397 |
-
|
398 |
-
/**
|
399 |
-
* Count links: broken, redirects, dismissed, warning, all.
|
400 |
-
*
|
401 |
-
* @return array[]|void Return $data response array or void on failure.
|
402 |
-
* @throws Exception Error exception.
|
403 |
-
*/
|
404 |
-
public function get_count_links() {
|
405 |
-
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
406 |
-
return;
|
407 |
-
}
|
408 |
-
|
409 |
-
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
|
410 |
-
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
|
411 |
-
|
412 |
-
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
413 |
-
|
414 |
-
require_once $file_path1;
|
415 |
-
require_once $file_path2;
|
416 |
-
|
417 |
-
MainWP_Helper::check_classes_exists( '\blcLinkQuery' );
|
418 |
-
MainWP_Helper::check_methods( '\blcLinkQuery', 'getInstance' );
|
419 |
-
|
420 |
-
$data = array();
|
421 |
-
$blc_link_query = \blcLinkQuery::getInstance();
|
422 |
-
|
423 |
-
MainWP_Helper::check_methods( $blc_link_query, 'get_filter_links' );
|
424 |
-
|
425 |
-
$data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
|
426 |
-
$data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) );
|
427 |
-
$data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) );
|
428 |
-
$data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) );
|
429 |
-
$data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
|
430 |
-
return $data;
|
431 |
-
}
|
432 |
-
|
433 |
-
/**
|
434 |
-
* Link checker data.
|
435 |
-
*
|
436 |
-
* @param mixed $params Broken Links parameters.
|
437 |
-
* @return array $return Links Array.
|
438 |
-
* @throws Exception Error Exception.
|
439 |
-
*/
|
440 |
-
public function links_checker_data( $params ) {
|
441 |
-
|
442 |
-
MainWP_Helper::check_functions( 'blc_get_links' );
|
443 |
-
MainWP_Helper::check_classes_exists( '\blcLink' );
|
444 |
-
|
445 |
-
$links = blc_get_links( $params );
|
446 |
-
|
447 |
-
$filter_fields = array(
|
448 |
-
'link_id',
|
449 |
-
'url',
|
450 |
-
'being_checked',
|
451 |
-
'last_check',
|
452 |
-
'last_check_attempt',
|
453 |
-
'check_count',
|
454 |
-
'http_code',
|
455 |
-
'request_duration',
|
456 |
-
'timeout',
|
457 |
-
'redirect_count',
|
458 |
-
'final_url',
|
459 |
-
'broken',
|
460 |
-
'warning',
|
461 |
-
'first_failure',
|
462 |
-
'last_success',
|
463 |
-
'may_recheck',
|
464 |
-
'false_positive',
|
465 |
-
'dismissed',
|
466 |
-
'status_text',
|
467 |
-
'status_code',
|
468 |
-
'log',
|
469 |
-
);
|
470 |
-
|
471 |
-
$return = array();
|
472 |
-
|
473 |
-
$blc_option = get_option( 'wsblc_options' );
|
474 |
-
|
475 |
-
if ( is_string( $blc_option ) && ! empty( $blc_option ) ) {
|
476 |
-
$blc_option = json_decode( $blc_option, true );
|
477 |
-
}
|
478 |
-
|
479 |
-
if ( is_array( $links ) ) {
|
480 |
-
foreach ( $links as $link ) {
|
481 |
-
$new_link = new \stdClass();
|
482 |
-
foreach ( $filter_fields as $field ) {
|
483 |
-
$new_link->$field = $link->$field;
|
484 |
-
}
|
485 |
-
|
486 |
-
$extra_info = array();
|
487 |
-
|
488 |
-
if ( ! empty( $link->post_date ) ) {
|
489 |
-
$extra_info['post_date'] = $link->post_date;
|
490 |
-
}
|
491 |
-
|
492 |
-
$days_broken = 0;
|
493 |
-
if ( $link->broken ) {
|
494 |
-
// Add a highlight to broken links that appear to be permanently broken.
|
495 |
-
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
|
496 |
-
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
|
497 |
-
$extra_info['permanently_broken'] = 1;
|
498 |
-
if ( $blc_option['highlight_permanent_failures'] ) {
|
499 |
-
$extra_info['permanently_broken_highlight'] = 1;
|
500 |
-
}
|
501 |
-
}
|
502 |
-
}
|
503 |
-
$extra_info['days_broken'] = $days_broken;
|
504 |
-
$instances = false;
|
505 |
-
|
506 |
-
$get_link = new \blcLink( intval( $link->link_id ) );
|
507 |
-
if ( $get_link->valid() ) {
|
508 |
-
MainWP_Helper::check_methods( $get_link, 'get_instances' );
|
509 |
-
$instances = $get_link->get_instances();
|
510 |
-
}
|
511 |
-
|
512 |
-
if ( ! empty( $instances ) ) {
|
513 |
-
$first_instance = reset( $instances );
|
514 |
-
|
515 |
-
MainWP_Helper::check_methods( $first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable' ) );
|
516 |
-
|
517 |
-
$new_link->link_text = $first_instance->ui_get_link_text();
|
518 |
-
$extra_info['count_instance'] = count( $instances );
|
519 |
-
$container = $first_instance->get_container();
|
520 |
-
|
521 |
-
if ( ! empty( $container ) ) {
|
522 |
-
if ( true === MainWP_Helper::check_properties( $first_instance, array( 'container_field' ), true ) ) {
|
523 |
-
if ( true === MainWP_Helper::check_properties( $container, array( 'container_type', 'container_id' ), true ) ) {
|
524 |
-
$extra_info['container_type'] = $container->container_type;
|
525 |
-
$extra_info['container_id'] = $container->container_id;
|
526 |
-
$extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field );
|
527 |
-
}
|
528 |
-
}
|
529 |
-
}
|
530 |
-
|
531 |
-
$can_edit_text = false;
|
532 |
-
$can_edit_url = false;
|
533 |
-
$editable_link_texts = $non_editable_link_texts = array();
|
534 |
-
|
535 |
-
foreach ( $instances as $instance ) {
|
536 |
-
if ( $instance->is_link_text_editable() ) {
|
537 |
-
$can_edit_text = true;
|
538 |
-
$editable_link_texts[ $instance->link_text ] = true;
|
539 |
-
} else {
|
540 |
-
$non_editable_link_texts[ $instance->link_text ] = true;
|
541 |
-
}
|
542 |
-
|
543 |
-
if ( $instance->is_url_editable() ) {
|
544 |
-
$can_edit_url = true;
|
545 |
-
}
|
546 |
-
}
|
547 |
-
|
548 |
-
$link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts;
|
549 |
-
$data_link_text = '';
|
550 |
-
if ( count( $link_texts ) === 1 ) {
|
551 |
-
// All instances have the same text - use it.
|
552 |
-
$link_text = key( $link_texts );
|
553 |
-
$data_link_text = esc_attr( $link_text );
|
554 |
-
}
|
555 |
-
$extra_info['data_link_text'] = $data_link_text;
|
556 |
-
$extra_info['can_edit_url'] = $can_edit_url;
|
557 |
-
$extra_info['can_edit_text'] = $can_edit_text;
|
558 |
-
} else {
|
559 |
-
$new_link->link_text = '';
|
560 |
-
$extra_info['count_instance'] = 0;
|
561 |
-
}
|
562 |
-
$new_link->extra_info = base64_encode( serialize( $extra_info ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
563 |
-
$new_link->synced = 1;
|
564 |
-
$return[] = $new_link;
|
565 |
-
}
|
566 |
-
} else {
|
567 |
-
return array();
|
568 |
-
}
|
569 |
-
|
570 |
-
return $return;
|
571 |
-
}
|
572 |
-
|
573 |
-
/**
|
574 |
-
* Edit Link.
|
575 |
-
*
|
576 |
-
* @return array Return $information response array.
|
577 |
-
*/
|
578 |
-
public function edit_link() {
|
579 |
-
$information = array();
|
580 |
-
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
581 |
-
$information['error'] = 'NOTALLOW';
|
582 |
-
|
583 |
-
return $information;
|
584 |
-
}
|
585 |
-
|
586 |
-
$link_id = isset( $_POST['link_id'] ) ? sanitize_text_field( wp_unslash( $_POST['link_id'] ) ) : '';
|
587 |
-
|
588 |
-
// Load the link.
|
589 |
-
$link = new \blcLink( intval( $link_id ) );
|
590 |
-
if ( ! $link->valid() ) {
|
591 |
-
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
592 |
-
return $information;
|
593 |
-
}
|
594 |
-
|
595 |
-
// Validate the new URL.
|
596 |
-
$new_url = isset( $_POST['new_url'] ) ? strips
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|