show-current-template
Last commit date
css
9 years ago
languages
13 years ago
sass
9 years ago
README.md
13 years ago
readme.txt
6 years ago
show-current-template.php
6 years ago
show-current-template.pot
12 years ago
show-current-template.php
139 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | Plugin Name: Show Current Template |
| 5 | Plugin URI: https://wp.tekapo.com/ |
| 6 | Description: Show the current template file name in the tool bar. <a href="https://wp.tekapo.com/is-my-plugin-useful/">Is this useful for you?</a> |
| 7 | Author: JOTAKI Taisuke |
| 8 | Version: 0.3.4 |
| 9 | Author URI: https://tekapo.com/ |
| 10 | Text Domain: show-current-template |
| 11 | Domain Path: /languages/ |
| 12 | |
| 13 | License: |
| 14 | Released under the GPL license |
| 15 | http://www.gnu.org/copyleft/gpl.html |
| 16 | |
| 17 | Copyright 2013 (email : tekapo@gmail.com) |
| 18 | |
| 19 | This program is free software; you can redistribute it and/or modify |
| 20 | it under the terms of the GNU General Public License as published by |
| 21 | the Free Software Foundation; either version 2 of the License, or |
| 22 | (at your option) any later version. |
| 23 | |
| 24 | This program is distributed in the hope that it will be useful, |
| 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | GNU General Public License for more details. |
| 28 | |
| 29 | You should have received a copy of the GNU General Public License |
| 30 | along with this program; if not, write to the Free Software |
| 31 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 | */ |
| 33 | |
| 34 | load_plugin_textdomain( 'show-current-template', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 35 | |
| 36 | new Show_Template_File_Name(); |
| 37 | |
| 38 | class Show_Template_File_Name { |
| 39 | |
| 40 | function __construct() { |
| 41 | add_action( "admin_bar_menu", array( &$this, "show_template_file_name_on_top" ), 9999 ); |
| 42 | add_action( 'wp_enqueue_scripts', array( &$this, "add_current_template_stylesheet" ), 9999 ); |
| 43 | } |
| 44 | |
| 45 | public function show_template_file_name_on_top( $wp_admin_bar ) { |
| 46 | |
| 47 | if ( is_admin() or ! is_super_admin() ) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | global $template; |
| 52 | |
| 53 | $template_file_name = basename( $template ); |
| 54 | $template_relative_path = str_replace( ABSPATH . 'wp-content/', '', $template ); |
| 55 | |
| 56 | $current_theme = wp_get_theme(); |
| 57 | $current_theme_name = $current_theme->Name; |
| 58 | $parent_theme_name = ''; |
| 59 | |
| 60 | if ( is_child_theme() ) { |
| 61 | $child_theme_name = __( 'Theme name: ', 'show-current-template' ) |
| 62 | . $current_theme_name; |
| 63 | $parent_theme_name = $current_theme->parent()->Name; |
| 64 | $parent_theme_name = ' (' . $parent_theme_name |
| 65 | . __( "'s child", 'show-current-template' ) . ")"; |
| 66 | $parent_or_child = $child_theme_name . $parent_theme_name; |
| 67 | } else { |
| 68 | $parent_or_child = __( 'Theme name: ', 'show-current-template' ) |
| 69 | . $current_theme_name . ' (' . __( 'NOT a child theme', 'show-current-template' ) . ')'; |
| 70 | } |
| 71 | |
| 72 | $included_files = get_included_files(); |
| 73 | |
| 74 | sort( $included_files ); |
| 75 | $included_files_list = ''; |
| 76 | foreach ( $included_files as $filename ) { |
| 77 | if ( strstr( $filename, 'themes' ) ) { |
| 78 | $filepath = strstr( $filename, 'themes' ); |
| 79 | if ( $template_relative_path == $filepath ) { |
| 80 | $included_files_list .= ''; |
| 81 | } else { |
| 82 | $included_files_list .= '<li>' . "$filepath" . '</li>'; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | global $wp_admin_bar; |
| 88 | $args = array( |
| 89 | 'id' => 'show_template_file_name_on_top', |
| 90 | 'title' => __( 'Template:', 'show-current-template' ) |
| 91 | . '<span class="show-template-name"> ' . $template_file_name . '</span>', |
| 92 | ); |
| 93 | |
| 94 | $wp_admin_bar->add_node( $args ); |
| 95 | |
| 96 | $wp_admin_bar->add_menu( array( |
| 97 | 'parent' => 'show_template_file_name_on_top', |
| 98 | 'id' => 'template_relative_path', |
| 99 | 'title' => __( 'Template relative path:', 'show-current-template' ) |
| 100 | . '<span class="show-template-name"> ' . $template_relative_path . '</span>', |
| 101 | ) ); |
| 102 | |
| 103 | $wp_admin_bar->add_menu( array( |
| 104 | 'parent' => 'show_template_file_name_on_top', |
| 105 | 'id' => 'is_child_theme', |
| 106 | 'title' => $parent_or_child, |
| 107 | ) ); |
| 108 | |
| 109 | $wp_admin_bar->add_menu( array( |
| 110 | 'parent' => 'show_template_file_name_on_top', |
| 111 | 'id' => 'included_files_path', |
| 112 | 'title' => __( 'Also, below template files are included:', 'show-current-template' ) |
| 113 | . '<br /><ul id="included-files-list">' |
| 114 | . $included_files_list |
| 115 | . '</ul>', |
| 116 | ) ); |
| 117 | } |
| 118 | |
| 119 | public function add_current_template_stylesheet() { |
| 120 | |
| 121 | if ( is_admin() or ! is_super_admin() ) { |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | $wp_version = get_bloginfo( 'version' ); |
| 126 | |
| 127 | if ( $wp_version >= '3.8' ) { |
| 128 | $is_older_than_3_8 = ''; |
| 129 | } else { |
| 130 | $is_older_than_3_8 = '-old'; |
| 131 | } |
| 132 | |
| 133 | $stylesheet_path = plugins_url( 'css/style' . $is_older_than_3_8 . '.css', __FILE__ ); |
| 134 | wp_register_style( 'current-template-style', $stylesheet_path ); |
| 135 | wp_enqueue_style( 'current-template-style' ); |
| 136 | } |
| 137 | |
| 138 | } |
| 139 |