Here on the CUNY Academic Commons, we have an installation of MediaWiki which runs alongside our WordPress/BuddyPress installation. Without some additional coding, edits on the wiki don’t show up in the Commons News feed, and as a result they tend to get a little lost in the shuffle. This new plugin, BP External Activity, addresses this issue by allowing the administrator of a BuddyPress installation to specify an arbitrary RSS feed whose items will be regularly imported into the activity stream.
The plugin imports RSS feeds every hour. You may find that you need to decrease your Simplepie cache time to make it work: add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a', 'return 600;') );
reduces the RSS cache to ten minutes, for example. Put that in your bp-custom.php file if you are having problems with the plugin.
At the moment, the plugin uses the Author field from the RSS feed to look for a matching author in your WP database. If it doesn’t find one, it uses the unlinked text ‘A user’, as in ‘A user edited the wiki page…’.
Thanks to Andy Peatling, whose External Group Blogs served as the inspiration for a good part of the code.
During the recent upgrade from BuddyPress 1.1.x to BuddyPress 1.2.x, and the subsequent move away from group wires to interactive group activity streams, one thing that some users on the CUNY Academic Commons missed was the “Notify members by email” checkbox of the old wire.
This morning I wrote a bit of code to add that kind of functionality to group activity streams. There are three functions, each of which goes in your plugins/bp-custom.php file.
First, adding the checkbox to the activity box. Notice that it only shows up when you’re on a group page.
function cac_email_activity_checkbox() {
if ( !bp_is_groups_component() )
return;
?>
<?php
}
add_action( 'bp_activity_post_form_options', 'cac_email_activity_checkbox' );
Second, handling the data when it gets to the server and sending the emails. Obviously, you’ll want to change the text of the email to match your own site and your own preferences.
function cac_email_activity_handler( $activity ) {
global $bp;
if ( $_POST['mailme'] == 'mailme' ) {
$subject = sprintf('[CUNY Academic Commons] New update in the group "%s"', $bp->groups->current_group->name );
$message = strip_tags($activity->action);
$message .= '
';
$message .= strip_tags($activity->content);
$message .= '
-------
';
$message .= sprintf('You recieved this message because you are a member of the group "%s" on the CUNY Academic Commons. Visit the group: %s', $bp->groups->current_group->name, $bp->root_domain . '/' . $bp->groups->current_group->slug . '/' . $bp->groups->current_group->slug . '/' );
//print_r($message);
if ( bp_group_has_members( 'exclude_admins_mods=0&per_page=10000' ) ) {
global $members_template;
foreach( $members_template->members as $m ) {
wp_mail( $m->user_email, $subject, $message );
}
}
}
remove_action( 'bp_activity_after_save' , 'ass_group_notification_activity' , 50 );
}
add_action( 'bp_activity_after_save', 'cac_email_activity_handler', 1 );
Finally, you’ll need some Javascript to make the AJAX activity submission work correctly. This is really just a copy of what’s in the bp-default JS file, with a few added lines to make it work.
function cac_email_activity_js() {
if ( !bp_is_groups_component() )
return;
?>
var jq = jQuery;
jq(document).ready( function() {
jq("input#aw-whats-new-submit").unbind('click');
/* New posts */
jq("input#aw-whats-new-submit").click( function() {
var button = jq(this);
var form = button.parent().parent().parent().parent();
form.children().each( function() {
if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") )
jq(this).attr( 'disabled', 'disabled' );
});
jq( 'form#' + form.attr('id') + ' span.ajax-loader' ).show();
/* Remove any errors */
jq('div.error').remove();
button.attr('disabled','disabled');
/* Default POST values */
var object = '';
var item_id = jq("#whats-new-post-in").val();
var content = jq("textarea#whats-new").val();
var mailme = jq("#cac_activity_mail:checked").val();
/* Set object for non-profile posts */
if ( item_id > 0 ) {
object = jq("#whats-new-post-object").val();
}
jq.post( ajaxurl, {
action: 'post_update',
'cookie': encodeURIComponent(document.cookie),
'_wpnonce_post_update': jq("input#_wpnonce_post_update").val(),
'content': content,
'object': object,
'mailme': mailme,
'item_id': item_id
},
function(response)
{
jq( 'form#' + form.attr('id') + ' span.ajax-loader' ).hide();
form.children().each( function() {
if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") )
jq(this).attr( 'disabled', '' );
});
/* Check for errors and append if found. */
if ( response[0] + response[1] == '-1' ) {
form.prepend( response.substr( 2, response.length ) );
jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
button.attr("disabled", '');
} else {
if ( 0 == jq("ul.activity-list").length ) {
jq("div.error").slideUp(100).remove();
jq("div#message").slideUp(100).remove();
jq("div.activity").append( '
By default, BuddyPress does not include comments from non-members (or non-logged-in users more generally) in the sitewide activity stream. For some communities, this default behavior is probably just fine. But in a community like the CUNY Academic Commons, which aims to attract readership and conversation from all sorts of folks, whether or not they’re signed in, the sitewide activity stream will be much more meaningful if it includes comments from everyone.
My new plugin, BP Include Non-Member Comments, was built with this purpose in mind. The plugin is activated here on the CUNY Academic Commons, so that all comments on your blog – whether from logged-in users or not – will show up on the news feed.
The plugin has been tested on version 1.1.3 of BP, as well as the 1.2 release candidate. If you want to use the plugin for 1.1.3 or lower, you will need to uncomment the first few add_action and add_filter lines in the plugin file.
Technical caveat: Non-logged-in commenters have BP user_id 0. When BP creates the activity stream, it decides whether or not to show the Delete button by checking to see whether the user_id for the currently logged in user is the same as the user_id of the person to whom the comment belongs. Presumably, though, you don’t want non-logged-in viewers of the activity stream to be able to delete items from the activity stream at all. BP’s core code is not currently set up to make it easy to remove these buttons, so I employed an ugly fix. If you have changed your theme significantly from the default, you might have to adjust the filter bp_nonmember_comment_content (near the end of the plugin) to remove the button properly.
Since releasing my MediaWiki extension BuddyPressActivity, which puts wiki edits into your BuddyPress activity stream, I’ve noticed a bug or two. In particular, the cool feature that filters out multiple edits of a page by a given author within a 24 hour period wasn’t working right. I’ve made the necessary fixes in v0.2.
UPDATE: BP Dev Andy writes in a comment to this post that this bug will be fixed in BP core soon. If you’re running a recent version of BP, it’s likely that you won’t need this plugin. Please make sure you can reproduce the issue before installing.
This plugin fixes a small but potentially annoying quirk in BuddyPress. If you, as a blog owner, edit a comment that appears on your blog, BuddyPress adds an entry to the sitewide and individual activity streams – but it doesn’t delete the old entries. As a result, if you end up (for example) editing your own comment a few times in a row, you’ll see multiple items on the activity feed.
This plugin fixes the problem by checking whether a submitted comment is an edit, and if it is, by deleting previous versions of the comment in the activity stream.
Until the plugin is in the WordPress repository, I’ve made it available in a zip file here. Just load bp-activity-skip-comment-edits.php into your /wp-content/plugins folder, activate in Dashboard > Plugins (sitewide, if you’d like), and you should be good to go.
One of the most interesting vantage points from which to monitor goings-on around the CUNY Academic Commons is the BuddyPress activity feed. The sitewide feed – located on the Commons’s News page – lists all the activity happening the blogs, groups, and profiles around the site. There are activity streams for individual users and for those users’ friends as well – you can mine, for instance, here.
Until recently, though, these streams did not include information the activity taking place in the wiki portion of the site. I’ve developed a extension for MediaWiki (the software that powers the Wiki section of the Commons) called BuddyPressActivity that rectifies this shortcoming. For websites – like the CUNY Academic Commons – that have integrated our homegrown MediaWiki/Wordpress MU integration, this extension will update BuddyPress activity streams to include edits to pages within the wiki, thus better reflecting the extent and variety of the action on the site.
Email us at commonshelpsite@gmail.com so we can respond to your questions and requests. Please email from your CUNY email address if possible. Or visit our help site for more information: