wp_http_accept_encoding
云策文档标注
概述
wp_http_accept_encoding 是一个 WordPress 过滤器,用于修改 HTTP 请求中可接受的编码类型及其优先级。开发者可以通过此 Hook 自定义编码处理逻辑,但必须返回有效的 $type 值以确保 HTTP 调用成功。
关键要点
- 过滤器名称:wp_http_accept_encoding,用于过滤允许的编码类型数组。
- 参数:$type(编码类型数组)、$url(HTTP 请求的 URL)、$args(HTTP 请求参数)。
- 注意事项:过滤函数必须返回 $type 值,否则 HTTP 调用会失败。
- 引入版本:WordPress 3.6.0。
- 相关函数:WP_Http_Encoding::accept_encoding() 在 wp-includes/class-wp-http-encoding.php 中定义。
代码示例
add_filter( 'wp_http_accept_encoding', 'filter_function_name', 10, 3 );
function filter_function_name( $type, $url, $args ) {
// 在此处编写代码以修改可用的编码类型
return $type;
}
add_action( 'init', 'get_google_home' );
function get_google_home() {
$google = wp_remote_get( "http://google.com" );
}
原文内容
Filters the allowed encoding types.
Parameters
$typestring[]-
Array of what encoding types to accept and their priority values.
$urlstring-
URL of the HTTP request.
$argsarray-
HTTP request arguments.
Source
$type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |
Skip to note 2 content
Steven Lin
Example Migrated from Codex:
add_filter( 'wp_http_accept_encoding', 'filter_function_name', 10, 3 ); function filter_function_name( $type, $url, $args ) { // Write code below to alter available encoding types here return $type; } add_action( 'init', 'get_google_home' ); function get_google_home() { $google = wp_remote_get( "<a href="http://google.com"" rel="nofollow ugc">http://google.com"</a>; ); }