$method, 'timeout' => $timeout, 'redirection' => 0, 'headers' => array( 'Authorization' => 'Bearer ' . $secret, 'Accept' => 'application/json', ), ); if ( null !== $body ) { $args['headers']['Content-Type'] = 'application/json'; $args['body'] = wp_json_encode( $body ); } $response = wp_remote_request( self::BASE . $path, $args ); if ( is_wp_error( $response ) ) { return $response; } $data = json_decode( (string) wp_remote_retrieve_body( $response ), true ); $data = is_array( $data ) ? $data : array(); $data['_status'] = (int) wp_remote_retrieve_response_code( $response ); if ( $saved ) { if ( 401 === $data['_status'] ) { update_option( 'rabbitproof_gone', time(), false ); } elseif ( 200 === $data['_status'] && get_option( 'rabbitproof_gone' ) ) { delete_option( 'rabbitproof_gone' ); } } return $data; } public static function open( $path, $body ) { $response = wp_remote_request( self::BASE . $path, array( 'method' => 'POST', 'timeout' => 10, 'redirection' => 0, 'headers' => array( 'Accept' => 'application/json', 'Content-Type' => 'application/json', ), 'body' => wp_json_encode( $body ), ) ); if ( is_wp_error( $response ) ) { return $response; } $data = json_decode( (string) wp_remote_retrieve_body( $response ), true ); $data = is_array( $data ) ? $data : array(); $data['_status'] = (int) wp_remote_retrieve_response_code( $response ); return $data; } }