Admin Bar Controller

/* ~~~~~~~~~~~~~ Admin Bar ~~~~~~~~~~~~~~ */

define('TER_LOGIN_ADMIN_BAR',true); //Options = true,false - Show adminbar when logged out
define('TER_ADMIN_BAR','all'); //Options = 'all','admin','editor','none' - Show adminbar when user is logged in

//Admin Bar
function ter_admin_bar(){
if(TER_ADMIN_BAR != 'all') add_action('admin_print_scripts-profile.php','ter_hide_admin_bar_opt');
if(!is_user_logged_in() && TER_LOGIN_ADMIN_BAR == true) return true;
switch(TER_ADMIN_BAR){
case 'all': $hide_bar = false; break;
case 'admin': if(!current_user_can('administrator')) $hide_bar = true; break;
case 'editor': if(!current_user_can('editor')) $hide_bar = true; break;
case 'none': $hide_bar = true; break;
default: $hide_bar = false;
}
if($hide_bar) return false;
else return true;
}

//Login Admin Bar
function ter_login_admin_bar($wp_admin_bar){
if(!is_user_logged_in() && TER_LOGIN_ADMIN_BAR == true) $wp_admin_bar->add_menu(array('title' => __('Log In'),'href' => wp_login_url()));
}

//Admin Bar Options
function ter_hide_admin_bar_opt(){ echo '<style type="text/css">.show-admin-bar{display:none;}</style>'; }

add_action('admin_bar_menu','ter_login_admin_bar');
add_filter('show_admin_bar','ter_admin_bar');

0 Comments

You must be logged in to post a comment.