PluginProbe ʕ •ᴥ•ʔ
Show Current Template / trunk
Show Current Template vtrunk
trunk 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.4.0 0.4.1 0.4.2 0.4.3 0.4.4 0.4.4-alpha 0.4.4-beta 0.4.5 0.4.6 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4
show-current-template / show-current-template.php
show-current-template Last commit date
assets 5 years ago css 2 years ago languages 13 years ago README.md 2 years ago readme.txt 1 month ago show-current-template.php 6 months ago
show-current-template.php
229 lines
1 <?php
2 /**
3 Plugin Name: Show Current Template
4 Plugin URI: https://wp.tekapo.com/
5 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>
6 Author: JOTAKI Taisuke
7 Version: 0.5.4
8 Requires at least: 5.9
9 Requires PHP: 7.4
10 Author URI: https://tekapo.com/
11 Text Domain: show-current-template
12 Domain Path: /languages/
13
14 License:
15 Released under the GPL license
16 http://www.gnu.org/copyleft/gpl.html
17
18 Copyright 2026 (email : tekapo@gmail.com)
19
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 * */
34
35 define( 'WPSCT_VERSION', '0.5.4' );
36
37 load_plugin_textdomain( 'show-current-template', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
38
39 new Show_Template_File_Name();
40
41 class Show_Template_File_Name {
42
43 public $debug_info = array();
44
45 public function __construct() {
46 add_action( 'wp_footer', array( $this, 'get_included_files_at_footr' ) );
47
48 add_action( 'admin_bar_menu', array( &$this, 'show_template_file_name_on_top' ), 9999 );
49 add_action( 'wp_enqueue_scripts', array( &$this, 'add_current_template_stylesheet' ), 9999 );
50 add_action( 'wp_enqueue_scripts', array( &$this, 'add_current_template_js' ), 9999 );
51 }
52
53 public function show_template_file_name_on_top( $wp_admin_bar ) {
54 if ( is_admin() || ! is_super_admin() ) {
55 return;
56 }
57
58 global $template;
59
60 $template_relative_path = str_replace( ABSPATH . 'wp-content/', '', $template ?? '' );
61
62 if ( wp_is_block_theme() ) {
63 $template_file_name = __( '!!Block Theme!!', 'show-current-template' );
64 $site_editor_url = admin_url( 'site-editor.php' );
65 $block_theme_notice = sprintf(
66 /* translators: The placeholder is a URL. */
67 __(
68 "<p>The theme you're currently using is a block theme. You can modify its templates through the <a href='%s'>Site Editor</a> on your admin page.</p>
69 <p>Generally, it's advisable not to alter the template files of block themes directly.</p>
70 <p>Please refer to the <a href='https://developer.wordpress.org/block-editor/getting-started/full-site-editing/'>Full Site Editing</a> page for further information.</p>",
71 'show-current-template'
72 ),
73 $site_editor_url
74 );
75 } else {
76 $template_file_name = '<span class="show-template-name">' . basename( $template ) . '</span>';
77 $menu_title = __( 'Template relative path:', 'show-current-template' )
78 . '<span class="show-template-name"> ' . $template_relative_path . '</span>';
79 }
80
81 $current_theme = wp_get_theme();
82 $current_theme_name = $current_theme->get( 'Name' );
83 $parent_theme_name = '';
84
85 if ( is_child_theme() ) {
86 $child_theme_name = __( 'Theme name: ', 'show-current-template' )
87 . $current_theme_name;
88 $parent_theme = $current_theme->parent();
89 if ( $parent_theme ) {
90 $parent_theme_name = $parent_theme->get( 'Name' );
91 $parent_theme_name = ' (' . $parent_theme_name
92 . __( "'s child", 'show-current-template' ) . ')';
93 } else {
94 $parent_theme_name = '';
95 }
96 $parent_or_child = $child_theme_name . $parent_theme_name;
97 } else {
98 $parent_or_child = __( 'Theme name: ', 'show-current-template' )
99 . $current_theme_name . ' (' . __( 'NOT a child theme', 'show-current-template' ) . ')';
100 }
101
102 if ( ! wp_is_block_theme() ) {
103 $included_files = get_included_files();
104 $included_files_list = '';
105 sort( $included_files );
106 foreach ( $included_files as $filename ) {
107 if ( strstr( $filename, 'themes' ) ) {
108 $filepath = strstr( $filename, 'themes' );
109 if ( $template_relative_path === $filepath ) {
110 $included_files_list .= '';
111 } else {
112 $included_files_list .= '<li>' . "$filepath" . '</li>';
113 }
114 }
115 }
116
117 $admin_bar_dropdown_menu = __( 'Also, below template files are included:', 'show-current-template' )
118 . '<br /><ul id="included-files-list">'
119 . $included_files_list
120 . '</ul>';
121 }
122
123 global $wp_admin_bar;
124 $args = array(
125 'id' => 'show_template_file_name_on_top',
126 'title' => __( 'Template: ', 'show-current-template' ) . $template_file_name,
127 );
128
129 $wp_admin_bar->add_node( $args );
130
131 if ( wp_is_block_theme() ) {
132 $wp_admin_bar->add_menu(
133 array(
134 'parent' => 'show_template_file_name_on_top',
135 'id' => 'template_relative_path',
136 'title' => $block_theme_notice,
137 )
138 );
139 } else {
140 $wp_admin_bar->add_menu(
141 array(
142 'parent' => 'show_template_file_name_on_top',
143 'id' => 'template_relative_path',
144 'title' => $menu_title,
145 )
146 );
147
148 $wp_admin_bar->add_menu(
149 array(
150 'parent' => 'show_template_file_name_on_top',
151 'id' => 'is_child_theme',
152 'title' => $parent_or_child,
153 )
154 );
155
156 $wp_admin_bar->add_menu(
157 array(
158 'parent' => 'show_template_file_name_on_top',
159 'id' => 'included_files_path',
160 'title' => $admin_bar_dropdown_menu,
161 )
162 );
163 }
164 }
165
166 public function get_included_files_at_footr() {
167 if ( is_admin() || ! is_super_admin() || wp_is_block_theme() ) {
168 return;
169 }
170
171 $included_files = get_included_files();
172 global $template;
173
174 $template_relative_path = str_replace( ABSPATH . 'wp-content/', '', $template ?? '' );
175
176 sort( $included_files );
177 $included_files_list = '';
178 foreach ( $included_files as $filename ) {
179 if ( strstr( $filename, 'themes' . DIRECTORY_SEPARATOR ) ) {
180 $filepath = strstr( $filename, 'themes' );
181 if ( $template_relative_path === $filepath ) {
182 $included_files_list .= '';
183 } else {
184 $included_files_list .= '<li>' . "$filepath" . '</li>';
185 }
186 }
187 }
188 $included_files_format = '<ol id="included-files-fie-on-wp-footer">'
189 . '%s'
190 . '</ol>';
191 $included_files_html = sprintf( $included_files_format, $included_files_list );
192
193 echo wp_kses_post( $included_files_html );
194 }
195
196 public function add_current_template_stylesheet() {
197 if ( is_admin() || ! is_super_admin() ) {
198 return;
199 }
200
201 $wp_version = get_bloginfo( 'version' );
202
203 if ( $wp_version >= '3.8' ) {
204 $is_older_than_3_8 = '';
205 } else {
206 $is_older_than_3_8 = '-old';
207 }
208
209 $stylesheet_path = plugins_url( 'css/style' . $is_older_than_3_8 . '.css', __FILE__ );
210 wp_register_style( 'current-template-style', $stylesheet_path, array(), WPSCT_VERSION );
211 wp_enqueue_style( 'current-template-style' );
212 }
213 public function add_current_template_js() {
214 if ( is_admin() || ! is_super_admin() || ! is_admin_bar_showing() || wp_is_block_theme() ) {
215 return;
216 }
217
218 $wp_version = get_bloginfo( 'version' );
219
220 if ( $wp_version >= '5.4' ) {
221 $js_path = plugins_url( 'assets/js/replace.js', __FILE__ );
222 wp_register_script( 'current-template-js', $js_path, array( 'jquery' ), WPSCT_VERSION, true );
223 wp_enqueue_script( 'current-template-js' );
224 } else {
225 return;
226 }
227 }
228 }
229