PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / trunk
WP STAGING – WordPress Backups, Restore, Migration & Clone vtrunk
4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Staging / Ajax / StagingSiteDataChecker.php
wp-staging / Staging / Ajax Last commit date
Create 1 week ago Delete 1 week ago Reset 1 week ago Update 1 week ago AbstractAjaxPrepare.php 1 week ago Create.php 1 week ago Delete.php 1 week ago DirectoryChildren.php 1 week ago Listing.php 1 week ago Repair.php 1 week ago Reset.php 1 week ago Setup.php 1 week ago SizeCalculator.php 1 week ago StagingSiteDataChecker.php 1 week ago Update.php 1 week ago
StagingSiteDataChecker.php
103 lines
1 <?php
2
3 namespace WPStaging\Staging\Ajax;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Language\Language;
7 use WPStaging\Framework\Security\Auth;
8 use WPStaging\Framework\Adapter\Directory;
9 use WPStaging\Framework\Filesystem\DirectoryListing;
10
11
12
13
14
15
16
17 class StagingSiteDataChecker
18 {
19
20 private $auth;
21
22
23 private $dirAdapter;
24
25 public function __construct(Auth $auth, Directory $directory)
26 {
27 $this->auth = $auth;
28 $this->dirAdapter = $directory;
29 }
30
31
32
33
34 public function ajaxIsWritableCloneDestinationDir()
35 {
36 if (!$this->auth->isAuthenticatedRequest()) {
37 return;
38 }
39
40 $cloneDir = !empty($_POST['cloneDir']) ? sanitize_text_field($_POST['cloneDir']) : '';
41
42 if (!empty($cloneDir)) {
43 wp_mkdir_p($cloneDir);
44 if (!is_writable($cloneDir)) {
45 $directoryListing = WPStaging::getInstance()->getContainer()->get(DirectoryListing::class);
46 $reason = __('restricted folder permissions', 'wp-staging');
47 $howToFix = sprintf(
48 __('Adjust the permissions for <strong>%s</strong> to <code>755</code> and follow %s step-by-step guide', 'wp-staging'),
49 esc_html($cloneDir),
50 '<a href="https://wp-staging.com/docs/folder-permission-error-folder-xy-is-not-write-and-or-readable/" target="_blank" rel="noopener noreferrer">' . esc_html__('this', 'wp-staging') . '</a>'
51 );
52
53 if (!$directoryListing->isPathInOpenBaseDir($cloneDir)) {
54 $reason = __('the PHP open_basedir setting', 'wp-staging');
55 $howToFix = sprintf(
56 __('Add <strong>%s</strong> to your PHP <code>open_basedir</code> setting and follow %s step-by-step guide', 'wp-staging'),
57 esc_html($cloneDir),
58 '<a href="https://wp-staging.com/docs/how-to-fix-open_basedir-restriction-error/" target="_blank" rel="noopener noreferrer">' . esc_html__('this', 'wp-staging') . '</a>'
59 );
60 }
61
62 $supportLink = '<a href="' . esc_url(Language::localizeSupportUrl('https://wp-staging.com/support/')) . '" target="_blank" rel="noopener noreferrer">' . esc_html__('open a support ticket', 'wp-staging') . '</a>';
63 $message = sprintf(
64 __('The directory <strong>%s</strong> is not writable due to %s.<br/>
65 <p class="wpstg-mb-10px wpstg-mt-10px"><strong>How to fix this:</strong></p>
66 <ul style="list-style:circle;" class="wpstg-ml-15px wpstg-mt-5px">
67 <li>%s.</li>
68 <li>Or %s.</li>
69 </ul>', 'wp-staging'),
70 esc_html($cloneDir),
71 esc_html($reason),
72 $howToFix,
73 $supportLink
74 );
75
76 wp_send_json_error(['message' => $message]);
77 }
78
79 wp_send_json_success();
80 }
81
82 $cloneDirRootPath = $this->dirAdapter->getAbsPath();
83 if (is_writable($cloneDirRootPath)) {
84 wp_send_json_success();
85 }
86
87 $cloneDir = $this->dirAdapter->getStagingSiteDirectoryInsideWpcontent();
88 if ($cloneDir === false) {
89 wp_send_json_error([
90 'message' => sprintf(__('Clone destination dir cannot be created. Please choose another path.', 'wp-staging')),
91 ]);
92 }
93
94 if (is_writable($cloneDir)) {
95 wp_send_json_success();
96 }
97
98 wp_send_json_error([
99 'message' => sprintf(__('Clone destination dir is not writable. Please make <code>%s</code> or <code>%s</code> writable to proceed!', 'wp-staging'), esc_html($cloneDirRootPath), esc_html($cloneDir)),
100 ]);
101 }
102 }
103