WordPress函数:wp_remote_retrieve_response_code 从原始响应中获取响应代码

江河/ 2023年10月13日/ WordPress/ 浏览 433

函数原型:


wp_remote_retrieve_response_code( array|WP_Error $response ): int|string


从原始响应中获取响应代码。如果给定的参数值不正确,将返回一个空字符串。


函数源码:


function wp_remote_retrieve_response_code( $response ) {
	if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
		return '';
	}

	return $response['response']['code'];
}


使用举例:


$response = wp_remote_get( 'http://www.foo.com/file.txt' );
$response_code = wp_remote_retrieve_response_code( $response );


发表评论

暂无评论,抢个沙发...

客服 工单