如何使用“ http_request_host_is_external”过滤器
2 个回答
- 投票数
-
- 2013-11-14
您可以执行以下操作:
add_filter( 'http_request_host_is_external', '__return_true' );
但是,请注意,这会禁用此安全功能.如果您知道主机或url不会改变,并且始终会保持不变,则可以通过明确检查主机或url来更安全:
add_filter( 'http_request_host_is_external', 'allow_my_custom_host', 10, 3 ); function allow_my_custom_host( $allow, $host, $url ) { if ( $host == 'my-update-server' ) $allow = true; return $allow; }
You can do this:
add_filter( 'http_request_host_is_external', '__return_true' );
However, note that this disables this security feature. If you know the host or url isn't going to change and is always going to be that, you can be more secure by checking for that explicitly:
add_filter( 'http_request_host_is_external', 'allow_my_custom_host', 10, 3 ); function allow_my_custom_host( $allow, $host, $url ) { if ( $host == 'my-update-server' ) $allow = true; return $allow; }
-
(,,10,3)的第三个和第四个参数是什么?What are the 3rd and 4th arguments for (,,10,3)?
- 0
- 2013-11-15
- Jack Slingerland
-
10是过滤器的优先级(默认设置为10),而3是传递给过滤器函数的参数数(默认为1).这就是为什么我必须在此处添加10、3的原因,因为我希望函数获取传递给它的$ host和$ url值.The 10 is the priority of the filter (10 is the default setting), and the 3 is the number of arguments to pass to the filter function (the default is 1). This is why I had to add the 10, 3 here, because I want the function to get the $host and $url values passed to it.
- 1
- 2013-11-15
- Otto
-
- 2013-11-14
我似乎有些生锈.这是为我照顾的:
add_filter( 'http_request_host_is_external', function() { return true; });
I'm apparently a little rusty. This took care of it for me:
add_filter( 'http_request_host_is_external', function() { return true; });
我很难使用
http_request_host_is_external
过滤器.对于某些背景,我试图设置一个单独的服务器来处理私有插件和主题更新.问题在于它在单独的服务器上,因此Wordpresswp_http_validate_url
(wp-includes/http.php)函数会终止该请求.以下是该文件的第481-503行.您会注意到其中有一条评论,其中提到我们应该能够应用过滤器并发出外部请求,但我尝试执行的操作似乎无效.
我认为,如果我在插件的主文件中设置过滤器,它会解决这个问题,但是我认为问题在于外部请求正发生在Wordpress的更新程序中,所以也许我的过滤器不适用?