Постинг изображений в wordpress через XML-RPC

Май 13

небольшой код

 

$username = "username";
    $password = "password";
    $rpcurl = "http://myblog.com/xmlrpc.php";

    $image = fopen("file.jpg","r");
    $file = fread($image,filesize("file.jpg"));
    fclose($image);
    $filetype = "image/jpeg";
    $filename = "testimage.jpg";

$result = wpUploadFileXMLRPC($blogid,$rpcurl,$username,$password,$filename, $filetype, $file);
echo(print_r($result));

function wpUploadFileXMLRPC($blogid,$rpcurl,$username,$password,$filename, $filetype, $file){

    $params = array('',$username,$password,array('name'=>$filename, 'type'=>$filetype,'bits'=>$file,'overwrite'=>true));
    $request = xmlrpc_encode_request('wp.uploadFile',$params);
    $result = makeCall($request,$rpcurl);

    return($result);
}

Одно имя категории, разные родители.

Фев 20

Полночи бился с этим тупняком.

Суть – есть сайт, две основных категории – Ищу работу и Требуются. В них подкатегории. Подкатегории одинаковые, потому что слесари могут и требоваться и искать работу.

Постим туда через xml-rpc. Например, Иванов Иван, ищет слесаря в свою фирму. Т.е. категория слесарь родителя Требуются. Но при постинге не указывается родитель, указывается только имя категории – слесарь. И постится в тот родитель, который создан раньше. В моем случае Иванов Иван уже не ищет слесаря, а сам хочет им поработать.

Почитал доки по xml-rpc, ничего так и не нашел. Выход нашел, но не очень красивый.

Вот как тут быть?

Добавить postmeta через xml rpc

Фев 15

Или рожденные в муках познания.  XML-RPC как-то не очень дружит с документацией, никаких особо внятных вещей по поводу формата postmeta я так и не нашел.  И если как ставить какой-нибудь excerpt еще можно догадаться:

$content_struct['mt_excerpt'] = "string";

то вот до выставления даты можно долго доходить:

