Usage
PHP
nebula()->is_background_request()
Parameters
This function does not accept any parameters. Is this incorrect?
Additional Notes
This function is true if the current request is an AJAX, REST, CRON, XMLRPC, or WP installation.
This is great for optimizing server-side functionality that is only meant to be run either during, or not during one of these “background” requests.
Source File
Located in /libs/Utilities/Utilities.php on line 1475.
No Hooks
This function does not have any filters or actions available. Request one?
PHP
public function is_background_request(){
//Check for AJAX (including the WP Heartbeat)
if ( $this->is_ajax_request() ){
return true;
}
if ( wp_is_json_request() ){
return true;
}
//Check for the REST API
if ( (defined('REST_REQUEST') && REST_REQUEST) || isset($this->super->get['rest_route']) ){
return true;
}
//Common REST API URIs
if ( isset($this->super->server['REQUEST_URI']) ){
if ( str_contains($this->super->server['REQUEST_URI'], '/wp-json/') ){
return true;
}
}
//Check if a CRON is running
if ( wp_doing_cron() || (defined('DOING_CRON') && DOING_CRON) ){
return true;
}
//Check if it is an XMLRPC request
if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ){
return true;
}
//Check if WP is installing
if ( defined('WP_INSTALLING') && WP_INSTALLING ){
return true;
}
//If autosaving
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
return true;
}
//Note: WP CLI is not considered a background request
return false;
}
Override
This function can not be short-circuited with an override filter. Request one?