PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.0.4
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.0.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 / Framework / SiteInfo.php
wp-staging / Framework Last commit date
Adapter 2 years ago Analytics 3 years ago Assets 2 years ago BackgroundProcessing 2 years ago CloningProcess 2 years ago Collection 3 years ago Command 5 years ago Component 5 years ago DI 3 years ago Database 2 years ago DependencyResolver 4 years ago Exceptions 3 years ago Facades 3 years ago Filesystem 2 years ago Interfaces 5 years ago Mails 2 years ago Notices 2 years ago Permalinks 5 years ago Queue 3 years ago Rest 3 years ago Security 2 years ago Settings 3 years ago Staging 2 years ago Support 2 years ago TemplateEngine 5 years ago Traits 2 years ago Utils 2 years ago AnalyticsServiceProvider.php 2 years ago AssetServiceProvider.php 5 years ago CommonServiceProvider.php 2 years ago ErrorHandler.php 3 years ago NoticeServiceProvider.php 3 years ago SettingsServiceProvider.php 2 years ago SiteInfo.php 2 years ago Url.php 3 years ago
SiteInfo.php
219 lines
1 <?php
2
3 namespace WPStaging\Framework;
4
5 use WPStaging\Framework\Staging\CloneOptions;
6
7 /**
8 * Class SiteInfo
9 *
10 * Provides information about the current site.
11 *
12 * @package WPStaging\Site
13 */
14 class SiteInfo
15 {
16 /**
17 * The key used in DB to store is cloneable feature in clone options
18 * @var string
19 */
20 const IS_CLONEABLE_KEY = 'isCloneable';
21
22 /**
23 * The file which make staging site cloneable
24 * This way is depreciated
25 * @var string
26 */
27 const CLONEABLE_FILE = '.wp-staging-cloneable';
28
29 /**
30 * The key used in DB to store whether site is staging or not
31 * @var string
32 */
33 const IS_STAGING_KEY = 'wpstg_is_staging_site';
34
35 /**
36 * The file which makes a site a staging site
37 * @var string
38 */
39 const STAGING_FILE = '.wp-staging';
40
41 /**
42 * @var CloneOptions
43 */
44 private $cloneOptions;
45
46 /**
47 * @var array
48 */
49 private $errors = [];
50
51 public function __construct()
52 {
53 // TODO: inject using DI
54 $this->cloneOptions = new CloneOptions();
55 }
56
57 /**
58 * @return bool True if it is staging site. False otherwise.
59 */
60 public function isStagingSite()
61 {
62 if (defined('WPSTAGING_DEV_SITE') && WPSTAGING_DEV_SITE === true) {
63 return true;
64 }
65
66 if (get_option(self::IS_STAGING_KEY) === "true") {
67 return true;
68 }
69
70 return file_exists(ABSPATH . self::STAGING_FILE);
71 }
72
73 /**
74 * @return bool True if it is staging site. False otherwise.
75 *
76 * @todo update with WPStaging/Framework/Staging/CloneOption once PR #717 is merged
77 */
78 public function isCloneable()
79 {
80 // Site should be cloneable if not staging i.e. production site
81 if (!$this->isStagingSite()) {
82 return true;
83 }
84
85 // Old condition to check if staging site is cloneable
86 if (file_exists(ABSPATH . self::CLONEABLE_FILE)) {
87 return true;
88 }
89
90 // New condition for checking whether staging is cloneable or not
91 return $this->cloneOptions->get(self::IS_CLONEABLE_KEY);
92 }
93
94 /**
95 * Check if WP is installed in subdirectory
96 * If siteurl and home are not identical we assume the site is located in a subdirectory
97 * related to that instruction https://wordpress.org/support/article/giving-wordpress-its-own-directory/
98 *
99 * @return bool
100 */
101 public function isInstalledInSubDir()
102 {
103 $siteUrl = get_option('siteurl');
104 $homeUrl = get_option('home');
105
106 //Get URL path e.g.https://example.com/path will return /path
107 $siteUrlPath = wp_parse_url($siteUrl, PHP_URL_PATH);
108 $homeUrlPath = wp_parse_url($homeUrl, PHP_URL_PATH);
109
110 if ($siteUrlPath === null && $homeUrlPath === null || $siteUrlPath === $homeUrlPath) {
111 return false;
112 }
113
114 if ($siteUrlPath === null && $homeUrlPath !== null) {
115 return true;
116 }
117
118 return false;
119 }
120
121 /**
122 * Enable the cloning for current staging site.
123 *
124 * @return bool
125 */
126 public function enableStagingSiteCloning()
127 {
128 // Early Bail: if site is not staging
129 if (!$this->isStagingSite()) {
130 return false;
131 }
132
133 // Early Bail: if cloning already enabled
134 if ($this->isCloneable()) {
135 return true;
136 }
137
138 return $this->cloneOptions->set(self::IS_CLONEABLE_KEY, true);
139 }
140
141 /**
142 * Enable the cloning for current staging site.
143 *
144 * @return bool
145 */
146 public function disableStagingSiteCloning()
147 {
148 // Early Bail: if site is not staging
149 if (!$this->isStagingSite()) {
150 return false;
151 }
152
153 // Early Bail: if cloning already disabled
154 if (!$this->isCloneable()) {
155 return true;
156 }
157
158 // First try disabling if cloneable feature exist due to old way.
159 $cloneableFile = trailingslashit(ABSPATH) . self::CLONEABLE_FILE;
160 if (file_exists($cloneableFile) && !unlink($cloneableFile)) {
161 // Error if files exists but unable to unlink
162 return false;
163 }
164
165 // Staging site may have been made cloneable through both ways
166 // So now try disabling through new way
167 return (!file_exists($cloneableFile) && $this->cloneOptions->delete(self::IS_CLONEABLE_KEY));
168 }
169
170 /**
171 * @return bool True if "short_open_tags" is enabled, false if disabled.
172 */
173 public function isPhpShortTagsEnabled()
174 {
175 return in_array(strtolower(ini_get('short_open_tags')), ['1', 'on', 'true']);
176 }
177
178 /**
179 * Is WP Bakery plugin active?
180 *
181 * @return bool
182 */
183 public function isWpBakeryActive()
184 {
185 return defined('WPB_VC_VERSION');
186 }
187
188 /**
189 * @return array
190 */
191 public function getErrors()
192 {
193 return $this->errors;
194 }
195
196 /**
197 * @return bool
198 */
199 public function isWpContentOutsideAbspath()
200 {
201 $wpContentDir = wp_normalize_path(WP_CONTENT_DIR);
202 $abspath = wp_normalize_path(ABSPATH);
203
204 return !(strpos($wpContentDir, $abspath) === 0);
205 }
206
207 /**
208 * @return bool
209 */
210 public function isFlywheel()
211 {
212 if (!$this->isWpContentOutsideAbspath()) {
213 return false;
214 }
215
216 return file_exists(trailingslashit(wp_normalize_path(ABSPATH)) . '.fw-config.php');
217 }
218 }
219