Skip to content
Snippets Groups Projects
Commit 2de0cc2e authored by lechuck's avatar lechuck Committed by lucha
Browse files

Upgrade bp-mpo-activity-filter to 1.2

parent 636cb7f2
No related branches found
No related tags found
No related merge requests found
<?php <?php
/**
* Reaches into the activity global and filters out items the user doesn't have access to
*
* Uses privacy settings from More Privacy Options
*/
function bp_mpo_activity_filter( $a, $activities ) { function bp_mpo_activity_filter( $a, $activities ) {
global $bp; global $bp;
...@@ -7,9 +12,18 @@ function bp_mpo_activity_filter( $a, $activities ) { ...@@ -7,9 +12,18 @@ function bp_mpo_activity_filter( $a, $activities ) {
return $activities; return $activities;
foreach ( $activities->activities as $key => $activity ) { foreach ( $activities->activities as $key => $activity ) {
if ( $activity->component == 'blogs' ) { if ( $activity->type == 'new_blog_post' || $activity->type == 'new_blog_comment' ) {
$blog_id = $activity->item_id;
$current_user = $bp->loggedin_user->id; $current_user = $bp->loggedin_user->id;
// Account for bp-groupblog
if ( $activity->component == 'groups' ) {
$group_id = $activity->item_id;
$blog_id = groups_get_groupmeta( $group_id, 'groupblog_blog_id' );
} else {
$blog_id = $activity->item_id;
}
$privacy = get_blog_option( $blog_id, 'blog_public' ); $privacy = get_blog_option( $blog_id, 'blog_public' );
$remove_from_stream = false; $remove_from_stream = false;
...@@ -39,16 +53,14 @@ function bp_mpo_activity_filter( $a, $activities ) { ...@@ -39,16 +53,14 @@ function bp_mpo_activity_filter( $a, $activities ) {
case '-2': case '-2':
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
switch_to_blog( $blog_id ); $meta_key = 'wp_' . $blog_id . '_capabilities';
$caps = get_user_meta( $current_user, $meta_key, true );
$user = new WP_User( $current_user ); if ( !empty( $caps ) ) {
if ( !empty( $user->caps ) )
continue; continue;
else { } else {
$remove_from_stream = true; $remove_from_stream = true;
} }
restore_current_blog();
} else { } else {
$remove_from_stream = true; $remove_from_stream = true;
} }
...@@ -76,14 +88,14 @@ function bp_mpo_activity_filter( $a, $activities ) { ...@@ -76,14 +88,14 @@ function bp_mpo_activity_filter( $a, $activities ) {
if ( $remove_from_stream ) { if ( $remove_from_stream ) {
$activities->activity_count = $activities->activity_count - 1; $activities->activity_count = $activities->activity_count - 1;
unset( $activities->activities[$key] ); unset( $activities->activities[$key] );
} }
} }
} }
/* Renumber the array keys to account for missing items */
$activities_new = array_values( $activities->activities );
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new; $activities->activities = $activities_new;
//print "<pre>"; print_r($activities);
return $activities; return $activities;
} }
add_action( 'bp_has_activities', 'bp_mpo_activity_filter', 10, 2 ); add_action( 'bp_has_activities', 'bp_mpo_activity_filter', 10, 2 );
...@@ -94,4 +106,3 @@ function bp_mpo_activity_count() { ...@@ -94,4 +106,3 @@ function bp_mpo_activity_count() {
return '20'; return '20';
} }
add_action( 'bp_get_activity_count', 'bp_mpo_activity_count' ); add_action( 'bp_get_activity_count', 'bp_mpo_activity_count' );
?>
\ No newline at end of file
<?php <?php
/* /*
Plugin Name: BP MPO Activity Filter Plugin Name: BP MPO Activity Filter
Plugin URI: http://qwriting.org Plugin URI: http://github.com/boonebgorges/bp-mpo-activity-filter
Description: When using More Privacy Options, this plugin removes items from BP activity streams according to user roles Description: When using More Privacy Options, this plugin removes items from BP activity streams according to user roles
Version: 1.1.1 Version: 1.2
Author: Boone Gorges Author: Boone Gorges
Author URI: http://teleogistic.net Author URI: http://boone.gorg.es
*/ */
/* Only load the BuddyPress plugin functions if BuddyPress is loaded and initialized. */ /* Only load the BuddyPress plugin functions if BuddyPress is loaded and initialized. */
function bp_mpo_activity_filter_init() { function bp_mpo_activity_filter_init() {
require( dirname( __FILE__ ) . '/bp-mpo-activity-filter-bp-functions.php' ); require( dirname( __FILE__ ) . '/bp-mpo-activity-filter-bp-functions.php' );
} }
add_action( 'bp_init', 'bp_mpo_activity_filter_init' ); add_action( 'bp_include', 'bp_mpo_activity_filter_init' );
?>
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
Contributors: boonebgorges, cuny-academic-commons Contributors: boonebgorges, cuny-academic-commons
Tags: buddypress, activity, privacy, more privacy options, filter Tags: buddypress, activity, privacy, more privacy options, filter
Requires at least: WP 2.8, BuddyPress 1.2 Requires at least: WP 2.8, BuddyPress 1.2
Tested up to: WP 3.2.1, BuddyPress 1.5.1 Tested up to: WP 3.4.2, BuddyPress 1.6.1
Donate link: http://teleogistic.net/donate/ Donate link: http://teleogistic.net/donate/
Stable tag: 1.1.1 Stable tag: 1.2
When using More Privacy Options, this plugin removes items from BP activity streams according to user roles. When using More Privacy Options, this plugin removes items from BP activity streams according to user roles.
...@@ -24,6 +24,9 @@ I borrowed the idea, and a little bit of the code, from this plugin: http://blog ...@@ -24,6 +24,9 @@ I borrowed the idea, and a little bit of the code, from this plugin: http://blog
== Changelog == == Changelog ==
= 1.2 =
* Refactored some queries to avoid unnecessary switch_to_blog() usage
= 1.1.1 = = 1.1.1 =
* Oops * Oops
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment