Skip to content

Commit

Permalink
Added template part support
Browse files Browse the repository at this point in the history
  • Loading branch information
barrykooij committed Apr 11, 2013
1 parent 387cfbf commit 14321fe
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions what-the-file.php
Expand Up @@ -3,7 +3,7 @@
Plugin Name: What The File
Plugin URI: http://www.barrykooij.com/what-the-file/
Description: What The File adds an option to your toolbar showing you what file is used to display the page you’re on. If you want to you can click the file name to edit it directly through the theme editor. Supports BuddyPress and Roots Theme. More information can be found at the <a href='http://wordpress.org/extend/plugins/what-the-file/'>WordPress plugin page</a>.
Version: 1.2.1
Version: 1.3.0
Author: Barry Kooij
Author URI: http://www.barrykooij.com/
License: GPL v3
Expand All @@ -30,6 +30,7 @@ class WhatTheFile
const OPTION_INSTALL_DATE = 'whatthefile-install-date';
const OPTION_ADMIN_NOTICE_KEY = 'whatthefile-hide-notice';
private $template_name = '';
private $template_parts = array();

public static function plugin_activation()
{
Expand Down Expand Up @@ -109,6 +110,20 @@ private function hooks()
if( class_exists( 'BuddyPress' ) ) {
add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
}

// Template part hooks
add_action( 'all', array( $this, 'save_template_parts' ), 1, 3 );
}

public function save_template_parts( $tag, $slug=null, $name=null )
{
if( 0 !== strpos( $tag, 'get_template_part_' ) ) {
return;
}

if( $slug != null && $name != null ){
$this->template_parts[] = $slug . '-' . $name . '.php';
}
}

public function catch_hide_notice()
Expand Down Expand Up @@ -170,13 +185,21 @@ public function save_current_page( $template_name )
public function admin_bar_menu()
{
global $wp_admin_bar;
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar' , 'parent' => 'top-secondary' , 'title' => __( 'What The File', 'what-the-file' ) , 'href' => FALSE ) );
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-sub' , 'parent' => 'wtf-bar' , 'title' => $this->get_current_page() , 'href' => get_admin_url() . 'theme-editor.php?file=' . $this->get_current_page() . '&theme=' . get_template() ) );

$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar', 'parent' => 'top-secondary', 'title' => __( 'What The File', 'what-the-file' ) , 'href' => false ) );
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-template-file', 'parent' => 'wtf-bar', 'title' => $this->get_current_page(), 'href' => get_admin_url() . 'theme-editor.php?file=' . $this->get_current_page() . '&theme=' . get_template() ) );

if( count( $this->template_parts ) > 0 ) {
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-template-parts', 'parent' => 'wtf-bar', 'title' => 'Template Parts', 'href' => false ) );
foreach( $this->template_parts as $template_part ) {
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-template-part-' . $template_part, 'parent' => 'wtf-bar-template-parts', 'title' => $template_part, 'href' => get_admin_url() . 'theme-editor.php?file=' . $template_part . '&theme=' . get_template() ) );
}
}
}

public function print_css()
{
echo "<style type=\"text/css\" media=\"screen\">#wp-admin-bar-wtf-bar #wp-admin-bar-wtf-bar-sub .ab-item{display: block !important;text-align: right;}</style>\n";
echo "<style type=\"text/css\" media=\"screen\">#wp-admin-bar-wtf-bar #wp-admin-bar-wtf-bar-template-file .ab-item, #wp-admin-bar-wtf-bar #wp-admin-bar-wtf-bar-template-parts {text-align:right;}</style>\n";
}

}
Expand Down

0 comments on commit 14321fe

Please sign in to comment.