Guest User

Untitled

a guest
Mar 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2. class wp_xmlrpc_client {
  3. protected $_url;
  4. protected $_username;
  5. protected $_password;
  6. protected $_blogid;
  7. protected $_wp_client;
  8.  
  9. public function __construct($url, $username, $password, $blogid = 0)
  10. {
  11. if(empty($url)) throw new Exception('$url (parameter 1) not set');
  12. if(empty($username)) throw new Exception('$username (parameter 2) not set');
  13. if(empty($password)) throw new Exception('$password (parameter 3) not set');
  14. if(empty($blogid) && $blogid !== 0) throw new Exception('$blogid (parameter 4) not set');
  15.  
  16. $this->_username = $username;
  17. $this->_password = $password;
  18. $this->_url = $url;
  19. $this->_blogid = $blogid;
  20.  
  21. $this->_wp_client = new xmlrpc_client($url);
  22. $this->_wp_client->setSSLVerifyPeer(false);
  23.  
  24. }
  25.  
  26. public function call($method,$request_params=null)
  27. {
  28. //build the params
  29. $params = array();
  30.  
  31. if(is_string($request_params)) $params[] = new xmlrpcval($request_params);
  32. elseif(is_array($request_params)) foreach($requests_params as $param) $params[] = new xmlrpcval($param);
  33.  
  34. $params[] = new xmlrpcval($this->_blogid);
  35. $params[] = new xmlrpcval($this->_username);
  36. $params[] = new xmlrpcval($this->_password);
  37.  
  38. $result = $this->_wp_client->send(new xmlrpcmsg('wp.' . $method,$params));
  39.  
  40. if($result === false) throw new Exception('Could not send XMLRPC message ' . $method);
  41. elseif(!$result ->faultCode()) return php_xmlrpc_decode($result->value());
  42. else throw new Exception('XMLRPC Error Code: ' . htmlspecialchars($result->faultCode()) . ' Error Reason: ' . htmlspecialchars($result->faultString()) );
  43. }
  44.  
  45. public function getPageList()
  46. {
  47. return $this->call('getPageList');
  48. }
  49. }
Add Comment
Please, Sign In to add comment