Mar 25 2010

BuddyPress Hack: bbPress Forum tweaks using Group Forum Extras plugin

First, download the plugin (v0.1.8 is required)

The latest plugin update includes a few “extra” functions in order to display some classic bbPress features.

Link the freshness time_since to the last post anchor

edit /bp-default/forums/forums-loop.php

Change:

<td>
<?php bp_the_topic_time_since_last_post() ?>
</td>

To:

<td>
<a href="<?php echo bp_forum_extras_topic_last_post_link( 15  ); ?>"><?php bp_the_topic_time_since_last_post()  ?></a>
</td>

Add pagination next to topic title on Forum Page

edit /bp-default/forums/forums-loop.php

Add:

<?php bp_forum_extras_topic_page_links( 15 ) ?>

After the topic title. You may pass additional args and css maybe required – refer to paginate_links.

Please note: 15 is the default per_page for bp_has_forum_topic_posts loop – buddypress does not store page settings in a meta table like bbPress. So we have to fudge it a little.

Add Voices to Topic Page

edit /bp-default/groups/single/forum/topic.php

After:

<?php bp_the_topic_total_post_count() ?>

Add:

 , <?php bp_forum_extras_the_topic_voices_count(); ?>

Add Voices to Forum Page (does not require extras plugin)

edit /bp-default/forums/forums-loop.php

Add new columns

header:

<th id="th-voices"><?php _e( 'Voices', 'buddypress' ) ?></th>

and in the loop:

<td>
 <?php bb_topic_voices( bp_get_the_topic_id() ) ?>
 </td>

Add Author to Forum Page (does not require extras plugin)

edit /bp-default/forums/forums-loop.php

Add new columns

header:

<th id="th-author"><?php _e( 'Author', 'buddypress' ) ?></th>

and in the loop:

<td>
 <a href="<?php bp_the_topic_permalink() ?>"><?php bp_the_topic_poster_avatar( 'type=thumb&width=20&height=20' ) ?></a>
 <div><?php bp_the_topic_poster_name() ?></div>
 </td>

Mar 14 2010

BuddyPress Group Forum Extras plugin

Download from Wordpress Plugin Repo: BuddyPress Group Forum Extras

This plugin is a collection of ported bbpress and new plugins for buddypress group forums.

  • BBCode Lite for BuddyPress Groups
  • Shortcodes (bbcode) for BuddyPress Groups
  • Ajax Post Quote
  • Signatures
  • Forum Index (includes a widget)
  • Tag Index (includes a widget)
  • RSS Feeds for Forums and Topics
  • jQuery Topic Preview (displays first post underneath topic title)
  • Display Activity Stream Comments on Forum Posts
  • Highlight Posts and Topics
  • Extra Functions for bbPress classic features (pagination next to title, last post link)

Theme Edit is Required for some subplugins

Activate the plugin and view the “Forum Extras” wp-admin page for details.

See Also:
BuddyPress Hack: bbPress Forum tweaks using Group Forum Extras plugin

Activity Comments for a Forum Post

Activity Comments for a Forum Post

Activity Comments for a Forum Post


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, and thresholds (friends, days registered, status updates, post counts) 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.

Threshold Limits

You may also enable threshold limits for certain categories:
Days registered
Number of Friends
Number of Status updates
Number of Post counts

Helpful you want to allow more experience members of your community create groups at will.

CSS to remove Create Group button

You may now enter in custom css if you do not use the default theme – this will remove the create group button displayed (even though if a user clicks on it – group creation is closed – but better for UI experience)

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 ) {
 global $bp;

 //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->user_id != $bp->loggedin_user->id && $activity->component != 'groups' && $activity->component != 'blogs' && $activity->user_id != 0 && !my_is_friend_check($activity->user_id) && !my_is_follower_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 quick check functions – friend, nonfriend but made atme mention, follower ?

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;
}

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

 if ( !is_user_logged_in() )
 return false;

 if ( is_site_admin() )
 return true;

 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;
}

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

 if ( !is_user_logged_in() )
 return false;

 if ( is_site_admin() )
 return true;

 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 ( bp_follow_is_following( array( 'leader_id' => $potential_friend_id, 'follower_id' => $bp->loggedin_user->id ) ) )
 return true;
}

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  functions.php or bp-custom.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:  /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() ) :

**NOTE**

@r-a-y has created a buddypress plug-in to remove this functionality:
Plugin: BuddyPress Private Messages for Friends Only