CR-Post2PingFM Plugin Tweaked for WordPress MU
Although this is not strictly related to Second Life itself, I need some place to put a tweaked version of Arief Bayu Purwanto’s CR Post2PingFM plugin, which required some tweaking to work well with WordPress MU.
The problem has to do with setting and reading options properly in a multiblog environment. WordPress and WordPress MU handle this differently, thus the original, untweaked plugin didn’t work properly.
Thanks to Marcus Cudd for helping me to debug it!
You have to enclose it in the usual PHP tags, which this code plugin sadly eats up.
Warning: Beachbum noticed quite correctly that the single quotes in the code get unfortunately converted by WordPress into “typographical quotes”, so you have to be extra-careful when copying & pasting this! Thanks for the tip, Beachbum
Plugin Name: CR Post to Ping.fm
Plugin URI: http://bayu.freelancer.web.id/2009/03/31/wordpress-plugin-cr-post2pingfm/
Description: This plugin will submit your new post to ping.fm account.
Version: 0.7.2
Author: Arief Bayu Purwanto, tweaked by Gwyneth Llewelyn to work with WordPress MU 2.8.6
Author URI: http://bayu.freelancer.web.id/
*/
define(‘API_KEY’, ’41121eb3a56f921bc2957b2458d65bad’);
add_action(‘publish_post’, ‘cr_post_2_pingfm_submit_to_ping_fm’);
add_action(‘admin_menu’, ‘cr_post_2_pingfm_submit_config_admin’);
add_action(‘admin_init’, ‘cr_post_2_pingfm_settings_api_init’);
function cr_post_2_pingfm_settings_api_init()
{
register_setting(‘cr_post_2_pingfm_settings’, ‘cr_post_2_pingfm_options’);
}
function cr_post_2_pingfm_submit_to_ping_fm($postId)
{
$continue = false;
$categories = array();
$postMode = get_option(‘cl_post_pingfm_publish_mode’, false);
$republish = false;
if(!wp_is_post_revision($postId))
{
$this_post_submitted = get_option(‘cr_post_2_pingfm_submit_post_submitted_’.$postId, false);
if(!$this_post_submitted)
{
$continue = true;
}
else
{
if("all" == $postMode)
{
$continue = true;
$republish = true;
}
}
if($continue)
{
$theCats = get_the_category($postId);
foreach($theCats as $cats)
{
$categories[] = $cats->cat_ID;
$categories[] = $cats->category_nicename;
}
$continue = isCategoriesAllowedToPing($postId, $categories);
}
if($continue)
{
update_option(‘cr_post_2_pingfm_submit_post_submitted_’.$postId, true);
submitPingFM($postId, $republish);
}
}
}
function cr_post_2_pingfm_submit_config_admin()
{
add_options_page(‘CR Post2Pingfm’, ‘CR Post2Pingfm’, 8, __FILE__, ‘cr_post_2_pingfm_submit_config_form’);
}
function cr_post_2_pingfm_submit_config_form() {
?>
<div class="wrap">
<h2>CR Post2Pingfm</h2>
<form action="options.php" method="post">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">Ping.fm Application Key</th>
<td>
<input name="cr_post_2_pingfm_options[cl_post_pingfm_api_key]" size="45" type="text" value="<?php echo $options['cl_post_pingfm_api_key']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Ping Template</th>
<td>
<input name="cr_post_2_pingfm_options[cl_post_pingfm_message_template]" size="45" type="text" value="<?php echo ($options['cl_post_pingfm_message_template'] ? $options['cl_post_pingfm_message_template'] : ‘I just post {title} on {url}’); ?>" />
Template Tags: <strong>{title}</strong> for <em>Post Title</em> and <strong>{url}</strong> for <em>Permalink URL</em>
eg: <em>I just post {title} on {url}</em></td>
</tr>
<tr valign="top">
<th scope="row">Ping mode</th>
<td>
Allow submit new post to ping.fm:
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="all" /> />For all categories (<em>all</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="allow" /> />For this categories (<em>allow</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="deny" /> />For categories except this one (<em>deny</em>)
Category list (<em>category ID and slug is supported</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode_category]" type="text" value="<?php echo $options['cl_post_pingfm_ping_mode_category']; ?>" />(comma separated, eg: <em>1,23,random-caregory,10,rants</em>)
Category list is ignored if mode <em>all</em> is selected.</td>
</tr>
<tr valign="top">
<th>Publish mode</th>
<td>
Allow submit to ping.fm on the following condition:
<input name="cr_post_2_pingfm_options[cl_post_pingfm_publish_mode]" type="radio" value="once" /> />Only submit for the <strong>first time</strong>(<em>once</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_publish_mode]" type="radio" value="all" /> />For everytime you push <strong>publish</strong> button(<em>all</em>)</td>
</tr>
<tr valign="top">
<th>Re-Publish template</th>
<td>
This option only used if you choose <em>all</em> in <strong>publish mode</strong>.
<input name="cr_post_2_pingfm_options[cl_post_pingfm_republish_template]" type="radio" value="above" /> />Use Ping Template above
<input name="cr_post_2_pingfm_options[cl_post_pingfm_republish_template]" type="radio" value="this" /> />Use this template
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_republish_template_text]" size="45" type="text" value="<?php echo ($options['cl_post_pingfm_ping_republish_template_text'] ? $options['cl_post_pingfm_ping_republish_template_text'] : ‘republished {title} on {url}’); ?>" />
The above template tags, apply.</td>
</tr>
</tbody>
</table>
<input name="action" type="hidden" value="update" />
<input name="page_options" type="hidden" value="cl_post_pingfm_message_template,cl_post_pingfm_api_key,cl_post_pingfm_ping_mode_category,cl_post_pingfm_ping_mode,cl_post_pingfm_publish_mode,cl_post_pingfm_ping_republish_template_text,cl_post_pingfm_republish_template" />
<input class="button-primary" type="submit" value="<?php _e(‘Save Changes’) ?>" />
</form></div>
$post->post_title,
‘{url}’ => get_permalink($postId),
);
foreach($arrTemplate as $template => $template_data)
{
$ping_template = str_replace($template, $template_data, $ping_template);
}
// error_log(date("c") . " – Ping template: ‘" . $ping_template . "’\n", 3, "/var/tmp/pingfm-" . date("Ymd") . ".log");
$result = $pfm->post("status", $ping_template);
}
function isCategoriesAllowedToPing($postId, $categories)
{
$pingMode = get_option(‘cl_post_pingfm_ping_mode’);
$pingCats = get_option(‘cl_post_pingfm_ping_mode_category’);
$pingCats = array_map("trim", explode(",", $pingCats));
if(!is_array($pingCats)) $pingCats = array();
if("allow" == $pingMode)
{
foreach($categories as $cats)
{
if(in_array($cats, $pingCats))
{
return true;
}
}
}
else if("deny" == $pingMode)
{
foreach($categories as $cats)
{
if(in_array($cats, $pingCats))
{
return false;
}
}
return true;
}
else
{
return true;
}
}
Readers who viewed this page, also viewed:
Powered by Where did they go from here?












