wp_remote_retrieve_response_code example

|| ( isset( $results['data']['version'] ) && ! str_starts_with( $version$results['data']['version'] ) )
    ) {
        $url     = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
        $options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );

        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 );
    }

    

        $args = apply_filters( 'rest_url_details_http_request_args', $args$url );

        $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 ) ) {
            

    private function _fetch_with_format( $provider_url_with_args$format ) {
        $provider_url_with_args = add_query_arg( 'format', $format$provider_url_with_args );

        /** This filter is documented in wp-includes/class-wp-oembed.php */
        $args = apply_filters( 'oembed_remote_get_args', array()$provider_url_with_args );

        $response = wp_safe_remote_get( $provider_url_with_args$args );

        if ( 501 === wp_remote_retrieve_response_code( $response ) ) {
            return new WP_Error( 'not-implemented' );
        }

        $body = wp_remote_retrieve_body( $response );
        if ( ! $body ) {
            return false;
        }

        $parse_method = "_parse_$format";

        return $this->$parse_method( $body );
    }
'timeout'  => $timeout,
            'stream'   => true,
            'filename' => $tmpfname,
        )
    );

    if ( is_wp_error( $response ) ) {
        unlink( $tmpfname );
        return $response;
    }

    $response_code = wp_remote_retrieve_response_code( $response );

    if ( 200 !== $response_code ) {
        $data = array(
            'code' => $response_code,
        );

        // Retrieve a sample of the response body for debugging purposes.         $tmpf = fopen( $tmpfname, 'rb' );

        if ( $tmpf ) {
            /** * Filters the maximum error response body size in `download_url()`. * * @since 5.1.0 * * @see download_url() * * @param int $size The maximum error response body size. Default 1 KB. */


        $response = wp_remote_post( $url$args );

        if ( is_wp_error( $response ) ) {
            $errno       = $response->get_error_code();
            $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() ) {
            

function url_is_accessable_via_ssl( $url ) {
    _deprecated_function( __FUNCTION__, '4.0.0' );

    $response = wp_remote_get( set_url_scheme( $url, 'https' ) );

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

    return false;
}

/** * Start preview theme output buffer. * * Will only perform task if the user has permissions and template and preview * query variables exist. * * @since 2.6.0 * @deprecated 4.3.0 */
trigger_error(
            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/' )
            ) . ' ' . __( '(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'];

    
        require ABSPATH . WPINC . '/version.php';

        $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 )
            );
        }
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/' )
            ) . ' ' . __( '(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'];
}
continue;
                    }

                    if ( 'content-type' === $name ) {
                        $this->headers[ $name ] = array_pop( $value );
                    } else {
                        $this->headers[ $name ] = implode( ', ', $value );
                    }
                }

                $this->body        = wp_remote_retrieve_body( $res );
                $this->status_code = wp_remote_retrieve_response_code( $res );
            }
        } else {
            $this->error   = '';
            $this->success = false;
        }
    }
}
// translators: %s: The REST API URL.                     __( 'REST API Endpoint: %s' ),
                    $url
                ),
                sprintf(
                    // translators: 1: The WordPress error code. 2: The WordPress error message.                     __( 'REST API Response: (%1$s) %2$s' ),
                    $r->get_error_code(),
                    $r->get_error_message()
                )
            );
        } elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
            $result['status'] = 'recommended';

            $result['label'] = __( 'The REST API encountered an unexpected result' );

            $result['description'] .= sprintf(
                '<p>%s</p><p>%s<br>%s</p>',
                __( 'When testing the REST API, an unexpected result was returned:' ),
                sprintf(
                    // translators: %s: The REST API URL.                     __( 'REST API Endpoint: %s' ),
                    $url
                ),
    $return_headers = array();
    foreach ( wp_remote_retrieve_headers( $resp ) as $key => $value ) {
        if ( !is_array($value) ) {
            $return_headers[] = "$key: $value";
        } else {
            foreach ( $value as $v )
                $return_headers[] = "$key: $v";
        }
    }

    $response = new stdClass;
    $response->status = wp_remote_retrieve_response_code( $resp );
    $response->response_code = wp_remote_retrieve_response_code( $resp );
    $response->headers = $return_headers;
    $response->results = wp_remote_retrieve_body( $resp );

    return $response;
}

/** * Retrieve * * @since 1.5.0 * @package External * @subpackage MagpieRSS * * @param array $resp * @return MagpieRSS|bool */
 else {
            $support_errors->add(
                '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 ( false === $response ) {
        $url = 'http://api.wordpress.org/core/serve-happy/1.0/';

        if ( wp_http_supports( array( 'ssl' ) ) ) {
            $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 );
    }

    
$options = array(
            'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
        );

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

        $response = wp_remote_post( $url$options );

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

        /** * Response should be an array with: * 'platform' - string - A user-friendly platform name, if it can be determined * 'name' - string - A user-friendly browser name * 'version' - string - The version of the browser the user is using * 'current_version' - string - The most recent version of the browser * 'upgrade' - boolean - Whether the browser needs an upgrade * 'insecure' - boolean - Whether the browser is deemed insecure * 'update_url' - string - The url to visit to upgrade * 'img_src' - string - An image representing the browser * 'img_src_ssl' - string - An image (over SSL) representing the browser */
Home | Imprint | This part of the site doesn't use cookies.