Version Description
- Fixed a template part bug, props remyvv
- Code style change
Download this release
Release Info
Developer | barrykooij |
Plugin | What The File |
Version | 1.4.0 |
Comparing to | |
See all releases |
Code changes from version 1.3.2 to 1.4.0
- readme.txt +7 -3
- what-the-file.php +42 -34
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== What The File ===
|
2 |
Contributors: barrykooij
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q7QDZTLCRKSMG
|
4 |
-
Tags: toolbar, development, file, template, template editing, Template Hierarchy, theme, themes, php, php file
|
5 |
Requires at least: 3.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPL v3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -46,6 +46,10 @@ Yes it does.
|
|
46 |
|
47 |
== Changelog ==
|
48 |
|
|
|
|
|
|
|
|
|
49 |
= 1.3.2 =
|
50 |
* Plugin now check if file exists in child theme or parent theme.
|
51 |
|
1 |
=== What The File ===
|
2 |
Contributors: barrykooij
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q7QDZTLCRKSMG
|
4 |
+
Tags: toolbar, development, file, template, template editing, Template Hierarchy, theme, themes, php, php file, template part
|
5 |
Requires at least: 3.1
|
6 |
+
Tested up to: 3.6.1
|
7 |
+
Stable tag: 1.4.0
|
8 |
License: GPL v3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
46 |
|
47 |
== Changelog ==
|
48 |
|
49 |
+
= 1.4.0 =
|
50 |
+
* Fixed a template part bug, props remyvv
|
51 |
+
* Code style change
|
52 |
+
|
53 |
= 1.3.2 =
|
54 |
* Plugin now check if file exists in child theme or parent theme.
|
55 |
|
what-the-file.php
CHANGED
@@ -3,7 +3,7 @@
|
|
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: Barry Kooij
|
8 |
Author URI: http://www.barrykooij.com/
|
9 |
License: GPL v3
|
@@ -32,26 +32,22 @@ class WhatTheFile
|
|
32 |
private $template_name = '';
|
33 |
private $template_parts = array();
|
34 |
|
35 |
-
public static function plugin_activation()
|
36 |
-
{
|
37 |
self::insert_install_date();
|
38 |
}
|
39 |
|
40 |
-
public function __construct()
|
41 |
-
{
|
42 |
$this->hooks();
|
43 |
}
|
44 |
|
45 |
-
private static function insert_install_date()
|
46 |
-
{
|
47 |
$datetime_now = new DateTime();
|
48 |
$date_string = $datetime_now->format('Y-m-d');
|
49 |
add_site_option( self::OPTION_INSTALL_DATE, $date_string, '', 'no' );
|
50 |
return $date_string;
|
51 |
}
|
52 |
|
53 |
-
private function get_install_date()
|
54 |
-
{
|
55 |
$date_string = get_site_option( self::OPTION_INSTALL_DATE, '' );
|
56 |
if( $date_string == '' ) {
|
57 |
// There is no install date, plugin was installed before version 1.2.0. Add it now.
|
@@ -60,19 +56,17 @@ class WhatTheFile
|
|
60 |
return new DateTime( $date_string );
|
61 |
}
|
62 |
|
63 |
-
private function get_current_page()
|
64 |
-
{
|
65 |
return $this->template_name;
|
66 |
}
|
67 |
|
68 |
-
private function get_admin_querystring_array()
|
69 |
-
{
|
70 |
parse_str( $_SERVER['QUERY_STRING'], $params );
|
71 |
return $params;
|
72 |
}
|
73 |
|
74 |
-
private function hooks()
|
75 |
-
|
76 |
// Check if user is an administrator
|
77 |
if( !current_user_can('manage_options') ) {
|
78 |
return false;
|
@@ -115,24 +109,39 @@ class WhatTheFile
|
|
115 |
add_action( 'all', array( $this, 'save_template_parts' ), 1, 3 );
|
116 |
}
|
117 |
|
118 |
-
private function file_exists_in_child_theme( $file )
|
119 |
-
{
|
120 |
return file_exists( STYLESHEETPATH . '/' . $file );
|
121 |
}
|
122 |
|
123 |
-
public function save_template_parts( $tag, $slug=null, $name=null )
|
124 |
-
{
|
125 |
if( 0 !== strpos( $tag, 'get_template_part_' ) ) {
|
126 |
return;
|
127 |
}
|
128 |
|
129 |
-
if
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
}
|
|
|
132 |
}
|
133 |
|
134 |
-
public function catch_hide_notice()
|
135 |
-
{
|
136 |
if( isset( $_GET[ self::OPTION_ADMIN_NOTICE_KEY ] ) && current_user_can( 'install_plugins' ) ) {
|
137 |
// Add user meta
|
138 |
global $current_user;
|
@@ -158,25 +167,26 @@ class WhatTheFile
|
|
158 |
}
|
159 |
}
|
160 |
|
161 |
-
public function display_admin_notice()
|
162 |
-
|
163 |
$query_params = $this->get_admin_querystring_array();
|
164 |
$query_string = '?' . http_build_query( array_merge( $query_params, array( self::OPTION_ADMIN_NOTICE_KEY => '1' ) ) );
|
165 |
|
166 |
echo '<div class="updated"><p>';
|
167 |
printf(__("You've been using <b>What The File</b> for some time now, could you please give it a review at wordpress.org? <br /><br /> <a href='%s' target='_blank'>Yes, take me there!</a> - <a href='%s'>I've already done this!</a>"), 'http://wordpress.org/support/view/plugin-reviews/what-the-file', $query_string );
|
168 |
echo "</p></div>";
|
|
|
169 |
}
|
170 |
|
171 |
-
public function save_buddy_press_template( $template )
|
172 |
-
|
173 |
if( $this->template_name == '' ) {
|
174 |
$this->template_name = str_ireplace( get_template_directory() . '/', '', $template );
|
175 |
}
|
|
|
176 |
}
|
177 |
|
178 |
-
public function save_current_page( $template_name )
|
179 |
-
{
|
180 |
$this->template_name = basename( $template_name );
|
181 |
|
182 |
// Do Roots Theme check
|
@@ -187,8 +197,7 @@ class WhatTheFile
|
|
187 |
return $template_name;
|
188 |
}
|
189 |
|
190 |
-
public function admin_bar_menu()
|
191 |
-
{
|
192 |
global $wp_admin_bar;
|
193 |
|
194 |
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar', 'parent' => 'top-secondary', 'title' => __( 'What The File', 'what-the-file' ) , 'href' => false ) );
|
@@ -218,12 +227,11 @@ class WhatTheFile
|
|
218 |
}
|
219 |
}
|
220 |
|
221 |
-
public function print_css()
|
222 |
-
{
|
223 |
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";
|
224 |
}
|
225 |
|
226 |
}
|
227 |
|
228 |
add_action( 'plugins_loaded', create_function( '', 'new WhatTheFile();' ) );
|
229 |
-
register_activation_hook( __FILE__, array( 'WhatTheFile', 'plugin_activation' ) );
|
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.4.0
|
7 |
Author: Barry Kooij
|
8 |
Author URI: http://www.barrykooij.com/
|
9 |
License: GPL v3
|
32 |
private $template_name = '';
|
33 |
private $template_parts = array();
|
34 |
|
35 |
+
public static function plugin_activation() {
|
|
|
36 |
self::insert_install_date();
|
37 |
}
|
38 |
|
39 |
+
public function __construct() {
|
|
|
40 |
$this->hooks();
|
41 |
}
|
42 |
|
43 |
+
private static function insert_install_date() {
|
|
|
44 |
$datetime_now = new DateTime();
|
45 |
$date_string = $datetime_now->format('Y-m-d');
|
46 |
add_site_option( self::OPTION_INSTALL_DATE, $date_string, '', 'no' );
|
47 |
return $date_string;
|
48 |
}
|
49 |
|
50 |
+
private function get_install_date() {
|
|
|
51 |
$date_string = get_site_option( self::OPTION_INSTALL_DATE, '' );
|
52 |
if( $date_string == '' ) {
|
53 |
// There is no install date, plugin was installed before version 1.2.0. Add it now.
|
56 |
return new DateTime( $date_string );
|
57 |
}
|
58 |
|
59 |
+
private function get_current_page() {
|
|
|
60 |
return $this->template_name;
|
61 |
}
|
62 |
|
63 |
+
private function get_admin_querystring_array() {
|
|
|
64 |
parse_str( $_SERVER['QUERY_STRING'], $params );
|
65 |
return $params;
|
66 |
}
|
67 |
|
68 |
+
private function hooks() {
|
69 |
+
|
70 |
// Check if user is an administrator
|
71 |
if( !current_user_can('manage_options') ) {
|
72 |
return false;
|
109 |
add_action( 'all', array( $this, 'save_template_parts' ), 1, 3 );
|
110 |
}
|
111 |
|
112 |
+
private function file_exists_in_child_theme( $file ) {
|
|
|
113 |
return file_exists( STYLESHEETPATH . '/' . $file );
|
114 |
}
|
115 |
|
116 |
+
public function save_template_parts( $tag, $slug=null, $name=null ) {
|
|
|
117 |
if( 0 !== strpos( $tag, 'get_template_part_' ) ) {
|
118 |
return;
|
119 |
}
|
120 |
|
121 |
+
// Check if slug is set
|
122 |
+
if( $slug != null ) {
|
123 |
+
|
124 |
+
// Templates array
|
125 |
+
$templates = array();
|
126 |
+
|
127 |
+
// Add possible template part to array
|
128 |
+
if($name != null)
|
129 |
+
$templates[] = "{$slug}-{$name}.php";
|
130 |
+
|
131 |
+
// Add possible template part to array
|
132 |
+
$templates[] = "{$slug}.php";
|
133 |
+
|
134 |
+
// Get the correct template part
|
135 |
+
$template_part = str_replace( get_template_directory().'/', '', locate_template( $templates ) );
|
136 |
+
|
137 |
+
// Add template part if found
|
138 |
+
if( $template_part != '' )
|
139 |
+
$this->template_parts[] = $template_part;
|
140 |
}
|
141 |
+
|
142 |
}
|
143 |
|
144 |
+
public function catch_hide_notice() {
|
|
|
145 |
if( isset( $_GET[ self::OPTION_ADMIN_NOTICE_KEY ] ) && current_user_can( 'install_plugins' ) ) {
|
146 |
// Add user meta
|
147 |
global $current_user;
|
167 |
}
|
168 |
}
|
169 |
|
170 |
+
public function display_admin_notice() {
|
171 |
+
|
172 |
$query_params = $this->get_admin_querystring_array();
|
173 |
$query_string = '?' . http_build_query( array_merge( $query_params, array( self::OPTION_ADMIN_NOTICE_KEY => '1' ) ) );
|
174 |
|
175 |
echo '<div class="updated"><p>';
|
176 |
printf(__("You've been using <b>What The File</b> for some time now, could you please give it a review at wordpress.org? <br /><br /> <a href='%s' target='_blank'>Yes, take me there!</a> - <a href='%s'>I've already done this!</a>"), 'http://wordpress.org/support/view/plugin-reviews/what-the-file', $query_string );
|
177 |
echo "</p></div>";
|
178 |
+
|
179 |
}
|
180 |
|
181 |
+
public function save_buddy_press_template( $template ) {
|
182 |
+
|
183 |
if( $this->template_name == '' ) {
|
184 |
$this->template_name = str_ireplace( get_template_directory() . '/', '', $template );
|
185 |
}
|
186 |
+
|
187 |
}
|
188 |
|
189 |
+
public function save_current_page( $template_name ) {
|
|
|
190 |
$this->template_name = basename( $template_name );
|
191 |
|
192 |
// Do Roots Theme check
|
197 |
return $template_name;
|
198 |
}
|
199 |
|
200 |
+
public function admin_bar_menu() {
|
|
|
201 |
global $wp_admin_bar;
|
202 |
|
203 |
$wp_admin_bar->add_menu( array( 'id' => 'wtf-bar', 'parent' => 'top-secondary', 'title' => __( 'What The File', 'what-the-file' ) , 'href' => false ) );
|
227 |
}
|
228 |
}
|
229 |
|
230 |
+
public function print_css() {
|
|
|
231 |
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";
|
232 |
}
|
233 |
|
234 |
}
|
235 |
|
236 |
add_action( 'plugins_loaded', create_function( '', 'new WhatTheFile();' ) );
|
237 |
+
register_activation_hook( __FILE__, array( 'WhatTheFile', 'plugin_activation' ) );
|