Mar 14 2010

BuddyPress Group Forum Extras plugin

Download from Wordpress Plugin Repo: BuddyPress Group Forum Extras

A collection of bbPress plugins to bring a little more forum feel to the group forums.

  • Signatures (html tags are still limited to: a strong i )
  • BBCode Lite (or option for Shortcode)
  • Ajaxed Quote

I’m also looking to add the following:

  • Report Post to Mod (use notification system to group mods)
  • Support Forums (run nongroup forums)
  • Best Answer or bb-reputation (Karma)
  • Signatures administration to include a admin defined set of html tag or bbcode

Theme Edit is Required to use Ajax Quote

groups/single/forum/topic.php

Before the link:
<a href="#post-<?php bp_the_topic_post_id() ?>" title="<?php _e( 'Permanent link to this post', 'buddypress' ) ?>">#</a>

Please add this action:
<?php do_action( 'bp_forum_extras_topic_links' ) ?>

Also, to include a reply box on all pages instead of the last only, remove this if statement :

<?php if ( bp_get_the_topic_is_last_page() ) : ?>

(don’t forget about the correct <?php endif; ?> )


Mar 8 2010

BuddyPress Hack: Auto-assign mod or admin to new groups

If you have no need for the BuddyPress Restrict Group Creation plugin here is the function I used to demote the creator and automatically assign an admin and/or mod to the new group.

//if a new group is created - attach an admin, mod, demote
function my_group_autoadd_admin( $args ) {
global $bp;

//args is the group_id
if (!$args)
return;

if (! is_site_admin() )  {

//use this to demote the creator to a mod – assuming the logged in user is creating (you could also pull group->creator_id)
$member = new BP_Groups_Member($bp->loggedin_user->id, $args);
$member->is_admin = 0;
$member->is_mod = 1;
$member->user_title = __( 'Group Mod','buddypress' );
$member->date_modified = gmdate('Y-m-d H:i:s');
$member->save();

}

//use this to add some user_id (from wp_users->ID) as an admin
$member = new BP_Groups_Member(<insert_your_user_id>, $args);
$member->is_admin = 1;
$member->is_mod = 0;
$member->user_title = __( 'Group Admin', 'buddypress' );
$member->is_confirmed = 1;
$member->date_modified = gmdate( 'Y-m-d H:i:s' );
$member->save();

//use this to add some user_id (from wp_users->ID) as a mod
$member = new BP_Groups_Member(<insert_your_user_id>,$args);
$member->is_admin = 0;
$member->is_mod = 1;
$member->user_title = __( 'Group Mod', 'buddypress');
$member->is_confirmed = 1;
$member->date_modified = gmdate( 'Y-m-d H:i:s' );
$member->save();

}

add_action('groups_created_group', 'my_group_autoadd_admin', 1, 1);


Mar 7 2010

BuddyPress Restrict Group Creation plugin

Download from Wordpress Plugin Repo: BuddyPress Restrict Group Creation

This plugin will restrict group creation and settings to certain WP Capabilities. In addition, this plugin will auto-demote the group creator to group mod to ensure group settings may not be modified after creation. You may also define a group admin and mod that will be auto-assigned all new groups created.

Auto-assigning an admin and/or mod to new groups

In your wp-config.php file – set the following constants and check ‘Auto demote group creator to group mod‘ under the settings page.

define( 'BP_RESTRICTGROUP_AUTOADD_ADMIN_USER_ID', the_database_user_id );

and/or (admin inherits mod – no reason to define the same user_id twice)

define( 'BP_RESTRICTGROUP_AUTOADD_MOD_USER_ID', the_database_user_id );

Where the_database_user_id is the actual integer ID from the wp_users table.

Screenshots:

BuddyPress Restrict Group Plugin - Admin settings


Mar 5 2010

BuddyPress hack: Disable activity stream comments for non-friends and non-groups

What else could you do with this simple my_is_friend_check function?

How about removing the ability to Reply/Comment on non-friend and non-group activity updates.

See our previous: #BuddyPress hack: disable activity stream comments/favorites for certain types

so in the activity loop for activity-meta comment link, add the following check:

( bp_get_activity_user_id() != 0 && my_is_friend_check( bp_get_activity_user_id() ) )

what about disabling the reply comment for non-member groups?

(bp_get_activity_object_name() == 'groups' && groups_is_user_member( bp_loggedin_user_id(), bp_get_activity_item_id() ) )

So what does my if statement look like for activity-meta commenting?

if ( is_user_logged_in() && bp_activity_can_comment() &&
!my_denied_activity_meta_check( bp_get_activity_type() ) &&
( (bp_get_activity_object_name() == 'groups' && groups_is_user_member( bp_loggedin_user_id(), bp_get_activity_item_id() ) ) ||
( bp_get_activity_user_id() != 0 && my_is_friend_check( bp_get_activity_user_id() ) ) )     ) { ?>
<a href="<?php bp_activity_comment_link() ?>" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Reply', 'buddypress' ) ?> (<span><?php bp_activity_comment_count() ?></span>)</a>
<?php } ?>

1) Deny all replies for certain activity types (my_denied_activity_meta_check – see previous example)
2) Allow if loggedin user is in the same group as user who made activity updates (groups_is_user_member)
3) Allow if loggedin user is a friend (my_is_friend_check – see previous example)
4*) Allow if a friend posts in a public group in which loggedin user is not a member of

(a core filter would be excellent in this case – especially if a plugin wanted to control the activity meta features.)

…think i am done with my own tweaks to the activity stream. next up members and profile pages.

Please note – these little hacks to the activity stream will increase the number of db queries.

Before (on shared host):
This page generated in 0.864 seconds, using 151 queries.

After (on shared host):
This page generated in 0.853 seconds, using 215 queries.


Mar 5 2010

BuddyPress hack: remove non-friend updates from the activity stream

What else could you do with this simple my_is_friend_check function?

How about removing activity stream postings from non-friends all together (except public groups)

See our previous: #BuddyPress hack: remove new member registration from activity stream


function my_denied_activity_nonfriends( $a, $activities ) {

//if admin we want to know
if ( is_site_admin() )
return $activities;

foreach ( $activities->activities as $key => $activity ) {
/* if member of a group – we want the activity even if nonfriend */
if ( $activity->component != 'groups' && $activity->user_id != 0 && !my_is_friend_check($activity->user_id) && !my_is_atme_check($activity->content) ) {

unset( $activities->activities[$key] );

$activities->activity_count = $activities->activity_count-1;
$activities->total_activity_count = $activities->total_activity_count-1;
$activities->pag_num = $activities->pag_num -1;

}
}

/* Renumber the array keys to account for missing items */
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new;

return $activities;
}
add_action('bp_has_activities', 'my_denied_activity_nonfriends', 10, 2 );

Plus one more quick function to check for any atme mentions – maybe a non-friend?


function my_is_atme_check( $content ) {
global $bp;

if ( !is_user_logged_in() )
return false;

if (!$content)
return false;

$pattern = '/[@]+([A-Za-z0-9-_]+)/';
preg_match_all( $pattern, $content, $usernames );

/* Make sure there’s only one instance of each username */
if ( !$usernames = array_unique( $usernames[1] ) )
return false;

if ( in_array( bp_core_get_username( $bp->loggedin_user->id ), $usernames ) )
return true;

return false;
}

Grab this as a plugin from WPMU.org


Mar 4 2010

BuddyPress hack: Remove ‘Send Private Message’ for non-friends

A quick hack to only display the ‘Send Private Message’ for friends. First we’ll create a simple check function for your myhacks/theme functions.php file:


function my_is_friend_check( $friend_id = false) {
global $bp;

if ( is_site_admin() )
return true;

if ( !is_user_logged_in() )
return false;

if (!$friend_id) {
$potential_friend_id = $bp->displayed_user->id;
} else {
$potential_friend_id = $friend_id;
}

if ( $bp->loggedin_user->id == $potential_friend_id )
return false;

if (friends_check_friendship_status($bp->loggedin_user->id, $potential_friend_id) == 'is_friend')
return true;

return false;
}

Then edit the default theme file: bp-default/members/single/member-header.php and look for the ‘Send Private Message’ check and change it to:

