PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.0
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 week ago Backup 1 week ago Basic 1 week ago Component 1 week ago Core 1 week ago Framework 1 week ago Frontend 5 months ago Notifications 8 months ago Staging 1 week ago assets 1 week ago languages 1 week ago resources 1 year ago vendor_wpstg 1 week ago views 1 week ago CONTRIBUTING.md 1 year ago Deactivate.php 8 months ago README.md 3 months ago SECURITY.md 2 years ago autoloader.php 1 month ago bootstrap.php 1 month ago commonBootstrap.php 1 week ago constantsFree.php 1 week ago freeBootstrap.php 1 month ago install.php 1 week ago opcacheBootstrap.php 1 week ago readme.txt 1 week ago runtimeRequirements.php 3 months ago uninstall.php 1 week ago wp-staging-error-handler.php 6 months ago wp-staging.php 1 week ago
commonBootstrap.php
187 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('wpstgShouldSkipBootstrap')) {
127 function wpstgShouldSkipBootstrap(): bool
128 {
129 if (defined('WP_INSTALLING') && WP_INSTALLING) {
130 return false;
131 }
132
133 if (defined('DOING_CRON') && DOING_CRON) {
134 return false;
135 }
136
137 if (defined('WP_CLI') && WP_CLI) {
138 return false;
139 }
140
141 $requestUri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : '';
142
143 // WordPress login page: needed for post-restore login prompt and other login hooks.
144 if (strpos($requestUri, '/wp-login.php') !== false) {
145 return false;
146 }
147
148 // Temporary/auto login links (?wpstg_login=, ?wpstg_staging_login=, ?action=wpstg_*).
149 $action = wpstgGetRequestAction();
150 if (
151 !empty($_GET['wpstg_login']) ||
152 !empty($_GET['wpstg_staging_login']) ||
153 wpstgIsPluginAction($action)
154 ) {
155 return false;
156 }
157
158 // Staging sites need full bootstrap: login gate, permission checks, admin bar CSS.
159 if (get_option('wpstg_is_staging_site') === 'true') {
160 return false;
161 }
162
163 if (file_exists(ABSPATH . '.wp-staging')) {
164 return false;
165 }
166
167 // Non-WP-CLI PHP processes (test runners, deploy tools) also need full bootstrap.
168 if (php_sapi_name() === 'cli') {
169 return false;
170 }
171
172 if (wpstgIsAdminActionRequest($requestUri)) {
173 return !wpstgIsPluginAction($action);
174 }
175
176 if (is_admin()) {
177 return false;
178 }
179
180 if (wpstgIsRestRequest($requestUri)) {
181 return !wpstgIsPluginRestRequest($requestUri);
182 }
183
184 return true;
185 }
186 }
187