: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$decoded = json_decode( $response_body );
if ( is_null( $decoded ) ) {
if ( preg_match( '/Please turn JavaScript on/i', $response_body ) &&
preg_match( '/text\/javascript/', $response_body )
self::ThrowCloudFlareDDoSException( $response_body );
} else if ( preg_match( '/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $response_body ) &&
preg_match( '/squid/', $response_body )
self::ThrowSquidAclException( $response_body );
$decoded = (object) array(
'error' => (object) array(
'message' => $response_body,
* Makes an HTTP request. This method can be overridden by subclasses if
* developers want to do fancier things or use something other than wp_remote_request()
* @param string $pCanonizedPath The URL to make the request to
* @param string $pMethod HTTP method
* @param array $pParams The parameters to use for the POST body
* @param null|array $pWPRemoteArgs wp_remote_request options.
* @return object[]|object|null
* @throws Freemius_Exception
public function MakeRequest(
$resource = explode( '?', $pCanonizedPath );
// Only sign request if not ping.json connectivity test.
$sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
return self::MakeStaticRequest(
$sign_request ? array( &$this, 'SignRequest' ) : null
* Sets CURLOPT_IPRESOLVE to CURL_IPRESOLVE_V4 for cURL-Handle provided as parameter
* @param resource $handle A cURL handle returned by curl_init()
* @return resource $handle A cURL handle returned by curl_init() with CURLOPT_IPRESOLVE set to
* @link https://gist.github.com/golderweb/3a2aaec2d56125cc004e
static function CurlResolveToIPv4( $handle ) {
curl_setopt( $handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
#----------------------------------------------------------------------------------
#region Connectivity Test
#----------------------------------------------------------------------------------
* This method exists only for backward compatibility to prevent a fatal error from happening when called from an outdated piece of code.
public static function Test( $pPong = null ) {
* Ping API to test connectivity.
public static function Ping() {
$result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
} catch ( Freemius_Exception $e ) {
$result = (object) $e->getResult();
} catch ( Exception $e ) {
$result = (object) array(
'error' => (object) array(
'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
#----------------------------------------------------------------------------------
#region Connectivity Exceptions
#----------------------------------------------------------------------------------
* @param \WP_Error $pError
private static function IsCurlError( WP_Error $pError ) {
$message = $pError->get_error_message( 'http_request_failed' );
return ( 0 === strpos( $message, 'cURL' ) );
* @param WP_Error $pError
* @throws Freemius_Exception
private static function ThrowWPRemoteException( WP_Error $pError ) {
if ( self::IsCurlError( $pError ) ) {
$message = $pError->get_error_message( 'http_request_failed' );
#region Check if there are any missing cURL methods.
$curl_required_methods = array(
// Find all missing methods.
$missing_methods = array();
foreach ( $curl_required_methods as $m ) {
if ( ! function_exists( $m ) ) {
if ( ! empty( $missing_methods ) ) {
throw new Freemius_Exception( array(
'error' => (object) array(
'code' => 'curl_missing',
'missing_methods' => $missing_methods,
// cURL error - "cURL error {{errno}}: {{error}}".
$parts = explode( ':', substr( $message, strlen( 'cURL error ' ) ), 2 );
$code = ( 0 < count( $parts ) ) ? $parts[0] : 'http_request_failed';
$message = ( 1 < count( $parts ) ) ? $parts[1] : $message;
$e = new Freemius_Exception( array(
'error' => (object) array(
'type' => 'CurlException',
$e = new Freemius_Exception( array(
'error' => (object) array(
'code' => $pError->get_error_code(),
'message' => $pError->get_error_message(),
'type' => 'WPRemoteException',
* @throws Freemius_Exception
private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
throw new Freemius_Exception( array(
'error' => (object) array(
'type' => 'CloudFlareDDoSProtection',
'code' => 'cloudflare_ddos_protection',
* @throws Freemius_Exception
private static function ThrowSquidAclException( $pResult = '' ) {
throw new Freemius_Exception( array(
'error' => (object) array(
'type' => 'SquidCacheBlock',
'code' => 'squid_cache_block',