wp_safe_remote_get example


        $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 ( wp_remote_retrieve_header( $response, 'X-Pingback' ) ) {
        return wp_remote_retrieve_header( $response, 'X-Pingback' );
    }

    // Not an (x)html, sgml, or xml page, no use going further.     if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'Content-Type' ) ) ) {
        return false;
    }

    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).     $response = wp_safe_remote_get(
        $url,
        array(
            'timeout'     => 2,
            'httpversion' => '1.0',
        )
    );

    if ( is_wp_error( $response ) ) {
        return false;
    }

    
$url_path     = parse_url( $url, PHP_URL_PATH );
    $url_filename = '';
    if ( is_string( $url_path ) && '' !== $url_path ) {
        $url_filename = basename( $url_path );
    }

    $tmpfname = wp_tempnam( $url_filename );
    if ( ! $tmpfname ) {
        return new WP_Error( 'http_no_file', __( 'Could not create temporary file.' ) );
    }

    $response = wp_safe_remote_get(
        $url,
        array(
            'timeout'  => $timeout,
            'stream'   => true,
            'filename' => $tmpfname,
        )
    );

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

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

        // Fetch URL content.         $request = wp_safe_remote_get( $url$args );
        $html    = wp_remote_retrieve_body( $request );
        if ( $html ) {

            /** * Filters the link types that contain oEmbed provider URLs. * * @since 2.9.0 * * @param string[] $format Array of oEmbed link types. Accepts 'application/json+oembed', * 'text/xml+oembed', and 'application/xml+oembed' (incorrect, * used by at least Vimeo). */
// Let's check the remote site.         $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. */

function wp_remote_fopen( $uri ) {
    $parsed_url = parse_url( $uri );

    if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
        return false;
    }

    $options            = array();
    $options['timeout'] = 10;

    $response = wp_safe_remote_get( $uri$options );

    if ( is_wp_error( $response ) ) {
        return false;
    }

    return wp_remote_retrieve_body( $response );
}

/** * Sets up the WordPress query. * * @since 2.0.0 * * @global WP $wp Current WordPress environment instance. * @global WP_Query $wp_query WordPress Query object. * @global WP_Query $wp_the_query Copy of the WordPress Query object. * * @param string|array $query_vars Default WP_Query arguments. */
Home | Imprint | This part of the site doesn't use cookies.