I tend to use CSS to hide all sorts of things within the BuddyPress interface rather than unhooking functions. I find that it more quickly and flexibly accommodates my clients’ changing desires.
Today I needed to add a css body class for group moderators and admins. The goal was to hide the “Admin” button for moderators but display it for admins.
To pull it off, I added the following to my functions.php file:
// Add "bp-group-moderator" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_bp_group_moderator_body_classes');
function add_bp_group_moderator_body_classes($classes) {
if ( bp_group_is_mod() ):
// add 'bp-group-moderator' to the $classes array
$classes[] = 'bp-group-moderator';
// return the $classes array
return $classes;
else :
// do nothing
$classes[] = '';
// return the $classes array
return $classes;
endif;
}
// Add "bp-group-admin" to body_class function if we are on a BuddyPress-generated page
add_filter('body_class','add_bp_group_admin_body_classes');
function add_bp_group_admin_body_classes($classes) {
if ( bp_group_is_admin() ):
// add 'bp-group-admin' to the $classes array
$classes[] = 'bp-group-admin';
// return the $classes array
return $classes;
else :
// do nothing
$classes[] = '';
// return the $classes array
return $classes;
endif;
}
It works nicely!
I plan to release it as a plugin. Perhaps some day this will be in core. In general, I can never have too many body classes. 🙂
More posts from themightymo.com
How to Connect a GoDaddy Site to ManageWP
GoDaddy owns ManageWP, and, strangely, they make it very difficult to add GoDaddy-managed WordPress sites to their ManageWP service. Thankfully, there’s a quick workaround: Visit https://yoursite.com/wp-admin/plugins.php?showWorker=1 — This will make the ManageWP “Worker” plugin visible. Copy the connection info from the ManageWP Worker plugin. Add the site per-normal on ManageWP. That’s it! I hope this…
How to check if your current page is the wp-login.php page
I realized this morning that my TMM Maintenance Mode WordPress plugin had a bug that was causing the wp-login.php page to be inaccessible. The solution was to write a simple function that checks whether or not we’re currently on a login page, and then add a call to that function in my code. Here’s the…
WooCommerce Product Image Gallery Not Loading with WP Rocket Active
Today I updated a WooCommerce site, and everything worked fine, except for the images on product pages – they were not displaying at all. After a lot of trial & error, I realized that WP Rocket was to blame. I’m not sure exactly what the issue was (though my hunch is that it had to…