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.

Posted in Tech | Tagged , | Leave a comment

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;
}
Posted in Tech | Tagged , | 8 Comments

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

Posted in Tech | Tagged , | 1 Comment

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.

Posted in Tech | Tagged , | 20 Comments

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 )

Posted in Tech | Tagged , | 4 Comments

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:

Posted in Tech | Tagged , , | 1 Comment

Forcing BuddyPress to utilize user_nicename for member urls and mentions

For an upcoming project that will be utilizing BuddyPress 1.2 – I hit a snag with the user_login and member slugs. Importantly the column user_login may contain an @ symbol or other special characters. Since my user registration is via WordPress the user_nicename column is already cleaned and ready to go.

***WARNING***

This requires editing core files and will break whatever upgrade process you use. Thus I can not guarantee this will work for everyone (I’m already one pint into a Arrogant Bastard Ale) I tried to extract the changes I made, so hopefully this is all of them.

You can download a zip file or see below.

bp-activity-filters.php
104c104,105
< if ( !$user_id = username_exists( $username ) )
---
> //ETIVITI (rich!) force user_nicename
> if ( !$user_id = bp_core_get_userid( $username ) )

bp-core-catchuri.php
115c115,117
< if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
---
> //ETIVITI (rich!) force user_nicename
> if ( get_user_by('slug', $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
>

bp-activity.php
114a115,117
> //ETIVITI (rich!) force user_nicename
> $user_nicename = ( !empty( $bp->displayed_user->userdata->user_nicename ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
>
127c130,131
< bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
---
> //ETIVITI (rich!) force user_nicename
> bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_nicename ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );

bp-core.php
1001c1001
<
---
> //ETIVITI (rich!) force user_nicename
1003c1003
< return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
---
> return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $username ) ) );
1040,1043c1040,1041
< if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
< $username = $user_login;
< else
< $username = $user_nicename;
---
> //ETIVITI (rich!) force user_nicename
> $username = $user_nicename;

Please let me know if I fudged anything up here…

This will not work with BP_ENABLE_USERNAME_COMPATIBILITY_MODE – not tested with other bp plug-ins.

Posted in Tech | Tagged , | 1 Comment

Mentioned on BuddyPress Major Contributors list

Guess I enjoy finding bugs: http://buddypress.org/about/, thanks! :)

Posted in Tech | Tagged | Leave a comment

FireNICO v1.2.2 for Firefox 3.6 is up

Sorry, I forgot about the “other” extension :P

Download Now – FireNICO v1.2.2 for Firefox 3.5 to 3.6

See the changelog

Posted in FireNICO | Tagged , | Leave a comment

Adblock Plus and NICOclub Forums

I recommend installing Adblock Plus and add the following subscription list:

How to add an Adblock Plus Filter Subscription:
Open ADP Options (Tools > Add-Ons > Adblock Plus > Options or right click on ADP status icon > Preferences)
Filters > Add filter subscription
Add a different subscription
Enter a title and this url:

http://update.firenico.com/abp/nico.supersizeme.txt


This will bring FireNICO back up to speed and should improve the the overall experience.

Posted in FireNICO | Tagged , , | Comments Off