Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefrosty/e01dc0cc06cd16498c1c to your computer and use it in GitHub Desktop.
Save thefrosty/e01dc0cc06cd16498c1c to your computer and use it in GitHub Desktop.
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
Copy link

quicker way to check admin perms?

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

@thefrosty
Copy link
Author

Updated the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment