wp_remote_fopen

函式
wp_remote_fopen ( $uri )
引數
  • (string) $uri URI/URL of web page to retrieve.
    Required:
返回值
  • (string|false) HTTP content. False on failure.
相關
  • wp_safe_remote_get()
定義位置
相關方法
wp_remote_getwp_remote_postwp_remote_headwp_remote_requestwp_safe_remote_get
引入
1.5.1
棄用
-

wp_remote_fopen: 這個函式用來開啟一個遠端檔案以供閱讀。它接受一個引數:遠端檔案的URL。

對URI的HTTP請求,以檢索內容。

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

常見問題

FAQs
檢視更多 >