Wordpress API send message

I am an experienced PHP programmer, familiar with CURL and using it with a cookie, and also comfortable with JSON.

That I am not familiar with WordPress 4.1.1, and my goal is simple: remotely invoke a WordPress site both natively and with a plugin (hopefully from the beginning) and:

a) send an article / message and hopefully

b) get a list of user messages sorted by date, as well (for comparison).

From the research so far, I see that you need to log in, and maybe this is a two-step process, including receiving nonce and then sending the message using nonce. Can someone tell me where to look for API documentation or where to start?

+4
source share
2

XML-RPC API, , , curl, , wp.newPost:

// initialize curl
$ch = curl_init();
// set url ie path to xmlrpc.php
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/xmlrpc.php");
// xmlrpc only supports post requests
curl_setopt($ch, CURLOPT_POST, true);
// return transfear
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// setup post data
$content = array(
  'post_type' => 'post',
  'post_content' => 'This is the post content',
  'post_title' => 'This is the post title',
  'post_status' => 'publish',
);
// parameters are blog_id, username, password and content
$params = array(1, '<user>', '<password>', $content);
$params = xmlrpc_encode_request('wp.newPost', $params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// execute the request
curl_exec($ch);
// shutdown curl
curl_close($ch);

, wp.getPosts, , , :

// filter used when retrieving posts
$filter = array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'number' => 50,
  'offset' => 0,
  'orderby' => 'post_title',
);
// fields to include in response
$fields = array(
  'post_title',
  'post_author',
  'post_id',
  'post_content',
);
$params = array(1, '<username>', '<password>', $filter, $fields);
$params = xmlrpc_encode_request('wp.getPosts', $params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// execute query
$response = curl_exec($ch);
// response is xml
$response = simplexml_load_string($response);
// walk over response and figure out if post should be displayed or not
+1

WP, , .

- , , . nonce, IXR, XML.

PHP script. , , . WP.

.

, ?

Script WP:

header('Content-Type: text/plain; charset=utf-8');
$rows = 0;
$date = date('Y-m-d',strtotime($_GET['date'])) . '00:00:00';
$results=mysqli_query("SELECT`comment_post_ID`,`comment_date`,`comment_content`  
  FROM `wp_comments` WHERE `comment_date` > '$date' 
  ORDER BY `comment_post_ID` ASC,`comment_date` ASC);
while ($pats = mysqli_fetch_array($results, MYSQL_NUM)){
  echo "$row[0]\t$row[1]\r\n";
}
echo "$rows\trows\n";

:

http://wp_site.com/script.php?date=m/d/y'

Script PHP script:

header('Content-Type: text/plain; charset=utf-8');
$data = file_get_contents('http://wp_site.com/script.php?date=m/d/y');
$fp = fopen('posts.csv');
fwrite($fp,$data);
fclose($fp);
echo $data

header('Content-Type: text/plain; charset=utf-8');
echo file_get_contents('http://wp_site.com/script.php?date=m/d/y');
0

All Articles