8

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
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
cool
  • 3,225
  • 3
  • 33
  • 58

2 Answers2

8

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;
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
cool
  • 3,225
  • 3
  • 33
  • 58
  • Can works fine, but some hosting company doesn't allow XML-RPC connexion by default for security reasons, and then your script will not work. – Benoti Mar 16 '19 at 10:20
  • The question states "is xmlrpc enabled in wordpress" and it is as it is. Means that I am interested for the software level check. If you have some kind of protocol filtering which is done on the network level - the xmlrpc is STIL enabled on the level of the wordpress, but its not going to work due to the network restriction. In that specific case you will need to implement method with different approach (or consult with the hosting company, because that kind of restriction is weird). So the method above will work in any case, for the purpose which is written (and for the time when i used it) – cool Mar 17 '19 at 14:02
4

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.

Subodh Ghulaxe
  • 18,333
  • 14
  • 83
  • 102