前に書いたヤツを少しだけキレイに。
pearのXML_RPCモジュールをインストールしておく
1 |
$ sudo pear install XML_RPC |
↓ソースここから。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
require_once("XML/RPC.php"); $host = "hogehoge.com"; // WordPressのHost名 $user = "username"; // WordPressのユーザ名 $pass = "password"; // WordPressのパスワード $xmlrpc = "/xmlrpc.php"; // XMLRPCのパス $port = 80; // ポート番号 $blogid = 1; // blog ID $title = "記事のタイトル"; $description = "記事の本文"; $publish = 1; // 0:下書き、1:公開 $category1 = 1; // カテゴリID $category2 = 5; // カテゴリID $category3 = 8; // カテゴリID /* 投稿処理 */ // クライアント生成 $Client = new XML_RPC_client($xmlrpc, $host, $port); // メッセージ作成 $Message = new XML_RPC_Message( "metaWeblog.newPost", array( new XML_RPC_Value($blogid, "string"), new XML_RPC_Value($user, "string"), new XML_RPC_Value($pass, "string"), new XML_RPC_Value( array( "title" => new XML_RPC_Value($title, 'string'), "description" => new XML_RPC_Value($description, 'string'), "dateCreated" => new XML_RPC_Value("", 'string') // 投稿日時 ), "struct" ), new XML_RPC_Value($publish, "boolean") ) ); // メッセージ送信 if(!$Response = $Client->send($Message)){ echo "Post failed."; } /* カテゴリ変更 */ // Post ID取得 $Buf = $Response->value(); $PostId = $Buf->me["string"]; // カテゴリ指定 $CateList = array( new XML_RPC_Value($category1, "int"), new XML_RPC_Value($category2, "int"), new XML_RPC_Value($category3, "int") ); $Category = new XML_RPC_Value($CateList, "struct"); // メッセージ作成 $Message = new XML_RPC_Message( "mt.setPostCategories", array( new XML_RPC_Value($PostId, "int"), new XML_RPC_Value($user, "string"), new XML_RPC_Value($pass, "string"), $Category ) ); // メッセージ送信 if(!$Response = $Client->send($Message)){ echo "Category change failed."; } |