Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check is XML-RPC enabled in WordPress

Is it possible to check (via php) is XML-RPC enabled in WordPress? Something like, to write a function which will test this.

if(is_xmlrpc_enabled()) {
   //action
}
else {
   //another action
}
like image 355
cool Avatar asked Mar 19 '13 13:03

cool


2 Answers

XML-RPC is enabled by default for WP versions > 3.5 (with 'xmlrpc_enabled' hook which allow to disable it) For older versions, there is a field in the database (options table), which indicates if it is enabled or not.(This option is removed for 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;
}
like image 93
cool Avatar answered Nov 05 '22 16:11

cool


WordPress has two test methods in its XML-RPC server:

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;  
}  

If you get the same result it means you are able to send the request properly to your WordPress XML-RPC server and receive the request properly.

like image 43
Subodh Ghulaxe Avatar answered Nov 05 '22 17:11

Subodh Ghulaxe