Created
March 28, 2024 18:03
-
-
Save endurtech/e5f3346f26d7ab800858c69e4cc24ef6 to your computer and use it in GitHub Desktop.
Disables the WordPress Admin Bar and WordPress Admin Backend access for Subscribers. Insert into functions.php
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 | |
// Disable Subscriber WordPress Admin Bar | |
// Disables the WordPress Admin Bar and WordPress Admin Backend access for Subscribers. | |
// https://endurtech.com/disable-subscriber-wordpress-admin-bar/ | |
add_action( 'init', 'disable_admin_bar_for_subscribers' ); | |
function disable_admin_bar_for_subscribers() | |
{ | |
if ( current_user_can( 'subscriber' ) ) | |
{ | |
show_admin_bar( false ); | |
// Redirect Subscribers Away From Admin Backend | |
if ( is_admin() ) | |
{ | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment