Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class wp_xmlrpc_client {
- protected $_url;
- protected $_username;
- protected $_password;
- protected $_blogid;
- protected $_wp_client;
- public function __construct($url, $username, $password, $blogid = 0)
- {
- if(empty($url)) throw new Exception('$url (parameter 1) not set');
- if(empty($username)) throw new Exception('$username (parameter 2) not set');
- if(empty($password)) throw new Exception('$password (parameter 3) not set');
- if(empty($blogid) && $blogid !== 0) throw new Exception('$blogid (parameter 4) not set');
- $this->_username = $username;
- $this->_password = $password;
- $this->_url = $url;
- $this->_blogid = $blogid;
- $this->_wp_client = new xmlrpc_client($url);
- $this->_wp_client->setSSLVerifyPeer(false);
- }
- public function call($method,$request_params=null)
- {
- //build the params
- $params = array();
- if(is_string($request_params)) $params[] = new xmlrpcval($request_params);
- elseif(is_array($request_params)) foreach($requests_params as $param) $params[] = new xmlrpcval($param);
- $params[] = new xmlrpcval($this->_blogid);
- $params[] = new xmlrpcval($this->_username);
- $params[] = new xmlrpcval($this->_password);
- $result = $this->_wp_client->send(new xmlrpcmsg('wp.' . $method,$params));
- if($result === false) throw new Exception('Could not send XMLRPC message ' . $method);
- elseif(!$result ->faultCode()) return php_xmlrpc_decode($result->value());
- else throw new Exception('XMLRPC Error Code: ' . htmlspecialchars($result->faultCode()) . ' Error Reason: ' . htmlspecialchars($result->faultString()) );
- }
- public function getPageList()
- {
- return $this->call('getPageList');
- }
- }
Add Comment
Please, Sign In to add comment