PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.9.4
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.9.4
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 / commonBootstrap.php
wp-staging Last commit date
Backend 1 day ago Backup 1 day ago Basic 1 week ago Component 1 month ago Core 1 week ago Framework 1 day ago Frontend 6 months ago Notifications 9 months ago Staging 1 day ago assets 1 day ago languages 1 day ago resources 1 year ago vendor_wpstg 1 day ago views 1 day ago CONTRIBUTING.md 2 years ago Deactivate.php 9 months ago README.md 4 months ago SECURITY.md 1 day ago autoloader.php 2 months ago bootstrap.php 1 day ago commonBootstrap.php 1 day ago constantsFree.php 1 day ago freeBootstrap.php 3 weeks ago install.php 1 month ago opcacheBootstrap.php 1 day ago readme.txt 1 day ago runtimeRequirements.php 4 months ago uninstall.php 1 week ago wp-staging-error-handler.php 7 months ago wp-staging.php 1 day ago
commonBootstrap.php
203 lines
1 <?php
2
3 if (!function_exists('wpstgIsAdminActionRequest')) {
4 /**
5 * @param string $requestUri
6 * @return bool
7 */
8 function wpstgIsAdminActionRequest(string $requestUri): bool
9 {
10 $requestPath = (string)parse_url($requestUri, PHP_URL_PATH);
11
12 return strpos($requestPath, '/wp-admin/admin-ajax.php') !== false
13 || strpos($requestPath, '/wp-admin/admin-post.php') !== false;
14 }
15 }
16
17 if (!function_exists('wpstgIsPluginAction')) {
18 /**
19 * @param string $action
20 * @return bool
21 */
22 function wpstgIsPluginAction(string $action): bool
23 {
24 return strpos($action, 'wpstg') === 0 || strpos($action, 'raw_wpstg') === 0;
25 }
26 }
27
28 if (!function_exists('wpstgGetRequestAction')) {
29 /**
30 * @return string
31 */
32 function wpstgGetRequestAction(): string
33 {
34 if (isset($_GET['action'])) {
35 $action = sanitize_key($_GET['action']);
36 } elseif (isset($_POST['action'])) {
37 $action = sanitize_key($_POST['action']);
38 } elseif (isset($_REQUEST['action'])) {
39 $action = sanitize_key($_REQUEST['action']);
40 } else {
41 $action = '';
42 }
43
44 if (!is_scalar($action)) {
45 return '';
46 }
47
48 return sanitize_key(wp_unslash((string) $action));
49 }
50 }
51
52 if (!function_exists('wpstgIsPluginRestRoute')) {
53 /**
54 * @param string $route
55 * @return bool
56 */
57 function wpstgIsPluginRestRoute(string $route): bool
58 {
59 $route = ltrim($route, '/');
60
61 return $route === 'wpstg/v1' || strpos($route, 'wpstg/v1/') === 0;
62 }
63 }
64
65 if (!function_exists('wpstgGetPrettyRestRoute')) {
66 /**
67 * @param string $requestUri
68 * @return string
69 */
70 function wpstgGetPrettyRestRoute(string $requestUri): string
71 {
72 $requestPath = (string)parse_url($requestUri, PHP_URL_PATH);
73 if ($requestPath === '') {
74 return '';
75 }
76
77 // REST_REQUEST isn't defined at plugins_loaded; resolve prefix dynamically
78 // so custom rest_url_prefix filters are respected.
79 $restPrefix = '/' . trim(apply_filters('rest_url_prefix', 'wp-json'), '/') . '/';
80 $prefixPosition = strpos($requestPath, $restPrefix);
81 if ($prefixPosition === false) {
82 return '';
83 }
84
85 return ltrim(substr($requestPath, $prefixPosition + strlen($restPrefix)), '/');
86 }
87 }
88
89 if (!function_exists('wpstgIsRestRequest')) {
90 /**
91 * @param string $requestUri
92 * @return bool
93 */
94 function wpstgIsRestRequest(string $requestUri): bool
95 {
96 if (wpstgGetPrettyRestRoute($requestUri) !== '') {
97 return true;
98 }
99
100 return !empty($_GET['rest_route']);
101 }
102 }
103
104 if (!function_exists('wpstgIsPluginRestRequest')) {
105 /**
106 * @param string $requestUri
107 * @return bool
108 */
109 function wpstgIsPluginRestRequest(string $requestUri): bool
110 {
111 $prettyRoute = wpstgGetPrettyRestRoute($requestUri);
112 if ($prettyRoute !== '') {
113 return wpstgIsPluginRestRoute($prettyRoute);
114 }
115
116 if (empty($_GET['rest_route'])) {
117 return false;
118 }
119
120 $restRoute = sanitize_text_field(wp_unslash($_GET['rest_route']));
121
122 return wpstgIsPluginRestRoute($restRoute);
123 }
124 }
125
126 if (!function_exists('wpstgIsStagingSite')) {
127 /**
128 * @param string $stagingMarkerFileName Name of the marker file placed in the site root on staging sites.
129 * @param string $stagingSiteOptionName Option key that stores whether the site is a staging site.
130 * @return bool
131 */
132 function wpstgIsStagingSite(string $stagingMarkerFileName = '.wp-staging', string $stagingSiteOptionName = 'wpstg_is_staging_site'): bool
133 {
134 if (defined('WPSTAGING_DEV_SITE') && WPSTAGING_DEV_SITE === true) {
135 return true;
136 }
137
138 if (get_option($stagingSiteOptionName) === 'true') {
139 return true;
140 }
141
142 return file_exists(ABSPATH . $stagingMarkerFileName);
143 }
144 }
145
146 if (!function_exists('wpstgShouldSkipBootstrap')) {
147 function wpstgShouldSkipBootstrap(): bool
148 {
149 if (defined('WP_INSTALLING') && WP_INSTALLING) {
150 return false;
151 }
152
153 if (defined('DOING_CRON') && DOING_CRON) {
154 return false;
155 }
156
157 if (defined('WP_CLI') && WP_CLI) {
158 return false;
159 }
160
161 $requestUri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : '';
162
163 // WordPress login page: needed for post-restore login prompt and other login hooks.
164 if (strpos($requestUri, '/wp-login.php') !== false) {
165 return false;
166 }
167
168 // Temporary/auto login links (?wpstg_login=, ?wpstg_staging_login=, ?action=wpstg_*).
169 $action = wpstgGetRequestAction();
170 if (
171 !empty($_GET['wpstg_login']) ||
172 !empty($_GET['wpstg_staging_login']) ||
173 wpstgIsPluginAction($action)
174 ) {
175 return false;
176 }
177
178 // Staging sites need full bootstrap: login gate, permission checks, admin bar CSS.
179 if (wpstgIsStagingSite()) {
180 return false;
181 }
182
183 // Non-WP-CLI PHP processes (test runners, deploy tools) also need full bootstrap.
184 if (php_sapi_name() === 'cli') {
185 return false;
186 }
187
188 if (wpstgIsAdminActionRequest($requestUri)) {
189 return !wpstgIsPluginAction($action);
190 }
191
192 if (is_admin()) {
193 return false;
194 }
195
196 if (wpstgIsRestRequest($requestUri)) {
197 return !wpstgIsPluginRestRequest($requestUri);
198 }
199
200 return true;
201 }
202 }
203