Created
October 21, 2013 03:42
-
-
Save R3V1Z3/7078340 to your computer and use it in GitHub Desktop.
Simple plugin for WordPress Multi-site and BuddyPress to restrict categories, by slug, from the Activity Stream. It's a Multi-site plugin, meant to be installed in wp-content/mu-plugins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Simple, Multi-site plugin for WordPress and BuddyPress to restrict categories, by slug, from the Activity Stream | |
Please note, his is a Multi-site plugin meant to be installed in wp-content/mu-plugins/ folder in a Multi-site WordPress install | |
code derivative of snippet by imath at: | |
http://buddypress.org/support/topic/possible-to-exclude-post-categories-in-activity-stream-and-make-a-user-profile-private-like-with-pri/ | |
*/ | |
function exclude_category_slugs_from_activity_stream( $post_id, $post ){ | |
// add in any categories to exclue from activity stream, separated by commas, no spaces | |
$category_slugs_to_exclude = "testing,autoblog"; | |
// create the array that contains the category ids to exclude | |
$ids_to_exclude = array(); | |
// create new array by splitting category slugs by comma | |
$category_slug_array = split( ",", $category_slugs_to_exclude ); | |
// iterate over category_slug_array | |
foreach ( $category_slug_array as $category ) { | |
// get the category id based on the slug | |
$idObj = get_category_by_slug( $category ); | |
$id = $idObj->term_id; | |
// push the category id onto the exclude array | |
array_push ( $ids_to_exclude, $id ); | |
} | |
// check post status to make sure it's published, exit if not | |
if ( 'publish' != $post->post_status ) | |
return false; | |
// get the post's categories | |
$categories = get_the_category( $post_id ); | |
$in = false; | |
// check if the post has any categories, do nothing if not | |
if( count($categories) > 0 ) { | |
// iterate over categories | |
foreach ( $categories as $category ) { | |
// check if any excluded category exists within post's categories | |
if( in_array( $category->cat_ID, $ids_to_exclude) ) | |
$in = true; | |
} | |
} | |
/* if the post has any excluded category, remove BuddyPress hook that records an activity */ | |
if( $in ) | |
remove_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); | |
} | |
// add our function to save_post action hook | |
add_action( 'save_post', 'exclude_category_slugs_from_activity_stream', 9, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment