_remote_request( self::ROCKETCDN_API . 'website/' . $subscription['id'] . '/purge/', $args ); if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { return [ 'status' => $status, 'message' => __( 'RocketCDN cache purge failed: The API returned an unexpected response code.', 'rocket' ), ]; } $data = wp_remote_retrieve_body( $response ); if ( empty( $data ) ) { return [ 'status' => $status, 'message' => __( 'RocketCDN cache purge failed: The API returned an empty response.', 'rocket' ), ]; } $data = json_decode( $data ); if ( ! isset( $data->success ) ) { return [ 'status' => $status, 'message' => __( 'RocketCDN cache purge failed: The API returned an unexpected response.', 'rocket' ), ]; } if ( ! $data->success ) { return [ 'status' => $status, 'message' => sprintf( // translators: %s = message returned by the API. __( 'RocketCDN cache purge failed: %s.', 'rocket' ), isset( $data->message ) ? $data->message : '' ), ]; } return [ 'status' => 'success', 'message' => __( 'RocketCDN cache purge successful.', 'rocket' ), ]; } /** * Filter the arguments used in an HTTP request, to make sure our user token has not been overwritten * by some other plugin. * * @since 3.5 * * @param array $args An array of HTTP request arguments. * @param string $url The request URL. * @return array */ public function preserve_authorization_token( $args, $url ) { if ( strpos( $url, self::ROCKETCDN_API ) === false ) { return $args; } if ( empty( $args['headers']['Authorization'] ) && self::ROCKETCDN_API . 'pricing' === $url ) { return $args; } $token = get_option( 'rocketcdn_user_token' ); if ( empty( $token ) ) { return $args; } $value = 'token ' . $token; if ( isset( $args['headers']['Authorization'] ) && $value === $args['headers']['Authorization'] ) { return $args; } $args['headers']['Authorization'] = $value; return $args; } }