Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Which WordPress tempalte are you currently one? http://wp.me/p4gJ2a-Be
function ap_show_template() {
// bail early
if ( is_admin() || !is_user_logged_in() )
return;
if ( !is_admin_bar_showing() || !current_user_can( 'edit_files' ) )
return;
global $template, $wp_admin_bar;
$title = ( isset( $template ) ) ? str_replace( array( get_template_directory(), get_stylesheet_directory() ), '', $template ) : 'Unknown';
$wp_admin_bar->add_node( array(
'parent' => false,
'id' => 'template',
'title' => $title,
'href' => '#'
) );
// optional add number queries under the template
$wp_admin_bar->add_node( array(
'parent' => 'template',
'id' => 'queries',
'title' => sprintf( esc_attr( '%s queries in %s sec' ), get_num_queries(), timer_stop() ),
'href' => '#'
) );
}
add_action( 'admin_bar_menu', 'ap_show_template', 10 );
@chuckreynolds

This comment has been minimized.

Copy link

commented Feb 6, 2015

quicker way to check admin perms?

if ( ! current_user_can( 'manage_options' ) ) {
    return false;
}
@thefrosty

This comment has been minimized.

Copy link
Owner Author

commented Feb 6, 2015

Updated the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.