Search Results for 'hide admin in directory'
-
AuthorSearch Results
-
September 14, 2017 at 2:45 pm #268044
In reply to: Hide member from public based on x-profile setting
xmgincParticipantUpdate: we have found that with a multisite with multiblog enabled to share the member list from the parent across all the child sites, code to filter out roles such as “administrator” only work if that user is also added to the child site.
Example:
Does not work in this scenario:
– parent site setup with user “johnadmin” with admin role is hidden on parent site directory
– child site without this user created does not hide him from the site directoryWorks in this scenario:
– parent site setup with user “johnadmin” with admin role is hidden on parent site directory
– child site ALSO setup with user “johnadmin” with admin role is hidden on child site directoryFor anyone wondering, the code that is partially working for us is below found at buddydev.com. This code has been added to the functions.php in the child site so that we can control what the child site loop shows individually. (example: parent shows everyone, child 1 shows only subscribers, child 2 only shows x, child 3 only shows y, etc.)
Would super appreciate any suggestions thx!
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' ); function buddydev_exclude_users_by_role( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } //$role = 'administrator';//change to the role to be excluded $user_ids = get_users( array( 'role__in' => ['administrator' , 'contributor' , 'author', 'editor'] ,'fields'=>'ID') ); $excluded = array_merge( $excluded, $user_ids ); $args['exclude'] = $excluded; return $args; }
September 14, 2017 at 3:56 am #268037xmgincParticipantHey guys,
Wondering if there is a way to hide specific members based on a extended profile setting.
While I see options for hiding based on WordPress user role (i.e. Admin, Author, etc.) or based on WordPress user’s ID #, I’m hoping we can do this via an option available to admins to change whether a member is visible in the directory.
Also, we found that the options to hide users appear to work on the parent Buddypress but those settings don’t affect the child site in a multiblog/multisite setting.
Any suggestions is greatly appreciated thanks!
June 20, 2017 at 7:37 pm #266603Topic: Hiding admins activity and profile errors
in forum How-to & TroubleshootingslimmyweightParticipantHi all,
I’m new to buddypress and have no experience with php. I have how ever managed to follow instructions on previous posts on preventing users from seeing the admin profile and activity but it hasnt worked correctly and has come up with errors.
I managed to create the bp-custom.php in the wp-content/plugins directory but the admin profile still appears and just comes up with an error message saying fatal error. It still allows the option to add as a friend aswell unless that might be to do with viewing it from an account already adding the admin account with.
This is where I got the code Im using from:
https://buddypress.org/support/topic/hide-admin-from-members-and-activity/Code in the bpcustom file
<?php function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 ); function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter'); function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 ); ?>
February 15, 2017 at 3:38 am #263784In reply to: Hide members
beforeplasticParticipantThank you but that doesn’t provide me the path the original file I was directed to update where I needed to add the ID numbers. I still need to know where that file lives.
For this new solution, what is the latest “official” complete code I should include in the new bp-custom.php file? The link you provided is asking me to create a new file if it didn’t exist. I did that adding it here in the plugins folder: public_html/wp-content/plugins
Including this code as a starting point:
<?php
// hacks and mods will go here
?>
—————————–
Is the below the correct and complete code to use?// Remove admin from the member directory
function bpdev_exclude_users($qs=false,$object=false){$excluded_user=’1′; // Id’s to remove, separated by comma
if($object != ‘members’ && $object != ‘friends’)// hide admin to members & friends
return $qs;$args=wp_parse_args($qs);
if(!empty($args[‘user_id’]))
return $qs;if(!empty($args[‘exclude’]))
$args[‘exclude’] = $args[‘exclude’].’,’.$excluded_user;
else
$args[‘exclude’] = $excluded_user;$qs = build_query($args);
return $qs;
}
add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2);// once admin is removed, we must recount the members !
function bpfr_hide_get_total_filter($count){
return $count-1;
}
add_filter(‘bp_get_total_member_count’,’bpfr_hide_get_total_filter’);January 24, 2017 at 7:00 pm #263153In reply to: Hide members
beforeplasticParticipantI found this. May I made a feature enhancement request to add each of these code features to enable a check box in the users section of the admin panel? Having to manually add the ID of new users to hide isn’t practical: https://buddypress.org/support/topic/hide-admin-from-members-and-activity/:
// Remove admin from the member directory
function bpdev_exclude_users($qs=false,$object=false){$excluded_user=’1′; // Id’s to remove, separated by comma
if($object != ‘members’ && $object != ‘friends’)// hide admin to members & friends
return $qs;$args=wp_parse_args($qs);
if(!empty($args[‘user_id’]))
return $qs;if(!empty($args[‘exclude’]))
$args[‘exclude’] = $args[‘exclude’].’,’.$excluded_user;
else
$args[‘exclude’] = $excluded_user;$qs = build_query($args);
return $qs;
}
add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2);// once admin is removed, we must recount the members !
function bpfr_hide_get_total_filter($count){
return $count-1;
}
add_filter(‘bp_get_total_member_count’,’bpfr_hide_get_total_filter’);December 27, 2016 at 10:48 pm #262411In reply to: [Resolved] How to Hide Admin accounts 2016?
livingflameParticipantSolution: HIDE ADMIN FROM BP WIDGETS AND DIRECTORY
This code is complementary for the other ==>
So, full code:
// Exclude Admin from Directories and BP Widgets add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users' ); function buddydev_exclude_users( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } $user_ids = array( 1, ); // enter user ids here $excluded = array_merge( $excluded, $user_ids ); $args['exclude'] = $excluded; return $args; } // Deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 ); // Hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
December 21, 2016 at 1:24 am #262296Topic: Hide BuddyPress Super Admin from Widget
in forum How-to & TroubleshootinglivingflameParticipant@danbp
Hi!
Can you help me?
How I can hide super admin’s vcard from BuddyPress Widgets??Your code only hide super admin from members and activity…
// Deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( ‘wp’, ‘bpfr_hide_admins_profile’, 1 ); // Hide admin’s activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // … but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID’s to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( ‘bp_has_activities’, ‘bpfr_hide_admin_activity’, 10, 2 ); // Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user=’1′; // Id’s to remove, separated by comma if($object != ‘members’ && $object != ‘friends’)// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args[‘user_id’])) return $qs; if(!empty($args[‘exclude’])) $args[‘exclude’] = $args[‘exclude’].’,’.$excluded_user; else $args[‘exclude’] = $excluded_user; $qs = build_query($args); return $qs; } add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter(‘bp_get_total_member_count’,’bpfr_hide_get_total_filter’);
December 9, 2016 at 12:39 am #261914In reply to: [Resolved] How to Hide Admin accounts 2016?
livingflameParticipantThis work okey –>: but, How I can Hide Admin from BuddyPress Widget??
—->
// Deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 ); // Hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 ); // Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
October 26, 2016 at 4:27 pm #260398ico33ParticipantNothing to do!
Error:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 3
This is the bp-custom code:
<? php
function buddydev_hide_members_directory_from_all_except_admin() {
if ( bp_is_members_directory() && ! is_super_admin() ) {
//should we add a message too?
//bp_core_add_message( ‘Private page.’, ‘error’ );
bp_core_redirect( site_url(‘/’) );
}
}
add_action( ‘bp_template_redirect’, ‘buddydev_hide_members_directory_from_all_except_admin’ );October 26, 2016 at 12:26 pm #260381danbpParticipantThe function is working correctly on my install.
Perhaps you have an issue with quotes, ie after copy/pasting the snippet from a topic where the code whas inserted without using the code button.
Which software do you use to publish bp-custom ?Copy/paste following and give a try:
function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
October 26, 2016 at 9:55 am #260371ico33ParticipantThanks! I did it with your suggest, so the file is
<? php function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
But every page of the website is now again a blank page with this error:Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 2
October 26, 2016 at 7:41 am #260364ico33ParticipantHello and thanks for the support, I tried the solution suggested, but after I created and then uploaded the file bp-custom in the plugins folder I got an error in every page of the website:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 2
This is my file bp-custom:
<? php function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' ); ?>
September 19, 2016 at 5:37 pm #258920Brajesh SinghParticipantPlease put this code in your bp-custom.php
function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
That should do it. Hoe it helps.
July 11, 2016 at 5:23 pm #256487fidelduqueParticipantHi, I’m using Buddypress Version 2.5.3 and WordPress 4.5.2.
I’m running a multisite wordpress installation, Right now I’m trying to exclude the suscribers in the members directory, this is the code i found:
function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude if($object!='members')//hide for members only return $qs; $excluded_user = implode(',',get_users('role=subscriber&fields=ID')); $excluded_admins = implode(',',get_users('role=administrator&fields=ID')); //$excluded_self=bp_loggedin_user_id(); $args=wp_parse_args($qs); //check if we are searching for friends list etc?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])){ $args['exclude']=$args['exclude'].','.$excluded_user; $args['exclude']=$args['exclude'].','.$excluded_admins; //$args['exclude']=$args['exclude'].','.$excluded_self; } else { $args['exclude']=$excluded_user; if(!empty($args['exclude'])) $args['exclude']= $args['exclude'].','.$excluded_admins; else $args['exclude']=$excluded_admins; //$args['exclude']=$excluded_self; } $qs=build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
but right now, the get_users function won’t show any subscriber because there are not suscribers on this site, but on the other ones. Anyway, the buddypress is showing all users including the ones in the other sites.
any hint?
Thanks
June 29, 2016 at 7:57 pm #255513danbpParticipantHi @navyspitfire,
when you pick up code somewhere, you should also read the comments. The solution to your issue was in one of them.
Here is what wil exclude site admin from members directory and exclude also the logged_in user. The total member count will also be adjusted correctly on All members [x] tab and for the pagination count.
$count-2
instead of$count-1
do the trick.Excluded members, incl. admin, are of course excluded from search.
function bpex_hide_admin_on_member_directory( $qs=false, $object=false ){ // Id's to hide, separated by comma $excluded_user = '1' ; // hide to members & friends if($object != 'members' && $object != 'friends') return $qs; $args = wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action( 'bp_ajax_querystring','bpex_hide_admin_on_member_directory', 20, 2 ); // once admin is excluded, we must recount the members ! function bpex_hide_get_total_filter( $count ){ return $count-2; } add_filter( 'bp_get_total_member_count', 'bpex_hide_get_total_filter' ); function bpex_exclude_loggedin_user( $qs = false, $object = false ) { //list of users to exclude if( !is_user_logged_in() ) return $qs; //if the user is logged in , let us exclude her/him $excluded_user= get_current_user_id(); if( $object !='members' )//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are listing friends?, do not exclude in this case if( !empty( $args[ 'user_id' ] ) ) return $qs; if( !empty( $args['exclude'] ) ) $args['exclude'] = $args['exclude'] .','. $excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query( $args ); return $qs; } add_action('bp_ajax_querystring','bpex_exclude_loggedin_user', 20, 2 );
Codex Reference
October 28, 2015 at 2:48 pm #246094In reply to: Hide All Admins from All Buddypress Activities
spluffordParticipantHi, struggling to get any of the the code in post #190874 to work. I have created a bp-custom.php file which I have uploaded to the root of the buddpress folder and my code looks like this:
<?php // deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 ); // Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter'); // hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 ); ?>
Not sure what I am doing wrong. All help gratefully received! Thanks
February 23, 2015 at 11:05 am #235021In reply to: How to hide administrators from list members
danbpParticipantHello,
please try to search in topics if a similar question wasn’t ask in the past.
hide+admin+in+adminA possible solution here.
December 29, 2014 at 7:25 pm #231214In reply to: [Resolved] admin bar mobile css
shayneParticipantI figured it out. For some reason WordPress decided it would be a good idea to hide custom menus added to the toolbar(when did they change the name from admin bar?) when viewing it on mobile devices.
If you browse through the WordPress directory you will find the css for the toolbar in wp-includes\css\admin-bar.css.
This line hides everything but the default items from the toolbar.
/* Show only default top level items */ #wp-toolbar > ul > li { display: none; }
By changing “display: none” to “display: block”. That fixed the problem i was having.
So hopefully that information is useful to someone.
Oh and one more thing. If you need to modify the toolbars css don’t do it there. You shouldn’t modify WordPress’s core files. Instead you should copy that css to your themes style sheet.
October 22, 2014 at 9:24 pm #223433danbpParticipantPlease use the code button to insert code in a topic. Thank you !
Give this a try
// deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 ); // Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter'); // hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
September 8, 2014 at 2:51 pm #190941In reply to: Activity Favorite Notification
aghajoonParticipantthis code work for me but java script not work and when user favorite comment user can’t remove notification help me
define("BP_FAVORITE_NOTIFIER_SLUG","fa_notification"); function bp_favorite_setup_globals() { global $bp, $current_blog; $bp->bp_favorite=new stdClass(); $bp->bp_favorite->id = 'bp_favorite'; $bp->bp_favorite->slug = BP_FAVORITE_NOTIFIER_SLUG; $bp->bp_favorite->notification_callback = 'bp_favorite_format_notifications';//show the notification $bp->active_components[$bp->bp_favorite->id] = $bp->bp_favorite->id; do_action( 'bp_favorite_setup_globals' ); } add_action( 'bp_setup_globals', 'bp_favorite_setup_globals' ); function bp_favorite_format_notifications( $action, $activity_id, $secondary_item_id, $total_items,$format='string' ) { $action_checker = explode('_', $action); $activities = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'display_comments' => true) ); $glue = ''; $user_names = array(); $users = find_favorite_involved_persons($activity_id, $action); $total_user = $count = count($users); if($count > 2) { $users = array_slice($users, $count - 2); $count = $count - 2; $glue = ", "; } else if($total_user == 2) { $glue = " and "; } foreach((array)$users as $user_id) { $user_names[] = bp_core_get_user_displayname($user_id); } if(!empty($user_names)) { $favoriting_users = join($glue, $user_names); } switch ( $action ) { case 'new_bp_favorite_'.$activity_id: if($total_user > 2) { $text = $favoriting_users.' and '.$count.' liked: '.substr($activities["activities"][0]->content,0,32).'...'; } else { $text = $favoriting_users." like: ".substr($activities["activities"][0]->content,0,32)."..."; } break; } $url = '<div id="'.$action.'"class="notification"><a href="#" class="social-delete" onclick="deleteAjaxNotification(\''.$action.'\',\''.$activity_id.'\', \''.admin_url( 'admin-ajax.php' ).'\'); return false;">x</a><span class="social-loader"></span></div>'; $link = favorite_activity_get_permalink( $activity_id ); if($format=='string') { return apply_filters( 'bp_activity_multiple_favorite_notifications', '<a href="' . $link. '">' . $text . '</a>'. $url .'' ,$users, $total_user, $count, $glue, $link ); } else { return array( 'link' => $link, 'text' => $text ); } return false; } function find_favorite_involved_persons($activity_id, $action) { global $bp,$wpdb; $table = $wpdb->prefix . 'bp_notifications'; return $wpdb->get_col($wpdb->prepare("select DISTINCT(secondary_item_id) from {$table} where item_id=%d and secondary_item_id!=%d and component_action = %s",$activity_id,$bp->loggedin_user->id, $action)); } function favorite_activity_get_permalink( $activity_id, $activity_obj = false ) { global $bp; if ( !$activity_obj ) $activity_obj = new BP_Activity_Activity( $activity_id ); if ( 'activity_comment' == $activity_obj->type ) $link = bp_get_activity_directory_permalink(). 'p/' . $activity_obj->item_id . '/'; else $link = bp_get_activity_directory_permalink() . 'p/' . $activity_obj->id . '/'; return apply_filters( 'ac_notifier_activity_get_permalink', $link ); } function favorite_notifier_remove_notification($activity ,$has_access){ global $bp; if($has_access) bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->bp_favorite->id, 'new_bp_favorite_'.$activity->id ); } add_action("bp_activity_screen_single_activity_permalink","favorite_notifier_remove_notification", 10,2); function favorite_notification( $activity_id){ global $bp; $activities = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'display_comments' => true) ); $author_id = $activities['activities'][0]->user_id; $user_id = bp_loggedin_user_id(); // if favoriting own activity, dont send notification if( $user_id == $author_id ) { return false; } if ( bp_is_active( 'notifications' ) ) { bp_notifications_add_notification( array( 'user_id' => $author_id, 'item_id' => $activity_id, 'secondary_item_id' => $user_id, 'component_name' => $bp->bp_favorite->id, 'component_action' => 'new_bp_favorite_'.$activity_id, 'date_notified' => bp_core_current_time(), 'is_new' => 1, ) ); } } add_action("bp_activity_add_user_favorite","favorite_notification", 10, 2); function deleteAjaxNotification(){ global $bp; bp_core_delete_notifications_by_item_id ($bp->loggedin_user->id, $bp->bp_favorite->id, 'new_bp_favorite_'.$activity->id); die(); } add_action('wp_ajax_deleteAjaxNotification', 'deleteAjaxNotification' ); function bp_like_add_like_action() { global $bp, $activities_template; if ( bp_activity_can_favorite() ) : $my_fav_count = bp_activity_get_meta( bp_get_activity_comment_id(), 'favorite_count' ); $my_fav_count = "<span>".$my_fav_count."</span>"; $is_favorite = apply_filters( 'bp_get_activity_is_favorite', in_array( bp_get_activity_comment_id(), $activities_template->my_favs ) ); if ( !$is_favorite ) : ?> <a href="<?php echo apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . bp_get_activity_comment_id() . '/' ), 'mark_favorite' ) ); ?>" class="tooltip-trigger fav bp-secondary-action bp-primary-action" title="<?php _e( 'Favorite', 'buddypress' ); ?>" style="position:relative;"><?php _e( 'Favorite', 'buddypress' ); ?><?php echo $my_fav_count; ?></a> <?php else : ?> <a href="<?php echo apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . bp_get_activity_comment_id() . '/' ), 'mark_favorite' ) ); ?>" class="tooltip-trigger unfav bp-secondary-action bp-primary-action" title="<?php _e( 'Remove Favorite', 'buddypress' ); ?>" style="position:relative;"><?php _e( 'Remove Favorite', 'buddypress' ); ?><?php echo $my_fav_count; ?></a> <?php endif; endif; } add_filter( 'bp_activity_comment_options' , 'bp_like_add_like_action', 1000 );
and java code
function deleteAjaxNotification(action_id, activity_id, adminUrl){ jQuery('#'+action_id).children(".social-delete").html(""); jQuery('#'+action_id ).children(".social-loader").show(); jQuery.ajax({ type: 'post', url: adminUrl, data: { action: "deleteAjaxNotification", action_id:action_id, activity_id:activity_id }, success: function(data) { jQuery('#'+action_id).parent().hide(); } }); }
September 7, 2014 at 7:43 pm #190874In reply to: Hide Admin from Members and Activity
danbpParticipanthi @canadadre,
you have to read the mentionnedd topic AND to follow the links if the topic contains some. 😉
i hope for you that you know how to copy/paste, because the above snippets must be added to your child-theme functions.php, or better into bp-custom.php
1. – Deny access to admins profile
// deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 );
2. – Remove admin from the member directory and recount members
// Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
3. – Hide admin’s activities from all activity feeds
// hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
May this help !
August 26, 2014 at 11:44 am #188500In reply to: [Resolved] Nobody visibility
danbpParticipantoh crossposting ! haven’t seen henry’s answer.
nobody visibility doesn’t exist. This setting is called “only me“. This means that only the member can see this field – and the site admins. Such fields are not for site admins, but for the members !
I don’t really understand what is not working for you, as what you’re looking for doesn’t exist in BuddyPress. Sorry if i’m misunderstanding you.
When you create such a field visibility, you should also set “Enforce the default visibility for all members“, so the member cannot modify it later on his profile settings.
Little weird side effect, when a “only me” field is used and member A wrote hello, this word becames clickabke, by default. When member B write also hello, it becames also clickable. And if A or B clcik on Hello, it shows a list of all members who wrote the same word. In this case A and B !
Not really confidential, isn’t it ? The solution is to remove the clickable link.
Here’s a snippet which let you do that selectively.function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { // Access the field you are going to display value. global $field; // In this array you write the ids of the fields you want to hide the link. $excluded_field_ids = array(2,9,54); // field ID separated by comma // If the id of this $field is in the array, we return the value only and not the link. if (in_array($field->id, $excluded_field_ids)) return $field_value; if ( 'datebox' == $field_type ) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); // If the value is a URL, skip it and just make it clickable. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { $new_values[] = make_clickable( $value ); // Is not clickable } else { // More than 5 spaces if ( count( explode( ' ', $value ) ) > 5 ) { $new_values[] = $value; // Less than 5 spaces } else { $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); $new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>'; } } } $values = implode( ', ', $new_values ); } return $values; } /** * We remove the buddypress filter and add our custom filter. */ function remove_xprofile_links() { // Remove the old filter. remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); // Add your custom filter. add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2); } add_action('bp_setup_globals', 'remove_xprofile_links');
June 20, 2014 at 6:46 am #184252In reply to: Hide admin activity in BP 2.x
nirgaloParticipantHi, I wanted to also hide admin from the “last activity” widget. I did an override of bp-core/bp-core-widget.php in my theme but it was not taken into account. However if I directly modify bp-core-widget.php in the BP plugin directory, then in works. Too bad the override doesn’t work, I guess I need to create my own widget…
November 24, 2013 at 12:30 am #174704In reply to: Buddypress on Mobile / Hide admin access
mattg123Participant@pjbursnall yeah that code replicates the notification element only (the only part that is somewhat confusing to replicate) you place the code in the plugins directory in bp-custom.php you may have to create the file yourself.
http://stackoverflow.com/questions/9953482/how-to-make-a-pure-css-based-dropdown-menu – shows you how to create a drop down menu, https://codex.wordpress.org/Function_Reference/get_currentuserinfo get the current users info so you can create links to their profile pages, etc.
Just a note, to add the notifcations to your custom bar your code will look something like
<li><?php bp_notification_badge(); ?></li>
September 20, 2013 at 4:10 am #171569geoffreysfParticipantPutting this in the functions or bp-custom.php files did not work.
I finally managed to get the admin and any other user excluded from the members directory by modifying the bp_had_members query that was already in my members-loop.php file.
<?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ).’&exclude=1,3,25′ . ‘&type=alphabetical&per_page=30’ ) ) : ?> <!– &exclude= user_ids of the people you want to exclude –>
By adding just this, it also removed the users from the total members count.
Note: I do not use friends or activity feeds on my site, so I have no idea if it hides from them, but I suppose it wouldn’t.
I have been looking high and low for the answer to this with my limited PHP knowledge… and wanted to share it back so other people could learn from it too.
And credit where it is due, this post led me to the answer.
https://buddypress.org/support/topic/member-parameters-not-working-with-bp_ajax_querystring/ -
AuthorSearch Results