Commit e58e40a2 authored by agata's avatar agata

rimosso plugin bp-mpo-activity-filter

parent c1fa387d
<?php
/**
* Reaches into the activity global and filters out items the user doesn't have access to
*
* Uses privacy settings from More Privacy Options
*
* @param boolean $has_activities True if there are activities, false otherwise
* @param object $activities The BP activities template object
* @param array $template_args The arguments used to init $activities_template
* @return boolean $has_activities True if there are activities, false otherwise
*/
function bp_mpo_activity_filter( $has_activities, $activities, $template_args ) {
global $bp;
if ( is_super_admin() )
return $has_activities;
/**
* List of activity types that this plugin filters.
*
* @param array $activity_types List of activity type identifiers.
*/
$activity_types = apply_filters( 'bp_mpo_activity_types', array(
'new_blog',
'new_blog_post',
'new_blog_comment',
'new_groupblog_post',
'new_groupblog_comment',
) );
foreach ( $activities->activities as $key => $activity ) {
if ( in_array( $activity->type, $activity_types ) ) {
$current_user = $bp->loggedin_user->id;
// Account for bp-groupblog
if ( $activity->component == 'groups' && bp_is_active( 'groups' ) && 0 === strpos( $activity->type, 'new_groupblog_' ) ) {
$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;
switch ( $privacy ) {
case '1':
continue;
break;
case '0':
if ( $current_user != 0 ) {
continue;
}
else {
$remove_from_stream = true;
}
break;
case '-1':
if ( $current_user != 0 )
continue;
else {
$remove_from_stream = true;
}
break;
case '-2':
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 {
$remove_from_stream = true;
}
} else {
$remove_from_stream = true;
}
break;
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 {
$remove_from_stream = true;
}
restore_current_blog();
} else {
$remove_from_stream = true;
}
break;
}
if ( $remove_from_stream ) {
$activities->activity_count = $activities->activity_count - 1;
unset( $activities->activities[$key] );
}
}
}
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new;
return $activities->has_activities();
}
add_filter( 'bp_has_activities', 'bp_mpo_activity_filter', 10, 3 );
// Filter the output of 'bp_get_activity_count' to account for the fact that there are fewer items. A total hack.
function bp_mpo_activity_count() {
return '20';
}
add_action( 'bp_get_activity_count', 'bp_mpo_activity_count' );
<?php
/*
Plugin Name: BP MPO Activity Filter
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.3.1
Author: Boone Gorges
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_include', 'bp_mpo_activity_filter_init' );
=== BP MPO Activity Filter ===
Contributors: boonebgorges, cuny-academic-commons
Tags: buddypress, activity, privacy, more privacy options, filter
Requires at least: 3.5
Tested up to: 5.0
Requires PHP: 5.3
Donate link: http://teleogistic.net/donate/
Stable tag: 1.3.1
When using More Privacy Options, this plugin removes items from BP activity streams according to user roles.
== Description ==
More Privacy Options is a plugin for WPMu that allows blog owners to fine-tune their blog's privacy settings, expanding on the default privacy settings offered in the WP core. Putting this plugin together with BuddyPress has been problematic, however, because BuddyPress is not built to recognize the new privacy settings defined by MPO. As a result, even private blog posts get put into the public activity feed.
This plugin, BP MPO Activity Filter, does just what the name suggests: it filters BuddyPress activity feeds (wherever bp_has_activities appears) and filters the output based on the privacy settings of the source blogs. For example, if a blog is set to be visible only to logged in members of the community, BP MPO Activity Filter will only display activity items corresponding to that blog (both posts and comments) to users who are logged in. Sitewide administrators will have an unfiltered activity stream.
Activity items stored with BP 1.1.3 or lower have a slightly different data format, which makes them incompatible with this plugin.
I borrowed the idea, and a little bit of the code, from this plugin: http://blogs.zmml.uni-bremen.de/olio.
== Installation ==
* Upload the directory '/bp-mpo-activity-filter/' to your WP plugins directory and activate from the Dashboard of the main blog.
== Changelog ==
= 1.3.1 =
* Fixes PHP 5.3 incompatibility
= 1.3.0 =
* Fixed bugs when checking for component activation
* Fixed bugs related to groupblog activity items
= 1.2.1 =
* Fixed bug in activity filter callback.
* Fixed bug that caused new_blog activity items not to be filtered properly.
* Fixed compatibility with BP Groupblog.
* Added filter for additional activity types.
= 1.2 =
* Refactored some queries to avoid unnecessary switch_to_blog() usage
= 1.1.1 =
* Oops
= 1.1 =
* Upgraded to reduce unnecessary switch_to_blog()
= 1.0.1 =
* Added code to ensure that plugin is not loaded before BuddyPress is
* Updated readme file to include more information on compatibility with BP < 1.2
= 1.0 =
* Initial release
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