Advertisement
janter13

WP XMLRPC POST

Feb 11th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2.  
  3. // WP XMLRPC POST
  4.  
  5. function api_post($rpc, $method, $filter){
  6. $USERNAME = "";
  7. $PASSWORD = "";
  8. $status = $rpc->query($method, "1", $USERNAME, $PASSWORD, $filter);
  9. if(!$status){
  10.     print "Error (".$rpc->getErrorCode()."):";
  11.     print $rpc->getErrorMessage()."\n";
  12.     exit;
  13. }
  14.  
  15. $comment = $rpc->getResponse();
  16.     return $comment;
  17. }
  18.  
  19. function do_post($type, $isi, $kategori, $judul, $domen){
  20.     $post_req['post_type'] = $type;
  21.     $post_req['post_status'] = 'publish';
  22.     $post_req['post_title'] = $judul;
  23.     $post_req['post_author'] = 1;
  24.     $post_req['post_excerpt'] = '';
  25.     $post_req['post_content'] = $isi;
  26.     $post_req['post_parent'] = 0;
  27.     $post_req['post_format'] = 'standard';
  28.     $post_req['post_password'] = '';
  29.     $post_req['comment_status'] = 'open';
  30.     $post_req['terms_names']['category'][0] = $kategori;
  31.     $post_req['custom_fields'][0]['key'] = 'post_views_count';
  32.     $post_req['custom_fields'][0]['value'] = 0;
  33.     $isi_post = api_post($rpc, 'wp.newPost', $post_req);
  34.     $slug = api_post($rpc, 'wp.getPost', $isi_post);
  35.     return '<a href="http://'.$domen.'/'.$slug['post_name'].'">'.$slug['post_title'].'<a><br>';
  36.     }
  37. ?>
  38. /*
  39. disini form atur2 episode..
  40. pake jquery buat nambah form episode / gmn gt..
  41. <?php
  42. if(isset(....)){
  43.     // pake aja foreach / while / for, buat looping
  44.     require "IXR_Library.php";
  45.     $target_domain = "";
  46.     $rpc = new IXR_Client('http://'.$target_domain.'/xmlrpc.php');
  47.     echo do_post($type, $isi, $kategori, $judul, $target_domain);
  48.    
  49. ?>
  50. */
  51. ///// TESTING
  52. <?php
  53.     require "IXR_Library.php";
  54.     $target_domain = "anu.com";
  55.     $judul = 'testing judul';
  56.     $type = 'post';
  57.     $kategori = 'testing kategori';
  58.     $isi = 'testing isi post';
  59.     $rpc = new IXR_Client('http://'.$target_domain.'/xmlrpc.php');
  60.     echo do_post($type, $isi, $kategori, $judul, $target_domain);
  61.    
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement