Allowing Group Email Subscription access only to a whitelist
-
As promised here http://buddypress.org/community/groups/buddypress-group-email-subscription/forum/topic/stableish-release-of-buddypress-group-email-subscription-with-digests/, I have cobbled together an ugly but functional version of the plugin that allows you, as the admin, to restrict access to the plugin’s functionality to a defined whitelist. I’m going to use this on my site for some beta testing before a sitewide rollout, but I can imagine a lot of other uses for it.
Instead of uploading a file, I’m going to give you the instructions on how to set it up, as it’s important that you understand what you’re doing (this is not yet a truly supported feature).
1) In bp-activity-subscription.php, define a variable called $ass_whitelist. Do this outside of any function, ideally right before the function activitysub_load_buddypress. Here’s an example:
$ass_whitelist = array( 2,6,10 )
This means that only members 2, 6, and 10 will be able to use the plugin.2) In bp-activity-subscription-functions.php, add the following two functions to the top of the plugin file:
function ass_check_whitelist() {
global $ass_whitelist, $current_user;if ( empty( $ass_whitelist ) || in_array( $current_user->ID, $ass_whitelist ) ) {
add_action( 'wp', 'ass_update_group_subscribe_settings', 4 );
add_action ( 'bp_group_header_meta', 'ass_group_subscribe_button' );
add_action ( 'bp_directory_groups_actions', 'ass_group_subscribe_button' );
//add_action ( 'bp_directory_groups_item', 'ass_group_subscribe_button' ); //useful to put in different location with css abs pos
add_action( 'bp_group_members_list_item_action', 'ass_show_subscription_status_in_member_list', 100 );
add_action( 'bp_notification_settings', 'ass_group_subscription_notification_settings' );
} else {
add_action( 'wp_head', 'ass_hide_email_options' );
}
}
add_action( 'wp', 'ass_check_whitelist', 1 );function ass_hide_email_options() {
?>li#nav-notifications-personal-li { display: none !important; }
<?php
}
The first function checks against the whitelist before activating the relevant hooks. The second one is an ugly hack having to do with the fact that BP Group Extensions are hard to deregister.3) Look through bp-activity-subscription-functions.php to find all the add_action references in the function ass_check_whitelist above, and comment them out. For example, you should find the other place in the file where it says
add_action( 'wp', 'ass_update_group_subscribe_settings', 4 );
and turn it into
// add_action( 'wp', 'ass_update_group_subscribe_settings', 4 );
This last step is very important, or the whitelist will do nothing – everyone will be able to access the plugin’s functionality.Let me know in this thread if you have any problems.
(heads up @hnla)
You must be logged in to reply to this topic.
mainly in due to the fact that that function ass_hide_email_options() is oh so very bad :angry: