Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from kimcoleman/dev
Browse files Browse the repository at this point in the history
Adding repo files, updating readme, new filter, improved code so it hides admin bar in admin profile edit, too.
  • Loading branch information
kimcoleman authored Apr 11, 2022
2 parents 190a8fc + c2366cd commit c7f0f32
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 26 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Items to ignore when downloading a zip

# Files
.gitattributes export-ignore
pmpro-buddypress-banner.png export-ignore
README.md export-ignore

# Folders
.github export-ignore
.wordpress-org export-ignore
Binary file added .wordpress-org/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
![](hide-admin-bar-from-non-admins-banner.png)

# [Hide Admin Bar from Non-Admins](https://wordpress.org/plugins/hide-admin-bar-from-non-admins/) #
[comment]: # (Generate badges from shields.io, only works for .org plugins to get other stats etc. We'd have to create our own endpoints for Premium plugins)

![WordPress Plugin Downloads](https://img.shields.io/wordpress/plugin/dy/hide-admin-bar-from-non-admins?style=flat-square) ![License](https://img.shields.io/badge/license-GPL--2.0%2B-red.svg?style=flat-square)

### Welcome to the Hide Admin Bar from Non-Admins GitHub Repository
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.

* Use this plugin for sites with only one admin who needs access to the dashboard and the admin bar.
* This plugin is super lightweight, with just a few lines of code.
* If you need to show the toolbar for other user roles, use the filter `habfna_show_admin_bar_roles`.

This plugin is a tweak of the code by Yoast to hide the admin bar for non-admins only.

For more information please visit [wordpress.org/plugins/hide-admin-bar-from-non-admins/](https://wordpress.org/plugins/hide-admin-bar-from-non-admins/)

## Installation ##
For detailed installation steps, visit the our [documentation](https://www.paidmembershipspro.com/add-ons/hide-admin-bar-from-non-admins/) page.

1. Download the current development ZIP file directly: `https://github.com/strangerstudios/hide-admin-bar-from-non-admins/archive/dev.zip`

**Please ensure that once installing this version of the plugin to remove `-dev` from the plugin's folder name.**

## Bugs ##
If you find an issue/bug, let us know by [creating a detailed GitHub issue](https://github.com/strangerstudios/hide-admin-bar-from-non-admins/issues/new).

## Support ##
This is a developer's portal for Hide Admin Bar from Non-Admins. We do not offer support on this channel. **Any support related questions should be directed to [wordpress.org/support/plugin/hide-admin-bar-from-non-admins/](https://wordpress.org/support/plugin/hide-admin-bar-from-non-admins/).**

## Contributing to Hide Admin Bar from Non-Admins ##

There are various **ways to help development** of Hide Admin Bar from Non-Admins:

1. Report [bugs/issues](https://github.com/strangerstudios/hide-admin-bar-from-non-admins/issues/new) on GitHub.
2. Work on any issues by submitting a Pull Request.

Here are some ways for **non-developers to contribute** to Hide Admin Bar from Non-Admins:

1. Leave an honest review for [Hide Admin Bar from Non-Admins](https://wordpress.org/support/plugin/hide-admin-bar-from-non-admins/reviews/#new-post).
Binary file added hide-admin-bar-from-non-admins-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 22 additions & 14 deletions hide-admin-bar-from-non-admins.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/*
Plugin Name: Hide Admin Bar From Non-admins
Plugin Name: Hide Admin Bar From Non-Admins
Plugin URI: https://www.paidmembershipspro.com/add-ons/hide-admin-bar-from-non-admins/
Description: A tweak of the code by Yoast to hide the admin bar for non-admins only.
Version: 1.0
Description: Hides the WordPress toolbar (admin bar) for all non-admin users.
Version: 1.0.1
Author: Stranger Studios
Author URI: https://www.strangerstudios.com
*/
Expand All @@ -12,19 +12,27 @@
Licensed under the GPLv2 license: http://www.gnu.org/licenses/gpl-2.0.html
*/

function habfna_hide_admin_bar_settings() { ?>
<style type="text/css">
.show-admin-bar {
display: none;
}
</style>
<?php
function habfna_show_admin_bar() {
$user = wp_get_current_user();
$habfna_show_admin_bar_roles = apply_filters( 'habfna_show_admin_bar_roles', array( 'administrator' ) );
if ( ! array_intersect( $habfna_show_admin_bar_roles, $user->roles ) ) {
return true;
} else {
return false;
}
}

function habfna_disable_admin_bar() {
if ( ! current_user_can( 'administrator' ) ) {
function habfna_disable_frontend_admin_bar() {
if ( habfna_show_admin_bar() ) {
add_filter( 'show_admin_bar', '__return_false' );
add_action( 'admin_print_scripts-profile.php', 'habfna_hide_admin_bar_settings' );
}
}
add_action('init', 'habfna_disable_admin_bar', 9);
add_action( 'wp', 'habfna_disable_frontend_admin_bar' );

function habfna_disable_backend_admin_bar() {
if ( habfna_show_admin_bar() ) { ?>
<style type="text/css" media="screen">html.wp-toolbar { padding-top: 0; } #wpadminbar { display: none; }</style>
<?php
}
}
add_action( 'admin_print_scripts-profile.php', 'habfna_disable_backend_admin_bar' );
47 changes: 35 additions & 12 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
=== Hide Admin Bar from Non-Admins ===
Contributors: strangerstudios
Tags: admin bar, adminbar, dashboard, membership
Tags: admin bar, toolbar, adminbar, dashboard, membership
Requires at least: 3.1
Tested up to: 5.9
Stable tag: 1.0
Tested up to: 5.9.3
Stable tag: 1.0.1

The WordPress admin bar will be hidden for all non-admin users.
Hides the WordPress toolbar (admin bar) for all non-admin users. Simple plugin with no settings to configure.

== Description ==

Perfect for sites where there is only one admin who needs access to the dashboard and the admin bar.
### Install, activate, and you're done.

When activated only administrators will see the admin bar.
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.

This plugin is just a few lines of code. Specifically the line `if(!current_user_can('administrator'))` determines who the admin bar is hidden for. Feel free to edit this to your needs. E.g. using
`if(!current_user_can('edit_posts'))` will allow authors to view the admin bar as well.
* Use this plugin for sites with only one admin who needs access to the dashboard and the admin bar.
* This plugin is super lightweight, with just a few lines of code.
* If you need to show the toolbar for other user roles, use the filter `habfna_show_admin_bar_roles`.

This plugin has no settings and will not be updated often, so feel free to edit to your needs.
This plugin is a tweak of the code by Yoast to hide the admin bar for non-admins only.

== Installation ==

1. Upload the `hide-admin-bar-from-non-admins` directory to the `/wp-content/plugins/` directory of your site.
1. Activate the plugin through the 'Plugins' menu in WordPress.
1. Tweak the plugin code as needed. There are no settings, and this plugin will not be updated often.
### Install Hide Admin Bar from Non-Admins from within WordPress

1. Visit the plugins page within your dashboard and select "Add New"
1. Search for "Hide Admin Bar from Non-Admins"
1. Locate this plugin and click "Install"
1. Activate "Hide Admin Bar from Non-Admins" through the "Plugins" menu in WordPress
1. That's it. There are no settings.

### Install Hide Admin Bar from Non-Admins Manually

1. Upload the `hide-admin-bar-from-non-admins` folder to the `/wp-content/plugins/` directory
1. Activate "Hide Admin Bar from Non-Admins" through the "Plugins" menu in WordPress
1. That's it. There are no settings.

== Frequently Asked Questions ==

= How do I hide the toolbar for other user roles? =
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).

= How do I block non-admins from access the WordPress admin area? =
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).

Paid Memberships Pro allows anyone to build a membership site—for free. Restrict content, accept payment, and manage subscriptions right from your WordPress admin.

= I found a bug in the plugin. =

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
Expand All @@ -36,5 +55,9 @@ Please visit our premium support site at https://www.paidmembershipspro.com for

== Changelog ==

= 1.0.1 - 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.

= 1.0 =
* Initial version of the plugin.

0 comments on commit c7f0f32

Please sign in to comment.