How to check if XML-RPC is supported in wordpress

Is it possible to verify (via php) that XML-RPC is included in wordpress. Something like to write a function that will check this ...

if(is_xmlrpc_enabled()) { //action } else { //another action } 
+7
source share
2 answers

XML-RPC is enabled by default for versions WP> 3.5 (with a hook "xmlrpc_enabled" that allows you to disable it) For older versions, the database (option table) has a field that indicates whether it is enabled or not. (This option has been 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; } 
+7
source

WordPress has two testing methods on 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 that you can correctly send the request to your WordPress XML-RPC server and correctly receive the request.

+3
source

All Articles