Account for early start-up phase

Using `$wp` doesn't work in certain scenarios, where the entire system
didn't complete bootstrapping.
The raw query, after escaping the values, should sufficiently cater for
the need.
This commit is contained in:
Justas Butkus 2019-12-02 21:56:42 +02:00
parent dbc0c5ab85
commit e0613db386
1 changed files with 10 additions and 3 deletions

View File

@ -124,10 +124,17 @@ class WC_WCCOM_Site {
* @return bool
*/
protected static function is_request_to_wccom_site_rest_api() {
global $wp;
$route = ltrim( $wp->query_vars['rest_route'], '/' );
$route = '/';
$rest_prefix = '';
return 0 !== strpos( $rest_route, 'wccom-site/' );
if ( isset( $_REQUEST['rest_route'] ) ) {
$route = esc_url_raw( wp_unslash( $_REQUEST['rest_route'] ) );
} else {
$route = esc_url_raw( wp_unslash( add_query_arg( array() ) ) );
$rest_prefix = trailingslashit( rest_get_url_prefix() );
}
return false !== strpos( $route, $rest_prefix . 'wccom-site/' );
}
/**