注意:代码没有经过测试-我不知道您的服务器设置等-只是我脑子里写出来的。您必须对其进行测试,找到合并参数的正确位置,并设置URL等。
如果自定义远程存储库发回可用的头(这种情况并不常见),那么初始测试(#1)可以得到改进。所以如果是这样,你最好使用wp_remote_head()
相反,它使HTTP请求更加轻量级。
<?php
defined( \'ABSPATH\' ) OR exit;
/**
* Plugin Name: (#78267) Custom Theme Update Args
* Description: Adds custom arguments to the HTTP request for a theme or plugin update from a custom location.
* Version: 2013-04-02.2139
* Author: Franz Josef Kaiser <[email protected]>
* Author URI: http://unserkaiser.com
* License: The MIT License (MIT)
* LicenseURI: http://www.opensource.org/licenses/mit-license.php
*/
add_filter( \'http_request_args\', \'custom_upgrade_process\', 9, 2 );
/**
* Callback for a HTTP request used to switch the
* SSL verification in case of a WP error response
* and routing to a custom Theme or Plugin repository.
* @param array $r Request arguments
* @param string $url Request URL
* @return array $r
*/
function custom_upgrade_process( $r, $url )
{
// Alter the following settings according to your
// update procedure and admin pages that deliver it.
# A) The admin URL
$custom_repo = \'https://example.com?foo=bar\';
if (
0 !== strpos( $url, \'http://api.wordpress.org/plugins/update-check\' )
XOR 0 !== strpos( $url, \'http://api.wordpress.org/themes/update-check\' )
)
return $r;
# 1) Do an initial test to check if things are working as expected
$response = wp_remote_get(
$custom_repo,
array(
\'timeout\' => 120,
\'httpversion\' => \'1.1\',
)
);
# 2) Turn off SSL verification in case the HTTP request didn\'t work out
if (
is_wp_error( $response )
AND strstr( $response->get_error_message(), \'SSL: certificate subject name\' )
)
add_filter( \'https_ssl_verify\', \'__return_false\' );
# 3) Add your custom request arguments
$r = array_merge( $r, array(
\'login\' => get_option( \'login\' ),
\'pass\' => get_option( \'pass\' ),
) );
return $r;
}
祝你好运。:)