Apr 7 2010

BuddyPress Activity Stream as Blog Comments plugin

Download from Wordpress Plugin Repo: BuddyPress Activity Stream as Blog Comments

This plugin will replace the main BuddyPress blog (for what BP is activated on) comments section with the activity stream.

A few important notes:

  • WPMU and subblogs – no official support yet but i think it is possible
  • This is not for everyone (silly yes but if you love comment moderation and the wp-admin – then don’t use this)
  • Includes own theme files – you may copy the activitycomments theme folder to your default theme and override the layout
  • Existing Blog posts/comments – requires this plugin: BP Import Blog Activity
  • You must allow activity types: new_blog_post and new_blog_comment (this is only important if you hacked BP to disallow certain commenting – something i have covered previously)

How does it work?

When a blog post (new_blog_post) or comment (new_blog_comment) is made – an activity record is created corresponding to the post_ID or comment_ID. This plugin will cycle over the activity records for threaded comments made and display them in the same fashion as the BuddyPress activity stream (ability to reply and nested via the same ajax means)

Why would i want to do this?

The activity stream is a centralized commenting system in BuddyPress – the disconnect on the BP Blog portion may alienate user discussion on your site.

See it in action

(i may take a shot at using activity stream for the forums)


Apr 5 2010

5 BuddyPress Quick Tips plus a new demo site

Kicking off a new simple BuddyPress showcase site – (?) – for my plugins and hacks (best way to demo them – but a warning – on a shared host )

I came up with a few more quick tweaks:

Remove Change Avatar link under Profile if Avatar Upload is Disabled
Display the Group’s recent activity on Group Directory (groups-loop)
Display the Group’s Forum link on the Group Directory (groups-loop.php)
Auto-Add Group Admin when a new group is created
Disable Member Directory

Account registration is linked between etivite and etiviti (if you want to comment on this blog)


Apr 2 2010

BuddyPress Hack: Add signup email checks (valid, duplicate and domains) on profile settings page

When a member creates a new account on BuddyPress, several email checks take place:  is_email, limited_email_domains, email_exists). One small problem is after the account has been created/validated a user may change their email address without these checks.  On My Profile > Settings > General

The code below will add the same signup checks plus force the user to enter their current password before updating.

*warning*

1) less than favorable hack as i was unable to create a proper plugin (something with removing the nav item and re-adding as the screen_function would not call the new template)

2) this should be a core thing and also email re-validation is needed (or maybe reset the pw on email change) – submitted a trac ticket email check

*warning #2 this requires modifying core files – built on BP v1.2.3*

Replace following 2 functions in buddypress/bp-core/bp-core-settings.php


function bp_core_screen_general_settings() {
 global $current_user, $bp_settings_updated, $pass_error, $email_error, $pwd_error;

 $bp_settings_updated = false;
 $pass_error = false;
 $email_error = false;
 $pwd_error = false;

 if ( isset($_POST['submit']) ) {
 check_admin_referer('bp_settings_general');

 require_once( WPINC . '/registration.php' );

 // Form has been submitted and nonce checks out, lets do it.

 //we want to validate the user again for the current password when making a big change
 if ( !empty( $_POST['pwd'] ) && $_POST['pwd'] != '' && wp_check_password($_POST['pwd'], $current_user->user_pass, $current_user->ID) ) {

 //need to make sure changing an email address does not already exists
 if ( $_POST['email'] != '' ) {

 //what is missing from the profile page vs signup - lets double check the goodies
 $user_email = sanitize_email( wp_specialchars( trim( $_POST['email'] ) ) );

 if ( !is_email( $user_email ) )
 $email_error = true;

 $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );

 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );

 if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
 $email_error = true;
 }

 if ( !$email_error && $current_user->user_email != $user_email  ) {

 //we don't want email dups in the system
 if ( email_exists( $user_email ) )
 $email_error = true;

 if (!$email_error)
 $current_user->user_email = $user_email;
 }
 }

 if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {

 if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
 $current_user->user_pass = $_POST['pass1'];
 else
 $pass_error = true;

 } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
 $pass_error = true;
 } else {
 unset( $current_user->user_pass );
 }

 if ( !$email_error && !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
 $bp_settings_updated = true;

 } else {
 $pwd_error = true;
 }

 }

 add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
 add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );

 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

2nd function to replace as we should display some feedback to the user:

function bp_core_screen_general_settings_content() {
 global $bp, $current_user, $bp_settings_updated, $pass_error, $pwd_error, $email_error; ?>

 <?php if ( $bp_settings_updated && !$pass_error ) { ?>
 <div id="message">
 <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
 </div>
 <?php } ?>

 <?php if ( $pass_error && !$bp_settings_updated ) { ?>
 <div id="message">
 <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
 </div>
 <?php } ?>

 <?php if ( $pwd_error && !$bp_settings_updated ) { ?>
 <div id="message">
 <p><?php _e( 'Your password is incorrect', 'buddypress' ) ?></p>
 </div>
 <?php } ?>

 <?php
 if ( $email_error && !$bp_settings_updated ) { ?>
 <div id="message">
 <p><?php _e( 'Sorry, that email address is already used or is invalid', 'buddypress' ) ?></p>
 </div>
 <?php } ?>

 <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" id="settings-form">

 <label for="pwd"><?php _e( 'Current Password <span>(required to update email or change current password)</span>', 'buddypress' ) ?></label>
 <input type="password" name="pwd" id="pwd" size="16" value="" /> &nbsp;<?php _e( 'Current Password', 'buddypress' ) ?><br />
 <a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a><br/>

 <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
 <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" />

 <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>

 <input type="password" name="pass1" id="pass1" size="16" value="" /> &nbsp;<?php _e( 'New Password', 'buddypress' ) ?><br />
 <input type="password" name="pass2" id="pass2" size="16" value="" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ) ?>

 <div>
 <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit"/></p>
 </div>

 <?php wp_nonce_field('bp_settings_general') ?>
 </form>
<?php

}

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


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)

UPDATE: I have created a simple BuddyPress Block Activity Stream Types plugin which will block any types being saved to the database.