Note: this still seems to have some problems…
Does this work in WPMU 2.9.2?
This ought to work on 2.9.2 (at least it worked for me!), but it's not the latest version of CR-Post2PingFM … I'm working on changing that one
Let's see who is faster, Auttomatic releasing WP 3.0 (which unifies the WP and WP MU code base), or me tweaking the plugin.
I tried to copy your code and replace the original plugin code but it returned a white screen of death. I'm using mu2.9.2. Would it be possible to post a link to the actual file or email it to me? I am desperately looking for a fix and it seems this the only hope out of ALL the post to pingfm plugins. Thank you so much for working on this.
WOOT!, I got it going. The problem was your code that I copied has ‘curleyquotes’ instead of 'singlequotes' . I think thats what there called anyways. What are the “problems” you mentioned this code still has. I tested from a post made via admin and the “postie” plugin and both sees to work. Thanks again for your work on this. Looking forward to the version you are working on. I think it would be a great benefit if you added it to the plugin repository.
Aww yes. Sorry about that. Dang, this stupid syntax highlighter gets confused with the quotes
The latest version of the CR-Post2PingFM is not too different from this, but the truth is, I didn't manage to “backfix” it for WP 2.9.2
Actually, I'm thinking about waiting a few more weeks until the release of WP 3.0 (same codebase for both WP and WP MU). The big issue with Arief's code is the way he deals with options. Since WP MU has a mechanism to deal with options for the different blogs (which is a bit more elegant than the regular WP code, which can only deal with “site-wide” options), I'm assuming that this will be the API version that goes into WP 3.0, thus breaking each and all plugins relying on the old method (used by Arief's code). But I'm just guessing. WP 3.0 might simply use a completely different mechanism.
Grr, instead of writing these comments, I should simply get WP 3.0 Beta, install it on a test site, and see for myself what happens
any news on your update?
Thnx,
MMmh no, I'm stuck
I've tried installing it under WP 3.0 Beta 2, to see if there was some “magic” that fixed it automatically. The options get correctly saved (unlike what happens on WP MU 2.9.2), there's no problem with that, and I can also easily see the changes made on the “new post” page. But it doesn't send anything to Ping.FM
Oh, latest news: Arief Bayu has just reported that his Ping.fm application key has been blocked by Ping.fm
That's probably the reason why, right now, nobody can use it
I was gonna give you my update 2 days after I said it was working good and it stopped, but it was the same time ping.fm was having bad downtime and just figured it was that. Now I am manually posting my stuff via the ping.fm dashboard. I just don't understand why there isn't a working version of this yet for WPMU. Such a huge market. If a new application key is what it would take, could someone donate one? Or what was the reason it being blocked? Im gonna go see if I an get one and use it. I'm very ignorant on coding stuffs but wouldn't the key need to be tied to the script?
I'm just sorry I can't help, I can't code for toffee
ALL PROBLEMS ARE SOLVED IN NEW VERSIONS !!!!!!!!
I've upgraded to WP3.0 and today CR-Post2Pingfm was updated to v.10( http://wordpress.org/extend/plugins/cr-post2pin... ) and ALL IS GOOD!!
Thank you so much Gwyneth for the fixes before.
Now we can all celebrate and rejoice.
Cheers!
Thanks for testing Beachbum! Now if we can only get a category ping template
Just had another upgrade today and ur wish came true in version 1.0
Template Mode Choose what template you want to use:
Global template.
Per-category template.
Woo-hoo! Thank you so much!!