<?php
/*
Plugin Name: Post to WPMU
Plugin URI: http://blogbox.zar.tc
Description: Post all posts to WPMU network
Version: 1.0
Author: Godfrey Philander
Author URI: http://blogbox.zar.tc
*/
add_action('publish_post', 'postWPMU');
function wpPostXMLRPC($post_type,$title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') {
if(trim($title)=='' || trim($body)==''){return;}
$body=utf8_decode($body);$title=utf8_decode($title);
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>$post_type,
'mt_keywords'=>$keywords,
'categories'=>array($category));
$params = array(0,$username,$password,$content,1);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$results = curl_exec($ch);
curl_close($ch);
$response = xmlrpc_decode(trim($results));
if ($response && xmlrpc_is_fault($response)) {
echo $response[faultString] ($response[faultCode]);
}
}
function postWPMU($post_ID){
$post = get_post($post_ID);
$permalink = get_permalink($post_ID);
$tags = get_the_tags($post_ID);
$title=$post->post_title;
$excerpt=$post->post_excerpt;
$categories = get_the_category($post_ID);
if (!empty($categories))
foreach($categories as $category)
$all_categories .= $category->cat_name . ', ';
$blogs = file('wpmublogs.txt');
foreach($blogs as $blog){
wpPostXMLRPC('post',$title,$excerpt.'<br>Read More at '.$permalink,$blog."/xmlrpc.php",'username','password',$all_categories);
}
}
?>