wp_remote_fopen() WordPress Function

The wp_remote_fopen() function is used to open a remote file using the HTTP or FTP protocol. This function is available on servers running WordPress 4.4 or higher.

wp_remote_fopen( string $uri ) #

HTTP request for URI to retrieve content.


Description

Top ↑

See also


Top ↑

Parameters

$uri

(string)(Required)URI/URL of web page to retrieve.


Top ↑

Return

(string|false) HTTP content. False on failure.


Top ↑

More Information

See Plugin Handbook: HTTP API


Top ↑

Source

File: wp-includes/functions.php

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


Top ↑

Changelog

Changelog
VersionDescription
1.5.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More