Version Description
Download this release
Release Info
Developer | barrykooij |
Plugin | What The File |
Version | 1.6.0 |
Comparing to | |
See all releases |
Code changes from version 1.5.4 to 1.6.0
- assets/js/what-the-file.js +39 -0
- classes/class-nag.php +3 -5
- readme.txt +22 -4
- what-the-file.php +75 -46
assets/js/what-the-file.js
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
window.addEventListener('load', (event) => {
|
2 |
+
|
3 |
+
if (wtf_templates === undefined) {
|
4 |
+
return;
|
5 |
+
}
|
6 |
+
|
7 |
+
// check if there are templates
|
8 |
+
if (wtf_templates.length > 0) {
|
9 |
+
// the parent selector
|
10 |
+
var parent = document.querySelector("#wp-admin-bar-wtf-bar-template-parts #wp-admin-bar-wtf-bar-template-parts-default");
|
11 |
+
|
12 |
+
// clear the loading
|
13 |
+
parent.replaceChildren();
|
14 |
+
|
15 |
+
// add new children
|
16 |
+
for (let i = 0; i < wtf_templates.length; i++) {
|
17 |
+
let listItem = document.createElement("li");
|
18 |
+
listItem.id = "wp-admin-bar-wtf-bar-template-part-template-parts/" + i;
|
19 |
+
|
20 |
+
let templateName;
|
21 |
+
|
22 |
+
if(wtf_templates[i].edit_url !== false) {
|
23 |
+
templateName = document.createElement("a");
|
24 |
+
templateName.className ="ab-item";
|
25 |
+
templateName.href = wtf_templates[i].edit_url;
|
26 |
+
}else {
|
27 |
+
templateName = document.createElement("span");
|
28 |
+
templateName.className ="ab-item ab-empty-item";
|
29 |
+
}
|
30 |
+
templateName.textContent = wtf_templates[i].file;
|
31 |
+
|
32 |
+
listItem.appendChild(templateName);
|
33 |
+
parent.appendChild(listItem);
|
34 |
+
}
|
35 |
+
} else {
|
36 |
+
// we have no template parts, remove the menu item for this page
|
37 |
+
document.querySelector("#wp-admin-bar-wtf-bar-template-parts").remove();
|
38 |
+
}
|
39 |
+
});
|
classes/class-nag.php
CHANGED
@@ -6,13 +6,11 @@ class WTF_Nag {
|
|
6 |
* Setup the class
|
7 |
*/
|
8 |
public function setup() {
|
9 |
-
|
10 |
// catch nag hide
|
11 |
$this->catch_hide_notice();
|
12 |
-
|
13 |
// bind nag
|
14 |
$this->bind();
|
15 |
-
|
16 |
}
|
17 |
|
18 |
/**
|
@@ -99,7 +97,7 @@ class WTF_Nag {
|
|
99 |
public static function insert_install_date() {
|
100 |
$datetime_now = new DateTime();
|
101 |
$date_string = $datetime_now->format( 'Y-m-d' );
|
102 |
-
add_site_option( WhatTheFile::OPTION_INSTALL_DATE, $date_string
|
103 |
|
104 |
return $date_string;
|
105 |
}
|
@@ -117,4 +115,4 @@ class WTF_Nag {
|
|
117 |
echo "</p></div>";
|
118 |
|
119 |
}
|
120 |
-
}
|
6 |
* Setup the class
|
7 |
*/
|
8 |
public function setup() {
|
|
|
9 |
// catch nag hide
|
10 |
$this->catch_hide_notice();
|
11 |
+
|
12 |
// bind nag
|
13 |
$this->bind();
|
|
|
14 |
}
|
15 |
|
16 |
/**
|
97 |
public static function insert_install_date() {
|
98 |
$datetime_now = new DateTime();
|
99 |
$date_string = $datetime_now->format( 'Y-m-d' );
|
100 |
+
add_site_option( WhatTheFile::OPTION_INSTALL_DATE, $date_string );
|
101 |
|
102 |
return $date_string;
|
103 |
}
|
115 |
echo "</p></div>";
|
116 |
|
117 |
}
|
118 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,9 @@ Contributors: never5, barrykooij
|
|
3 |
Donate link: http://www.barrykooij.com/donate/
|
4 |
Tags: toolbar, development, file, template, template editing, Template Hierarchy, theme, themes, php, php file, template part
|
5 |
Requires at least: 3.1
|
6 |
-
|
7 |
-
|
|
|
8 |
License: GPL v3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -12,10 +13,16 @@ What The File is the best tool to find out what template parts are used to displ
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
What The File adds an option to your toolbar showing what file and template parts are used to display the page you're currently viewing.
|
|
|
|
|
|
|
|
|
16 |
|
17 |
More information can be found <a href='http://www.barrykooij.com/what-the-file/'>here</a>.
|
18 |
-
|
|
|
|
|
19 |
|
20 |
== Installation ==
|
21 |
|
@@ -32,6 +39,10 @@ In the toolbar you will find the "What The File" option. Hovering this option wi
|
|
32 |
|
33 |
You have to be an Administrator to see the "What The File" option.
|
34 |
|
|
|
|
|
|
|
|
|
35 |
= Does What The File supports BuddyPress =
|
36 |
|
37 |
Yes it does.
|
@@ -50,6 +61,13 @@ Glad to hear I could help you! You can thank me in various ways, please see [my
|
|
50 |
|
51 |
== Changelog ==
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
= 1.5.4: October 8, 2017 =
|
54 |
* Version and meta update.
|
55 |
|
3 |
Donate link: http://www.barrykooij.com/donate/
|
4 |
Tags: toolbar, development, file, template, template editing, Template Hierarchy, theme, themes, php, php file, template part
|
5 |
Requires at least: 3.1
|
6 |
+
Requires PHP: 5.3
|
7 |
+
Tested up to: 6.0.2
|
8 |
+
Stable tag: 1.6.0
|
9 |
License: GPL v3
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
11 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
+
What The File adds an option to your toolbar showing what file and template parts are used to display the page you're currently viewing.
|
17 |
+
|
18 |
+
You can click the file name to directly edit it through the theme editor, though I don't recommend this for bigger changes.
|
19 |
+
|
20 |
+
What The File supports BuddyPress and Roots Theme based themes.
|
21 |
|
22 |
More information can be found <a href='http://www.barrykooij.com/what-the-file/'>here</a>.
|
23 |
+
|
24 |
+
= Looking for a great related posts plugin for WordPress? =
|
25 |
+
Another plugin I've built, that I'm very proud of is Related Posts for WordPress. Related Posts for WordPress offers you the ability to link related posts to each other with just 1 click! And it's 100% free! [Check it out on the WordPress repository.](https://wordpress.org/plugins/related-posts-for-wp/)
|
26 |
|
27 |
== Installation ==
|
28 |
|
39 |
|
40 |
You have to be an Administrator to see the "What The File" option.
|
41 |
|
42 |
+
= What PHP version are supported / tested? =
|
43 |
+
|
44 |
+
What The File works supports starts at PHP 5.3 and is tested on every major release up until PHP 8.1.
|
45 |
+
|
46 |
= Does What The File supports BuddyPress =
|
47 |
|
48 |
Yes it does.
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= 1.6.0: September 19, 2022 =
|
65 |
+
* Feature: Now correctly working with the wp_body_open tag. Full template part support is back.
|
66 |
+
* Tweak: Used proper add_site_option argument count. props @szepeviktor
|
67 |
+
* Tweak: Optimized file editing allowed function. props @szepeviktor
|
68 |
+
* Tweak: Change template_include priority from 1000 to PHP_INT_MAX for wider support. props @greenshady
|
69 |
+
* Tweak: Version and meta update.
|
70 |
+
|
71 |
= 1.5.4: October 8, 2017 =
|
72 |
* Version and meta update.
|
73 |
|
what-the-file.php
CHANGED
@@ -3,13 +3,14 @@
|
|
3 |
Plugin Name: What The File
|
4 |
Plugin URI: http://www.barrykooij.com/what-the-file/
|
5 |
Description: What The File adds an option to your toolbar showing what file and template parts are used to display the page you’re currently viewing. You can click the file name to directly edit it 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>.
|
6 |
-
Version: 1.
|
7 |
Author: Never5
|
8 |
Author URI: http://www.never5.com/
|
9 |
License: GPL v3
|
|
|
10 |
|
11 |
What The File Plugin
|
12 |
-
Copyright (C) 2012-
|
13 |
|
14 |
This program is free software: you can redistribute it and/or modify
|
15 |
it under the terms of the GNU General Public License as published by
|
@@ -30,6 +31,8 @@ class WhatTheFile {
|
|
30 |
const OPTION_INSTALL_DATE = 'whatthefile-install-date';
|
31 |
const OPTION_ADMIN_NOTICE_KEY = 'whatthefile-hide-notice';
|
32 |
|
|
|
|
|
33 |
/** @var string $template_name */
|
34 |
private $template_name = '';
|
35 |
|
@@ -56,7 +59,7 @@ class WhatTheFile {
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
*
|
60 |
*
|
61 |
* @return void
|
62 |
*/
|
@@ -64,7 +67,7 @@ class WhatTheFile {
|
|
64 |
|
65 |
// Check if user is an administrator
|
66 |
if ( ! current_user_can( 'manage_options' ) ) {
|
67 |
-
return
|
68 |
}
|
69 |
|
70 |
// include nag class
|
@@ -83,7 +86,7 @@ class WhatTheFile {
|
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
-
*
|
87 |
*
|
88 |
* @return void
|
89 |
*/
|
@@ -95,9 +98,12 @@ class WhatTheFile {
|
|
95 |
|
96 |
// WTF actions and filers
|
97 |
add_action( 'wp_head', array( $this, 'print_css' ) );
|
98 |
-
|
|
|
99 |
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
|
100 |
|
|
|
|
|
101 |
// BuddyPress support
|
102 |
if ( class_exists( 'BuddyPress' ) ) {
|
103 |
add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
|
@@ -125,7 +131,7 @@ class WhatTheFile {
|
|
125 |
* @return bool
|
126 |
*/
|
127 |
private function file_exists_in_child_theme( $file ) {
|
128 |
-
return file_exists(
|
129 |
}
|
130 |
|
131 |
/**
|
@@ -134,20 +140,15 @@ class WhatTheFile {
|
|
134 |
* @return bool
|
135 |
*/
|
136 |
private function is_file_editing_allowed() {
|
137 |
-
|
138 |
-
if ( ( defined( 'DISALLOW_FILE_EDIT' ) && true == DISALLOW_FILE_EDIT ) || ( defined( 'DISALLOW_FILE_MODS' ) && true == DISALLOW_FILE_MODS ) ) {
|
139 |
-
$allowed = false;
|
140 |
-
}
|
141 |
-
|
142 |
-
return $allowed;
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
* Save the template parts in our array
|
147 |
*
|
148 |
-
* @param $tag
|
149 |
-
* @param null $slug
|
150 |
-
* @param null $name
|
151 |
*/
|
152 |
public function save_template_parts( $tag, $slug = null, $name = null ) {
|
153 |
if ( 0 !== strpos( $tag, 'get_template_part_' ) ) {
|
@@ -247,36 +248,21 @@ class WhatTheFile {
|
|
247 |
'href' => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $this->get_current_page() . '&theme=' . $theme : false )
|
248 |
) );
|
249 |
|
250 |
-
//
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
'title' => 'Template Parts',
|
258 |
-
'href' => false
|
259 |
-
) );
|
260 |
-
|
261 |
-
// Loop through template parts
|
262 |
-
foreach ( $this->template_parts as $template_part ) {
|
263 |
-
|
264 |
-
// Check if template part exists in child theme
|
265 |
-
$theme = get_stylesheet();
|
266 |
-
if ( ! $this->file_exists_in_child_theme( $template_part ) ) {
|
267 |
-
$theme = get_template();
|
268 |
-
}
|
269 |
-
|
270 |
-
// Add template part to sub menu item
|
271 |
-
$wp_admin_bar->add_menu( array(
|
272 |
-
'id' => 'wtf-bar-template-part-' . $template_part,
|
273 |
-
'parent' => 'wtf-bar-template-parts',
|
274 |
-
'title' => $template_part,
|
275 |
-
'href' => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $template_part . '&theme=' . $theme : false )
|
276 |
-
) );
|
277 |
-
}
|
278 |
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
// Add powered by
|
282 |
$wp_admin_bar->add_menu( array(
|
@@ -292,7 +278,50 @@ class WhatTheFile {
|
|
292 |
* Print the custom CSS
|
293 |
*/
|
294 |
public function print_css() {
|
295 |
-
echo "<style type=\"text/css\" media=\"screen\">#wp-admin-bar-wtf-bar > .ab-item{padding-right:26px !important;background: url('" . plugins_url( 'assets/images/never5-logo.png', __FILE__ ) . "')center right no-repeat !important;} #wp-admin-bar-wtf-bar.hover > .ab-item {background-color: #32373c !important; } #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;} #wp-admin-bar-wtf-bar-template-parts.menupop > .ab-item:before{ right:auto !important; }#wp-admin-bar-wtf-bar-powered-by{text-align: right;}#wp-admin-bar-wtf-bar-powered-by a{color:#ffa100 !important;}</style>\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
}
|
297 |
|
298 |
}
|
3 |
Plugin Name: What The File
|
4 |
Plugin URI: http://www.barrykooij.com/what-the-file/
|
5 |
Description: What The File adds an option to your toolbar showing what file and template parts are used to display the page you’re currently viewing. You can click the file name to directly edit it 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>.
|
6 |
+
Version: 1.6.0
|
7 |
Author: Never5
|
8 |
Author URI: http://www.never5.com/
|
9 |
License: GPL v3
|
10 |
+
Requires PHP: 5.3
|
11 |
|
12 |
What The File Plugin
|
13 |
+
Copyright (C) 2012-2022, Never5 - www.never5.com
|
14 |
|
15 |
This program is free software: you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
31 |
const OPTION_INSTALL_DATE = 'whatthefile-install-date';
|
32 |
const OPTION_ADMIN_NOTICE_KEY = 'whatthefile-hide-notice';
|
33 |
|
34 |
+
CONST VERSION = '1.6.0';
|
35 |
+
|
36 |
/** @var string $template_name */
|
37 |
private $template_name = '';
|
38 |
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
+
* Set up the admin hooks
|
63 |
*
|
64 |
* @return void
|
65 |
*/
|
67 |
|
68 |
// Check if user is an administrator
|
69 |
if ( ! current_user_can( 'manage_options' ) ) {
|
70 |
+
return;
|
71 |
}
|
72 |
|
73 |
// include nag class
|
86 |
}
|
87 |
|
88 |
/**
|
89 |
+
* Set up the frontend hooks
|
90 |
*
|
91 |
* @return void
|
92 |
*/
|
98 |
|
99 |
// WTF actions and filers
|
100 |
add_action( 'wp_head', array( $this, 'print_css' ) );
|
101 |
+
add_action( 'wp_footer', array( $this, 'print_frontend_js' ), 50 );
|
102 |
+
add_filter( 'template_include', array( $this, 'save_current_page' ), PHP_INT_MAX );
|
103 |
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
|
104 |
|
105 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_script' ) );
|
106 |
+
|
107 |
// BuddyPress support
|
108 |
if ( class_exists( 'BuddyPress' ) ) {
|
109 |
add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
|
131 |
* @return bool
|
132 |
*/
|
133 |
private function file_exists_in_child_theme( $file ) {
|
134 |
+
return file_exists( get_stylesheet_directory() . '/' . $file );
|
135 |
}
|
136 |
|
137 |
/**
|
140 |
* @return bool
|
141 |
*/
|
142 |
private function is_file_editing_allowed() {
|
143 |
+
return ! ( ( defined( 'DISALLOW_FILE_EDIT' ) && true == DISALLOW_FILE_EDIT ) || ( defined( 'DISALLOW_FILE_MODS' ) && true == DISALLOW_FILE_MODS ) );
|
|
|
|
|
|
|
|
|
|
|
144 |
}
|
145 |
|
146 |
/**
|
147 |
* Save the template parts in our array
|
148 |
*
|
149 |
+
* @param string $tag
|
150 |
+
* @param string|null $slug
|
151 |
+
* @param string|null $name
|
152 |
*/
|
153 |
public function save_template_parts( $tag, $slug = null, $name = null ) {
|
154 |
if ( 0 !== strpos( $tag, 'get_template_part_' ) ) {
|
248 |
'href' => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $this->get_current_page() . '&theme=' . $theme : false )
|
249 |
) );
|
250 |
|
251 |
+
// Add template parts menu item
|
252 |
+
$wp_admin_bar->add_menu( array(
|
253 |
+
'id' => 'wtf-bar-template-parts',
|
254 |
+
'parent' => 'wtf-bar',
|
255 |
+
'title' => 'Template Parts',
|
256 |
+
'href' => false
|
257 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
|
259 |
+
// add a dummy child, we replace this via JS
|
260 |
+
$wp_admin_bar->add_menu( array(
|
261 |
+
'id' => 'wtf-bar-template-part-loading',
|
262 |
+
'parent' => 'wtf-bar-template-parts',
|
263 |
+
'title' => 'Loading...',
|
264 |
+
'href' => false
|
265 |
+
) );
|
266 |
|
267 |
// Add powered by
|
268 |
$wp_admin_bar->add_menu( array(
|
278 |
* Print the custom CSS
|
279 |
*/
|
280 |
public function print_css() {
|
281 |
+
echo "<style type=\"text/css\" media=\"screen\">#wp-admin-bar-wtf-bar > .ab-item{padding-right:26px !important;background: url('" . plugins_url( 'assets/images/never5-logo.png', __FILE__ ) . "')center right no-repeat !important;} #wp-admin-bar-wtf-bar.hover > .ab-item {background-color: #32373c !important; } #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;} #wp-admin-bar-wtf-bar-template-parts.menupop > .ab-item:before{ right:auto !important; }#wp-admin-bar-wtf-bar-powered-by{text-align: right;}#wp-admin-bar-wtf-bar-powered-by a{color:#ffa100 !important;} #wpadminbar .ab-top-secondary .menupop .menupop > .ab-item .wp-admin-bar-arrow:before {right: auto !important;}</style>\n";
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Enqueue frontend JS
|
286 |
+
*
|
287 |
+
* @return void
|
288 |
+
*/
|
289 |
+
public function enqueue_frontend_script() {
|
290 |
+
wp_enqueue_script( 'rp4wp-frontend-js', plugin_dir_url( __FILE__ ) . 'assets/js/what-the-file.js', array(), self::VERSION, true );
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* Print frontend JS
|
295 |
+
*
|
296 |
+
* @return void
|
297 |
+
*/
|
298 |
+
public function print_frontend_js() {
|
299 |
+
|
300 |
+
$edit_allowed = $this->is_file_editing_allowed();
|
301 |
+
|
302 |
+
$templates = array();
|
303 |
+
|
304 |
+
foreach ( $this->template_parts as $template_part ) {
|
305 |
+
|
306 |
+
// dedupe template parts
|
307 |
+
foreach ( $templates as $t ) {
|
308 |
+
if ( $t['file'] == $template_part ) {
|
309 |
+
continue 2;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
$theme = get_stylesheet();
|
314 |
+
if ( ! $this->file_exists_in_child_theme( $template_part ) ) {
|
315 |
+
$theme = get_template();
|
316 |
+
}
|
317 |
+
|
318 |
+
$templates[] = array(
|
319 |
+
"edit_url" => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $template_part . '&theme=' . $theme : false ),
|
320 |
+
"file" => $template_part
|
321 |
+
);
|
322 |
+
}
|
323 |
+
|
324 |
+
echo "<script type='text/javascript'>var wtf_templates = " . json_encode( $templates ) . ";</script>";
|
325 |
}
|
326 |
|
327 |
}
|