wp_remote_retrieve_body example

if ( is_wp_error( $request ) ) {
            $res = new WP_Error(
                'translations_api_failed',
                sprintf(
                    /* translators: %s: Support forums URL. */
                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                    __( 'https://wordpress.org/support/forums/' )
                ),
                $request->get_error_message()
            );
        } else {
            $res = json_decode( wp_remote_retrieve_body( $request ), true );
            if ( ! is_object( $res ) && ! is_array( $res ) ) {
                $res = new WP_Error(
                    'translations_api_failed',
                    sprintf(
                        /* translators: %s: Support forums URL. */
                        __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                        __( 'https://wordpress.org/support/forums/' )
                    ),
                    wp_remote_retrieve_body( $request )
                );
            }
        }
 . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
            headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
        );

        $response = wp_remote_get( $http_url$options );
    }

    if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
        return false;
    }

    $body = trim( wp_remote_retrieve_body( $response ) );
    $body = json_decode( $body, true );

    if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
        return false;
    }

    return $body['checksums'];
}

/** * Dismisses core update. * * @since 2.7.0 * * @param object $update * @return bool */
if ( is_wp_error( $request ) ) {
            $res = new WP_Error(
                'plugins_api_failed',
                sprintf(
                    /* translators: %s: Support forums URL. */
                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                    __( 'https://wordpress.org/support/forums/' )
                ),
                $request->get_error_message()
            );
        } else {
            $res = json_decode( wp_remote_retrieve_body( $request ), true );
            if ( is_array( $res ) ) {
                // Object casting is required in order to match the info/1.0 format.                 $res = (object) $res;
            } elseif ( null === $res ) {
                $res = new WP_Error(
                    'plugins_api_failed',
                    sprintf(
                        /* translators: %s: Support forums URL. */
                        __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                        __( 'https://wordpress.org/support/forums/' )
                    ),
                    
'ssl_verification_failed',
                __( 'SSL verification failed.' )
            );
        }

        $response = $unverified_response;
    }

    if ( ! is_wp_error( $response ) ) {
        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
            $support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) );
        } elseif ( false === wp_is_local_html_output( wp_remote_retrieve_body( $response ) ) ) {
            $support_errors->add( 'bad_response_source', __( 'It looks like the response did not come from this site.' ) );
        }
    }

    update_option( 'https_detection_errors', $support_errors->errors );
}

/** * Schedules the Cron hook for detecting HTTPS support. * * @since 5.7.0 * @access private */

        }

        if ( ! empty( $keys_salts ) ) {
            $keys_salts_str = '';
            $from_api       = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
            if ( is_wp_error( $from_api ) ) {
                foreach ( $keys_salts as $c => $v ) {
                    $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
                }
            } else {
                $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
                foreach ( $keys_salts as $c => $v ) {
                    $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
                }
            }
            $num_keys_salts = count( $keys_salts );
            ?> <p id="network-wpconfig-authentication-description"> <?php             if ( 1 === $num_keys_salts ) {
                printf(
                    /* translators: %s: wp-config.php */
                    
$url = set_url_scheme( $url, 'https' );
        }

        $url = add_query_arg( 'php_version', $version$url );

        $response = wp_remote_get( $url );

        if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
            return false;
        }

        $response = json_decode( wp_remote_retrieve_body( $response ), true );

        if ( ! is_array( $response ) ) {
            return false;
        }

        set_site_transient( 'php_check_' . $key$response, WEEK_IN_SECONDS );
    }

    if ( isset( $response['is_acceptable'] ) && $response['is_acceptable'] ) {
        /** * Filters whether the active PHP version is considered acceptable by WordPress. * * Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators. * * This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring * that this filter can only make this check stricter, but not loosen it. * * @since 5.1.1 * * @param bool $is_acceptable Whether the PHP version is considered acceptable. Default true. * @param string $version PHP version checked. */
if ( ! $no_api ) {
                $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
            }

            if ( $no_api || is_wp_error( $secret_keys ) ) {
                $secret_keys = array();
                for ( $i = 0; $i < 8; $i++ ) {
                    $secret_keys[] = wp_generate_password( 64, true, true );
                }
            } else {
                $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) );
                foreach ( $secret_keys as $k => $v ) {
                    $secret_keys[ $k ] = substr( $v, 28, 64 );
                }
            }
        }

        $key = 0;
        foreach ( $config_file as $line_num => $line ) {
            if ( str_starts_with( $line, '$table_prefix =' ) ) {
                $config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
                continue;
            }
if ( wp_http_supports( array( 'ssl' ) ) ) {
            $url = set_url_scheme( $url, 'https' );
        }

        $response = wp_remote_get( $url$options );

        if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
            return false;
        }

        $results = json_decode( wp_remote_retrieve_body( $response ), true );

        if ( ! is_array( $results ) ) {
            return false;
        }

        set_site_transient( 'wordpress_credits_' . $locale$results, DAY_IN_SECONDS );
    }

    return $results;
}

