Commit 2de0cc2e authored by lechuck's avatar lechuck Committed by lucha
Browse files

Upgrade bp-mpo-activity-filter to 1.2

parent 636cb7f2
<?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 ) {
global $bp;
......@@ -7,9 +12,18 @@ function bp_mpo_activity_filter( $a, $activities ) {
return $activities;
foreach ( $activities->activities as $key => $activity ) {
if ( $activity->component == 'blogs' ) {
$blog_id = $activity->item_id;
if ( $activity->type == 'new_blog_post' || $activity->type == 'new_blog_comment' ) {
$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' );
$remove_from_stream = false;
......@@ -38,17 +52,15 @@ function bp_mpo_activity_filter( $a, $activities ) {
break;
case '-2':
if ( is_user_logged_in() ) {
switch_to_blog( $blog_id );
$user = new WP_User( $current_user );
if ( !empty( $user->caps ) )
if ( is_user_logged_in() ) {
$meta_key = 'wp_' . $blog_id . '_capabilities';
$caps = get_user_meta( $current_user, $meta_key, true );
if ( !empty( $caps ) ) {
continue;
else {
} else {
$remove_from_stream = true;
}
restore_current_blog();
} else {
$remove_from_stream = true;
}
......@@ -57,9 +69,9 @@ function bp_mpo_activity_filter( $a, $activities ) {
case '-3':
if ( is_user_logged_in() ) {
switch_to_blog( $blog_id );
$user = new WP_User( $current_user );
if ( in_array( 'administrator', $user->roles ) )
continue;
else {
......@@ -72,18 +84,18 @@ function bp_mpo_activity_filter( $a, $activities ) {
break;
}
if ( $remove_from_stream ) {
$activities->activity_count = $activities->activity_count - 1;
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;
//print "<pre>"; print_r($activities);
return $activities;
}
add_action( 'bp_has_activities', 'bp_mpo_activity_filter', 10, 2 );
......@@ -94,4 +106,3 @@ function bp_mpo_activity_count() {
return '20';
}
add_action( 'bp_get_activity_count', 'bp_mpo_activity_count' );
?>
\ No newline at end of file
<?php
/*
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
Version: 1.1.1
Version: 1.2
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. */
function bp_mpo_activity_filter_init() {
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 @@
Contributors: boonebgorges, cuny-academic-commons
Tags: buddypress, activity, privacy, more privacy options, filter
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/
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.
......@@ -24,6 +24,9 @@ I borrowed the idea, and a little bit of the code, from this plugin: http://blog
== Changelog ==
= 1.2 =
* Refactored some queries to avoid unnecessary switch_to_blog() usage
= 1.1.1 =
* Oops
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment