: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @package WP-Background-Processing
Library URI: https://github.com/deliciousbrains/wp-background-processing/blob/fbbc56f2480910d7959972ec9ec0819a13c6150a/classes/wp-async-request.php
Author: Delicious Brains Inc.
Author URI: https://deliciousbrains.com/
License: GNU General Public License v2.0
License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a
if ( ! class_exists( 'WP_Async_Request' ) ) {
* Abstract WP_Async_Request class.
abstract class WP_Async_Request {
protected $prefix = 'wp';
* (default value: 'async_request')
protected $action = 'async_request';
* (default value: array())
protected $data = array();
* Initiate new async request
public function __construct() {
$this->identifier = $this->prefix . '_' . $this->action;
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
* Set data used during the request
* @param array $data Data.
public function data( $data ) {
* Dispatch the async request
public function dispatch() {
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
$args = $this->get_post_args();
return wp_remote_post( esc_url_raw( $url ), $args );
protected function get_query_args() {
if ( property_exists( $this, 'query_args' ) ) {
return $this->query_args;
'action' => $this->identifier,
'nonce' => wp_create_nonce( $this->identifier ),
* Filters the post arguments used during an async request.
return apply_filters( $this->identifier . '_query_args', $args );
protected function get_query_url() {
if ( property_exists( $this, 'query_url' ) ) {
$url = admin_url( 'admin-ajax.php' );
* Filters the post arguments used during an async request.
return apply_filters( $this->identifier . '_query_url', $url );
protected function get_post_args() {
if ( property_exists( $this, 'post_args' ) ) {
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
* Filters the post arguments used during an async request.
return apply_filters( $this->identifier . '_post_args', $args );
* Check for correct nonce and pass to handler.
public function maybe_handle() {
// Don't lock up other requests while processing
check_ajax_referer( $this->identifier, 'nonce' );
* Override this method to perform any actions required
* during the async request.
abstract protected function handle();