PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.0.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.0.2
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 3 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
215 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 (get_option(self::IS_STAGING_KEY) === "true") {
63 return true;
64 }
65
66 return file_exists(ABSPATH . self::STAGING_FILE);
67 }
68
69 /**
70 * @return bool True if it is staging site. False otherwise.
71 *
72 * @todo update with WPStaging/Framework/Staging/CloneOption once PR #717 is merged
73 */
74 public function isCloneable()
75 {
76 // Site should be cloneable if not staging i.e. production site
77 if (!$this->isStagingSite()) {
78 return true;
79 }
80
81 // Old condition to check if staging site is cloneable
82 if (file_exists(ABSPATH . self::CLONEABLE_FILE)) {
83 return true;
84 }
85
86 // New condition for checking whether staging is cloneable or not
87 return $this->cloneOptions->get(self::IS_CLONEABLE_KEY);
88 }
89
90 /**
91 * Check if WP is installed in subdirectory
92 * If siteurl and home are not identical we assume the site is located in a subdirectory
93 * related to that instruction https://wordpress.org/support/article/giving-wordpress-its-own-directory/
94 *
95 * @return bool
96 */
97 public function isInstalledInSubDir()
98 {
99 $siteUrl = get_option('siteurl');
100 $homeUrl = get_option('home');
101
102 //Get URL path e.g.https://example.com/path will return /path
103 $siteUrlPath = wp_parse_url($siteUrl, PHP_URL_PATH);
104 $homeUrlPath = wp_parse_url($homeUrl, PHP_URL_PATH);
105
106 if ($siteUrlPath === null && $homeUrlPath === null || $siteUrlPath === $homeUrlPath) {
107 return false;
108 }
109
110 if ($siteUrlPath === null && $homeUrlPath !== null) {
111 return true;
112 }
113
114 return false;
115 }
116
117 /**
118 * Enable the cloning for current staging site.
119 *
120 * @return bool
121 */
122 public function enableStagingSiteCloning()
123 {
124 // Early Bail: if site is not staging
125 if (!$this->isStagingSite()) {
126 return false;
127 }
128
129 // Early Bail: if cloning already enabled
130 if ($this->isCloneable()) {
131 return true;
132 }
133
134 return $this->cloneOptions->set(self::IS_CLONEABLE_KEY, true);
135 }
136
137 /**
138 * Enable the cloning for current staging site.
139 *
140 * @return bool
141 */
142 public function disableStagingSiteCloning()
143 {
144 // Early Bail: if site is not staging
145 if (!$this->isStagingSite()) {
146 return false;
147 }
148
149 // Early Bail: if cloning already disabled
150 if (!$this->isCloneable()) {
151 return true;
152 }
153
154 // First try disabling if cloneable feature exist due to old way.
155 $cloneableFile = trailingslashit(ABSPATH) . self::CLONEABLE_FILE;
156 if (file_exists($cloneableFile) && !unlink($cloneableFile)) {
157 // Error if files exists but unable to unlink
158 return false;
159 }
160
161 // Staging site may have been made cloneable through both ways
162 // So now try disabling through new way
163 return (!file_exists($cloneableFile) && $this->cloneOptions->delete(self::IS_CLONEABLE_KEY));
164 }
165
166 /**
167 * @return bool True if "short_open_tags" is enabled, false if disabled.
168 */
169 public function isPhpShortTagsEnabled()
170 {
171 return in_array(strtolower(ini_get('short_open_tags')), ['1', 'on', 'true']);
172 }
173
174 /**
175 * Is WP Bakery plugin active?
176 *
177 * @return bool
178 */
179 public function isWpBakeryActive()
180 {
181 return defined('WPB_VC_VERSION');
182 }
183
184 /**
185 * @return array
186 */
187 public function getErrors()
188 {
189 return $this->errors;
190 }
191
192 /**
193 * @return bool
194 */
195 public function isWpContentOutsideAbspath()
196 {
197 $wpContentDir = wp_normalize_path(WP_CONTENT_DIR);
198 $abspath = wp_normalize_path(ABSPATH);
199
200 return !(strpos($wpContentDir, $abspath) === 0);
201 }
202
203 /**
204 * @return bool
205 */
206 public function isFlywheel()
207 {
208 if (!$this->isWpContentOutsideAbspath()) {
209 return false;
210 }
211
212 return file_exists(trailingslashit(wp_normalize_path(ABSPATH)) . '.fw-config.php');
213 }
214 }
215