if ( is_user_logged_in() && !bp_is_my_profile() && function_exists( 'bp_send_private_message_link' ) && my_is_friend_check() ) :


Feb 26 2010

BuddyPress hack: remove new member registration from activity stream

Since it was asked (and on the buddypress.org forums). Mute new member activity stream registration (aka, don’t announce your spammers)

add to whatever bp-custom.php or theme functions php and define the filtered bp_has_activities() types

function my_denied_activity_new_member( $a, $activities ) {

//if admin we want to know
if ( is_site_admin() )
return $activities;

foreach ( $activities->activities as $key => $activity ) {
//new_member is the type name (component is 'profile')
if ( $activity->type =='new_member') {
unset( $activities->activities[$key] );

$activities->activity_count = $activities->activity_count-1;
$activities->total_activity_count = $activities->total_activity_count-1;
$activities->pag_num = $activities->pag_num -1;
}
}

/* Renumber the array keys to account for missing items */
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new;

return $activities;
}
add_action('bp_has_activities','my_denied_activity_new_member', 10, 2 );

Then in your favorite theme (i’m using default) under the activity/index.php file, change up up the  select option

<?php if (is_site_admin() ) : ?>
<option value="new_member"><?php _e( 'Show New Members', 'buddypress' ) ?></option>-->
<?php endif; ?>

I suspect you could take this a little further and check the $activity->date_recorded (ie, display new_member registration after 2 weeks)

or grab a simple plugin

http://code.etiviti.com/php/buddypress/buddypress-remove-newmember-activity.zip


Feb 25 2010

BuddyPress hack: disable activity stream comments/favorites for certain types

Want to keep the noise ratio down on activity stream commenting? Besides the built-in

Disable activity stream commenting on blog and forum posts?:

I don’t see a way to implement additional filters on bp_activity_can_comment() nor is there one setup for favorites. (unless i’m not looking hard enough)

So, a quick and dirty function to block out certain activity_types.

add to whatever myhacks/functions php and define the excluded activity types


function my_denied_activity_meta_check($type) {
return in_array($type, array( 'bp_link_vote', 'friendship_created', 'friendship_accepted', 'new_forum_post', 'new_member') );
}

*we are removing the ability for voted up links, friendships, new forum posts for a group and new member registrations.

Then in your favorite theme (i’m using default) under the activity/entry.php file – add the function to the is_user_logged_in() if statement on the comment link and/or favorite link sections:

!my_denied_activity_meta_check( bp_get_activity_type() )

In this case, no comments or favorites when members add a friendship or votes up a link (from the awesome BuddyPress Links plugin)

I submitted trac tickets for BP 1.3 to include filtering on the two items (hopefully not a dup :P )


Feb 20 2010

BuddyPress Sitemap Generator plugin

Download from Wordpress Plugin Repo: BuddyPress Sitemap Generator

Based upon GoogleSitemapGenerator by Arne at www.arnebrachhold.de – BuddyPress Sitemap Generator creates a sitemapindex and child maps for each BuddyPress main component.

Sitemap files:

  • overall activity
  • member listing
  • member listing -> groups slug (onlyif data)
  • member listing -> friends slug (onlyif data)
  • member listing -> profile slug
  • member listing -> activity slugs (main, just-me, friends, groups, favorites, mentions)
  • group listing -> public and private groups (if forums enabled – forum slug)
  • forum topics -> public and private groups only

Does not invoke BP components but rather queries MySQL directly. WP-Cron can be set for valid wordpress intervals and the default is daily.

What to expect:
- no fancy priority
- no options yet besides ping/sitemap location
- limited to 50k urls for each component

Screenshots:


Feb 17 2010

BuddyPress hack: Add a View BuddyPress profile link in wp-admin Users

bbPress has a hover link to view a member profile page from the bb-admin users section. I somewhat miss that little feature in Wordpress + BuddyPress 1.2 – so just a quick code snippet to add the link:

function user_row_actions_bp_view($actions, $user_object) {
global $bp;
$actions['view'] = '<a href="' . bp_core_get_user_domain($user_object->ID) . '">' . __('View BP') . '</a>';
return $actions;
}
add_filter('user_row_actions', 'user_row_actions_bp_view', 10, 2);