$errorstr    = $response->get_error_message();
            $this->error = new IXR_Error( -32300, "transport error: $errno $errorstr);
            return false;
        }

        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
            $this->error = new IXR_Error( -32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')' );
            return false;
        }

        if ( $this->debug ) {
            echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
        }

        // Now parse what we've got back.         $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
        if ( ! $this->message->parse() ) {
            // XML error.             $this->error = new IXR_Error( -32700, 'parse error. not well formed' );
            return false;
        }

        // Is the message a fault?
__( 'https://wordpress.org/support/forums/' )
            ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
            headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
        );
        $response = wp_remote_post( $http_url$options );
    }

    if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
        return;
    }

    $body = trim( wp_remote_retrieve_body( $response ) );
    $body = json_decode( $body, true );

    if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) {
        return;
    }

    $offers = $body['offers'];

    foreach ( $offers as &$offer ) {
        foreach ( $offer as $offer_key => $value ) {
            if ( 'packages' === $offer_key ) {
                
$response = wp_safe_remote_get( $url$args );

        if ( WP_Http::OK !== wp_remote_retrieve_response_code( $response ) ) {
            // Not saving the error response to cache since the error might be temporary.             return new WP_Error(
                'no_response',
                __( 'URL not found. Response returned a non-200 status code for this URL.' ),
                array( 'status' => WP_Http::NOT_FOUND )
            );
        }

        $remote_body = wp_remote_retrieve_body( $response );

        if ( empty( $remote_body ) ) {
            return new WP_Error(
                'no_content',
                __( 'Unable to retrieve body from response at this URL.' ),
                array( 'status' => WP_Http::NOT_FOUND )
            );
        }

        return $remote_body;
    }

    
        $http_api_args = array(
            'timeout'             => 10,
            'redirection'         => 0,
            'limit_response_size' => 153600, // 150 KB             'user-agent'          => "$user_agent; verifying pingback from $remote_ip",
            'headers'             => array(
                'X-Pingback-Forwarded-For' => $remote_ip,
            ),
        );

        $request                = wp_safe_remote_get( $pagelinkedfrom$http_api_args );
        $remote_source          = wp_remote_retrieve_body( $request );
        $remote_source_original = $remote_source;

        if ( ! $remote_source ) {
            return $this->pingback_error( 16, __( 'The source URL does not exist.' ) );
        }

        /** * Filters the pingback remote source. * * @since 2.5.0 * * @param string $remote_source Response source for the page linked from. * @param string $pagelinkedto URL of the page linked to. */

        else {
            $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' );
        }

        $debug[ 'gethostbynamel' ]  = function_exists('gethostbynamel') ? 'exists' : 'not here';
        $debug[ 'Servers' ]         = $servers;
        $debug[ 'Test Connection' ] = $response;
        
        Akismet::log( $debug );
        
        if ( $response && 'connected' == wp_remote_retrieve_body( $response ) )
            return true;
        
        return false;
    }

    // Check the server connectivity and store the available servers in an option.     public static function get_server_connectivity($cache_timeout = 86400) {
        return self::check_server_connectivity( $cache_timeout );
    }

    /** * Find out whether any comments in the Pending queue have not yet been checked by Akismet. * * @return bool */
$api_url                    = 'http://api.wordpress.org/events/1.0/';
        $request_args               = $this->get_request_args( $location_search$timezone );
        $request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );

        if ( wp_http_supports( array( 'ssl' ) ) ) {
            $api_url = set_url_scheme( $api_url, 'https' );
        }

        $response       = wp_remote_get( $api_url$request_args );
        $response_code  = wp_remote_retrieve_response_code( $response );
        $response_body  = json_decode( wp_remote_retrieve_body( $response ), true );
        $response_error = null;

        if ( is_wp_error( $response ) ) {
            $response_error = $response;
        } elseif ( 200 !== $response_code ) {
            $response_error = new WP_Error(
                'api-error',
                /* translators: %d: Numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */
                sprintf( __( 'Invalid API response code (%d).' )$response_code )
            );
        } elseif ( ! isset( $response_body['location']$response_body['events'] ) ) {
            
function get_block_editor_theme_styles() {
    global $editor_styles;

    $styles = array();

    if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
        foreach ( $editor_styles as $style ) {
            if ( preg_match( '~^(https?:)?//~', $style ) ) {
                $response = wp_remote_get( $style );
                if ( ! is_wp_error( $response ) ) {
                    $styles[] = array(
                        'css'            => wp_remote_retrieve_body( $response ),
                        '__unstableType' => 'theme',
                        'isGlobalStyles' => false,
                    );
                }
            } else {
                $file = get_theme_file_path( $style );
                if ( is_file( $file ) ) {
                    $styles[] = array(
                        'css'            => file_get_contents( $file ),
                        'baseURL'        => get_theme_file_uri( $style ),
                        '__unstableType' => 'theme',
                        
Home | Imprint | This part of the site doesn't use cookies.