$date = gmdate("Ymd\TH:i:s",strtotime("+".rand(0,20)." day +
".rand(0,20)." hour +".rand(0,60)." minute"));
$content_struct['dateCreated'] = new IXR_Date($date);

В примере дата на 20 дней вперед-назад разносится.

Custom fields выставляются так:

$custom_fields = array(
     array(
                'key'  => 'price',
		'value'	 => 'val1'
	),
);
$content_struct['custom_fields']= $custom_fields;

XML-RPC wordpress

Июл 10

Note: This API is current as of the 2.7.1 release.

wp.getUsersBlogs

Retrieve the blogs of the users.

Parameters

  • string username
  • string password

Return Values

  • array
    • struct
      • boolean is_admin
      • string url
      • int blog_id
      • string blog_name
      • string xmlrpc_url

wp.getTags

Get list of all tags.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • struct
      • int tag_id
      • string name
      • int count
      • string slug
      • string html_url
      • string rss_url

wp.getCommentCount

Retrieve comment count for a specific post.

Parameters

  • int blog_id
  • string username
  • string password
  • string post_id

Return Values

  • array
    • struct
      • int approved
      • int awaiting_moderation
      • int spam
      • int total_comments

wp.getPostStatusList

Retrieve post statuses.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • const string ‘draft’
    • const string ‘pending’
    • const string ‘private’
    • const string ‘publish’

wp.getPageStatusList

Retrieve all of the WordPress supported page statuses.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • const string ‘draft’
    • const string ‘private’
    • const string ‘publish’

wp.getPageTemplates

Retrieve page templates.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • struct
      • string name
      • string description

wp.getOptions

Retrieve blog options. If passing in an array, search for options listed within it.

Parameters

  • int blog_id
  • string username
  • string password
  • array
    • string option

Return Values

  • array
    • struct
      • string option
      • string value

wp.setOptions

Update blog options. Returns array of structs showing updated values.

Parameters

  • int blog_id
  • string username
  • string password
  • array
    • struct
      • string name
      • string value

Return Values

  • array
    • struct
      • string option
      • string value

wp.deleteComment

Remove comment.

Parameters

  • int blog_id
  • string username
  • string password
  • int comment_id

Return Values

  • boolean status

wp.editComment

Edit comment.

Parameters

  • int blog_id
  • string username
  • string password
  • int comment_id
  • struct comment
    • string comment_status
    • date date_created_gmt
    • string content
    • string author
    • string author_url
    • string author_email

Return Values

  • boolean status

wp.newComment

Create new comment.

Parameters

  • int blog_id
  • string username
  • string password
  • int post_id
  • struct comment
    • int comment_parent
    • string content
    • string author
    • string author_url
    • string author_email

Return Values

  • int comment_id

wp.getCommentStatusList

Retrieve all of the comment status.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • struct
    • string hold
    • string approve
    • string spam

wp.getPage

Get the page identified by the page id.

Parameters

  • int blog_id
  • int page_id
  • string username
  • string password

Return Values

  • struct
    • datetime dateCreated (ISO.8601)
    • int userid
    • int page_id
    • string page_status
    • string description
    • string title
    • string link
    • string permaLink
    • array categories
      • string Category Name
    • string excerpt
    • string text_more
    • int mt_allow_comments
    • int mt_allow_pings
    • string wp_slug
    • string wp_password
    • string wp_author
    • int wp_page_parent_id
    • string wp_page_parent_title
    • int wp_page_order
    • int wp_author_id
    • string wp_author_display_name
    • datetime date_created_gmt
    • array custom_fields
      • struct
        • string id
        • string key
        • string value
    • string wp_page_template

wp.getPages

Get an array of all the pages on a blog.

Parameters

  • int blog_id
  • string username
  • string password

Return Values


wp.getPageList

Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • struct
      • int page_id
      • string page_title
      • int page_parent_id
      • datetime dateCreated

wp.newPage

Create a new page. Similar to metaWeblog.newPost.

Parameters

  • int blog_id
  • string username
  • string password
  • struct content
    • string wp_slug
    • string wp_password
    • int wp_page_parent_id
    • int wp_page_order
    • int wp_author_id
    • string title
    • string description (content of post)
    • string mt_excerpt
    • string mt_text_more
    • int mt_allow_comments (0 = closed, 1 = open)
    • int mt_allow_pings (0 = closed, 1 = open)
    • datetime dateCreated
    • array custom_fields
      • struct
      • Same struct data as custom_fields in wp.getPage
  • bool publish

Return Values

  • int page_id

wp.deletePage

Removes a page from the blog.

Parameters

  • int blog_id
  • string username
  • string password
  • int page_id

Return Values

  • bool true

wp.editPage

Make changes to a blog page.

Parameters

  • int blog_id
  • int page_id
  • string username
  • string password
  • struct content
  • bool publish

Return Values

  • bool true

wp.getAuthors

Get an array of users for the blog.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • struct
      • int user_id
      • string user_login
      • string display_name
      • string user_email
      • string meta_value (Serialized PHP data)

wp.getCategories

Get an array of available categories on a blog.

Parameters

  • int blog_id
  • string username
  • string password

Return Values

  • array
    • struct
      • int categoryId
      • int parentId
      • string description
      • string categoryName
      • string htmlUrl
      • string rssUrl

wp.newCategory

Create a new category.

Parameters

  • int blog_id
  • string username
  • string password
  • struct
    • string name
    • string slug
    • int parent_id
    • string description

Return Values

  • int category_id

wp.deleteCategory

Delete a category.

Parameters

  • int blog_id
  • string username
  • string password
  • int category_id

Return Values

  • ?

wp.suggestCategories

Get an array of categories that start with a given string.

Parameters

  • int blog_id
  • string username
  • string password
  • string category
  • int max_results

Return Values

  • array
    • struct
      • int category_id
      • string category_name

wp.uploadFile

Upload a file.

Parameters

  • int blog_id
  • string username
  • string password
  • struct data
    • string name
    • string type
    • base64 bits
    • bool overwrite

Return Values

  • struct
    • string file
    • string url
    • string type

wp.getComment

Gets a comment, given it’s comment ID. Note that this isn’t in 2.6.1, but is in the HEAD (so should be in anything newer than 2.6.1)

Parameters

  • int blog_id
  • string username
  • string password
  • int comment_id

Return Values

  • struct
    • datetime dateCreated (ISO.8601, always GMT)
    • string user_id
    • string comment_id
    • string parent
    • string status
    • string content
    • string link
    • string post_id
    • string post_title
    • string author
    • string author_url
    • string author_email
    • string author_ip

wp.getComments

Gets a set of comments for a given post. Note that this isn’t in 2.6.1, but is in the HEAD (so should be in anything newer than 2.6.1).

Parameters

  • int blog_id
  • string username
  • string password
  • struct
    • post_id
    • status (approve is good. blank means ALL)
    • offset
    • number

Return Values

Returns an array of the comment structure (see wp.getComment)

  • struct
    • datetime dateCreated (ISO.8601, always GMT)
    • string user_id
    • string comment_id
    • string parent
    • string status
    • string content
    • string link
    • string post_id
    • string post_title
    • string author
    • string author_url
    • string author_email
    • string author_ip

http://codex.wordpress.org/XML-RPC_wp

32700:parse error. not well formed

Июл 10

На заметку.
Иногда выскакивает при постинге через XML-RPC.
Причина в неверно оформленном отправляемом запросе. У меня выдавалась еще и потому, что кодировка отличная от UTF-8 была