Version Description
- 2022-04-11 =
- ENHANCEMENT: Added
habfna_show_admin_bar_roles
filter to show the admin toolbar for additional roles. - BUG FIX: Fixed code to hide the admin bar from non-admins when viewing the Edit Profile WordPress admin page.
Download this release
Release Info
Developer | strangerstudios |
Plugin | Hide Admin Bar from Non-Admins |
Version | 1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.0.1
- hide-admin-bar-from-non-admins.php +25 -20
- readme.txt +50 -13
hide-admin-bar-from-non-admins.php
CHANGED
@@ -1,33 +1,38 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
Plugin Name: Hide Admin Bar From Non-
|
4 |
-
Plugin URI:
|
5 |
-
Description:
|
6 |
-
Version: 1.0
|
7 |
Author: Stranger Studios
|
8 |
-
Author URI:
|
9 |
*/
|
10 |
/*
|
11 |
Copyright 2013 Stranger Studios (email : jason@strangerstudios.com)
|
12 |
Licensed under the GPLv2 license: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
*/
|
14 |
|
15 |
-
function
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
<?php
|
24 |
}
|
25 |
-
|
26 |
-
{
|
27 |
-
if(
|
28 |
-
{
|
29 |
add_filter( 'show_admin_bar', '__return_false' );
|
30 |
-
add_action( 'admin_print_scripts-profile.php', 'habfna_hide_admin_bar_settings' );
|
31 |
}
|
32 |
}
|
33 |
-
add_action('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
/*
|
3 |
+
Plugin Name: Hide Admin Bar From Non-Admins
|
4 |
+
Plugin URI: https://www.paidmembershipspro.com/add-ons/hide-admin-bar-from-non-admins/
|
5 |
+
Description: Hides the WordPress toolbar (admin bar) for all non-admin users.
|
6 |
+
Version: 1.0.1
|
7 |
Author: Stranger Studios
|
8 |
+
Author URI: https://www.strangerstudios.com
|
9 |
*/
|
10 |
/*
|
11 |
Copyright 2013 Stranger Studios (email : jason@strangerstudios.com)
|
12 |
Licensed under the GPLv2 license: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
*/
|
14 |
|
15 |
+
function habfna_show_admin_bar() {
|
16 |
+
$user = wp_get_current_user();
|
17 |
+
$habfna_show_admin_bar_roles = apply_filters( 'habfna_show_admin_bar_roles', array( 'administrator' ) );
|
18 |
+
if ( ! array_intersect( $habfna_show_admin_bar_roles, $user->roles ) ) {
|
19 |
+
return true;
|
20 |
+
} else {
|
21 |
+
return false;
|
22 |
+
}
|
|
|
23 |
}
|
24 |
+
|
25 |
+
function habfna_disable_frontend_admin_bar() {
|
26 |
+
if ( habfna_show_admin_bar() ) {
|
|
|
27 |
add_filter( 'show_admin_bar', '__return_false' );
|
|
|
28 |
}
|
29 |
}
|
30 |
+
add_action( 'wp', 'habfna_disable_frontend_admin_bar' );
|
31 |
+
|
32 |
+
function habfna_disable_backend_admin_bar() {
|
33 |
+
if ( habfna_show_admin_bar() ) { ?>
|
34 |
+
<style type="text/css" media="screen">html.wp-toolbar { padding-top: 0; } #wpadminbar { display: none; }</style>
|
35 |
+
<?php
|
36 |
+
}
|
37 |
+
}
|
38 |
+
add_action( 'admin_print_scripts-profile.php', 'habfna_disable_backend_admin_bar' );
|
readme.txt
CHANGED
@@ -1,26 +1,63 @@
|
|
1 |
=== Hide Admin Bar from Non-Admins ===
|
2 |
Contributors: strangerstudios
|
3 |
-
Tags: admin bar, adminbar, dashboard, membership
|
4 |
-
Requires at least:
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 1.0
|
7 |
|
8 |
-
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
This plugin
|
20 |
|
21 |
== Installation ==
|
22 |
|
23 |
-
|
24 |
-
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
25 |
-
1. Tweak the plugin code as needed. There are no settings, and this plugin will not be updated oftne.
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
=== Hide Admin Bar from Non-Admins ===
|
2 |
Contributors: strangerstudios
|
3 |
+
Tags: admin bar, toolbar, adminbar, dashboard, membership
|
4 |
+
Requires at least: 5.2
|
5 |
+
Tested up to: 6.1
|
6 |
+
Stable tag: 1.0.1
|
7 |
|
8 |
+
Hides the WordPress toolbar (admin bar) for all non-admin users. Simple plugin with no settings to configure.
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
### Install, activate, and you're done.
|
13 |
|
14 |
+
This plugin hides the WordPress Toolbar (admin bar) for all visitors and users without the 'administrator' role. It's a very simple plugin with no settings to configure.
|
15 |
|
16 |
+
* Use this plugin for sites with only one admin who needs access to the dashboard and the admin bar.
|
17 |
+
* This plugin is super lightweight, with just a few lines of code.
|
18 |
+
* If you need to show the toolbar for other user roles, use the filter `habfna_show_admin_bar_roles`.
|
19 |
|
20 |
+
This plugin is a tweak of the code by Yoast to hide the admin bar for non-admins only.
|
21 |
|
22 |
== Installation ==
|
23 |
|
24 |
+
### Install Hide Admin Bar from Non-Admins from within WordPress
|
|
|
|
|
25 |
|
26 |
+
1. Visit the plugins page within your dashboard and select "Add New"
|
27 |
+
1. Search for "Hide Admin Bar from Non-Admins"
|
28 |
+
1. Locate this plugin and click "Install"
|
29 |
+
1. Activate "Hide Admin Bar from Non-Admins" through the "Plugins" menu in WordPress
|
30 |
+
1. That's it. There are no settings.
|
31 |
+
|
32 |
+
### Install Hide Admin Bar from Non-Admins Manually
|
33 |
+
|
34 |
+
1. Upload the `hide-admin-bar-from-non-admins` folder to the `/wp-content/plugins/` directory
|
35 |
+
1. Activate "Hide Admin Bar from Non-Admins" through the "Plugins" menu in WordPress
|
36 |
+
1. That's it. There are no settings.
|
37 |
+
|
38 |
+
== Frequently Asked Questions ==
|
39 |
+
|
40 |
+
= How do I hide the toolbar for other user roles? =
|
41 |
+
If you need to show the toolbar for other user roles, use the filter `habfna_show_admin_bar_roles`. Here is a [code recipe that demonstrates how to use this filter](https://gist.github.com/kimcoleman/a16ee438a292c927f0b2bcf7a9fc8763).
|
42 |
+
|
43 |
+
= How do I block non-admins from access the WordPress admin area? =
|
44 |
+
This plugin does not handle any user redirection. It's only for hiding the admin bar. If you are building a site that needs more robust user management, consider our [WordPress membership plugin, Paid Memberships Pro](https://www.paidmembershipspro.com/?utm_source=wordpress-org&utm_medium=readme&utm_campaign=hide-admin-bar-from-non-admins).
|
45 |
+
|
46 |
+
Paid Memberships Pro allows anyone to build a membership site—for free. Restrict content, accept payment, and manage subscriptions right from your WordPress admin.
|
47 |
+
|
48 |
+
= I found a bug in the plugin. =
|
49 |
+
|
50 |
+
Please post it in the issues section of GitHub and we'll fix it as soon as we can. Thanks for helping. https://github.com/strangerstudios/hide-admin-bar-from-non-admins/issues
|
51 |
+
|
52 |
+
= I need help installing, configuring, or customizing the plugin. =
|
53 |
+
|
54 |
+
Please visit our premium support site at https://www.paidmembershipspro.com for more documentation and our support forums.
|
55 |
+
|
56 |
+
== Changelog ==
|
57 |
+
|
58 |
+
= 1.0.1 - 2022-04-11 =
|
59 |
+
* ENHANCEMENT: Added `habfna_show_admin_bar_roles` filter to show the admin toolbar for additional roles.
|
60 |
+
* BUG FIX: Fixed code to hide the admin bar from non-admins when viewing the Edit Profile WordPress admin page.
|
61 |
+
|
62 |
+
= 1.0 =
|
63 |
+
* Initial version of the plugin.
|