是否可以檢查(通過php)在WordPress中是否啓用了XML-RPC。 喜歡的東西,寫一個函數至極將測試這個...如何檢查是否在wordpress中啓用XML-RPC
if(is_xmlrpc_enabled()) {
//action
}
else {
//another action
}
是否可以檢查(通過php)在WordPress中是否啓用了XML-RPC。 喜歡的東西,寫一個函數至極將測試這個...如何檢查是否在wordpress中啓用XML-RPC
if(is_xmlrpc_enabled()) {
//action
}
else {
//another action
}
默認情況下,對於WP版本> 3.5(允許禁用它的'xmlrpc_enabled'鉤子),啓用XML-RPC 對於舊版本,數據庫中有一個字段(選項表) (此選項在wp> 3.5時被刪除)
function is_xmlrpc_enabled() {
$returnBool = false;
$enabled = get_option('enable_xmlrpc'); //for ver<3.5
if($enabled) {
$returnBool = true;
}
else {
global $wp_version;
if (version_compare($wp_version, '3.5', '>=')) {
$returnBool = true; //its on by default for versions above 3.5
}
else {
$returnBool = false;
}
}
return $returnBool;
}
WordPress的在它的XML-RPC服務器兩種測試方法:
demo.sayHello – Returns a standard 「Hello!」 message.
demo.addTwoNumbers – Accepts an array containing two numbers and returns the sum.
function sayHello()
{
$params = array();
return $this->send_request('demo.sayHello',$params);
}
$objXMLRPClientWordPress = new XMLRPClientWordPress("http://localhost/wordpress31/xmlrpc.php" , "username" , "passowrd");
function send_request($requestname, $params)
{
$request = xmlrpc_encode_request($requestname, $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
如果你得到同樣的結果就意味着你能夠正確地將請求發送到您的WordPress XML-RPC服務器並正確接收請求。
+1有關測試方法的解釋 – cool 2013-03-19 21:29:09