Skip to content

Instantly share code, notes, and snippets.

@fiftin
Last active September 4, 2015 03:17
Show Gist options
  • Save fiftin/63a45e6d1083cf8265d7 to your computer and use it in GitHub Desktop.
Save fiftin/63a45e6d1083cf8265d7 to your computer and use it in GitHub Desktop.
Plugin for removing admin bar from Webpress site
<?php
/*
Plugin Name: Remove admin bar
Author: Denis Gukov
Version: 1.0
*/
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
function hide_admin_bar_backbox() {
$screen = get_current_screen();
if ($screen->id != 'profile' && $screen->id != 'user-edit') {
return;
}
if ($screen->id == 'profile' && current_user_can('administrator')) {
return;
}
if ($screen->id == 'user-edit') {
$user_id = filter_input(INPUT_GET, 'user_id', FILTER_VALIDATE_INT);
$user_query = new WP_User_Query([ 'search' => $user_id, 'search_columns' => ['ID'] ]);
foreach ($user_query->results as $user) { // only one, no need break
if (in_array('administrator', $user->roles)) {
return;
}
}
}
echo "<style>
.show-admin-bar {
display: none;
}
</style>";
}
add_action('admin_head', 'hide_admin_bar_backbox');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment