What The File - Version 1.4.1

Version Description

  • Fixed wrongly aligned arrow in MP6 - props remyvv.
  • Template parts are now correctly shown in child themes - props remyvv.
  • Code style change.
Download this release

Release Info

Developer barrykooij
Plugin Icon 128x128 What The File
Version 1.4.1
Comparing to
See all releases

Code changes from version 1.4.0 to 1.4.1

Files changed (2) hide show
  1. readme.txt +7 -2
  2. what-the-file.php +50 -41
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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,6 +46,11 @@ Yes it does.
46
 
47
  == Changelog ==
48
 
 
 
 
 
 
49
  = 1.4.0 =
50
  * Fixed a template part bug, props remyvv
51
  * Code style change
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.8.1
7
+ Stable tag: 1.4.1
8
  License: GPL v3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
46
 
47
  == Changelog ==
48
 
49
+ = 1.4.1 =
50
+ * Fixed wrongly aligned arrow in MP6 - props [remyvv](https://github.com/remyvv).
51
+ * Template parts are now correctly shown in child themes - props [remyvv](https://github.com/remyvv).
52
+ * Code style change.
53
+
54
  = 1.4.0 =
55
  * Fixed a template part bug, props remyvv
56
  * Code style change
what-the-file.php CHANGED
@@ -1,9 +1,10 @@
1
  <?php
 
2
  /*
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
@@ -25,12 +26,11 @@
25
  along with this program. If not, see <http://www.gnu.org/licenses/>.
26
  */
27
 
28
- class WhatTheFile
29
- {
30
- const OPTION_INSTALL_DATE = 'whatthefile-install-date';
31
- const OPTION_ADMIN_NOTICE_KEY = 'whatthefile-hide-notice';
32
- private $template_name = '';
33
- private $template_parts = array();
34
 
35
  public static function plugin_activation() {
36
  self::insert_install_date();
@@ -42,17 +42,19 @@ class WhatTheFile
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.
54
  $date_string = self::insert_install_date();
55
  }
 
56
  return new DateTime( $date_string );
57
  }
58
 
@@ -62,13 +64,14 @@ class WhatTheFile
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;
73
  }
74
 
@@ -77,31 +80,31 @@ class WhatTheFile
77
 
78
  // Is admin notice hidden?
79
  $current_user = wp_get_current_user();
80
- $hide_notice = get_user_meta( $current_user->ID, self::OPTION_ADMIN_NOTICE_KEY, true );
81
 
82
- if( current_user_can( 'install_plugins' ) && $hide_notice == '' ) {
83
  // Get installation date
84
  $datetime_install = $this->get_install_date();
85
- $datetime_past = new DateTime( '-10 days' );
86
 
87
- if( $datetime_past >= $datetime_install ) {
88
  // 10 or more days ago, show admin notice
89
  add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
90
  }
91
  }
92
 
93
  // Don't add admin bar option in admin panel
94
- if( is_admin() || !is_admin_bar_showing() ) {
95
  return;
96
  }
97
 
98
  // WTF actions and filers
99
- add_action( 'wp_head' , array( $this, 'print_css' ) );
100
- add_filter( 'template_include' , array( $this, 'save_current_page' ), 1000 );
101
- add_action( 'admin_bar_menu' , array( $this, 'admin_bar_menu' ), 1000 );
102
 
103
  // BuddyPress hook
104
- if( class_exists( 'BuddyPress' ) ) {
105
  add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
106
  }
107
 
@@ -113,53 +116,56 @@ class WhatTheFile
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;
148
  add_user_meta( $current_user->ID, self::OPTION_ADMIN_NOTICE_KEY, '1', true );
149
 
150
  // Build redirect URL
151
  $query_params = $this->get_admin_querystring_array();
152
- unset( $query_params[ self::OPTION_ADMIN_NOTICE_KEY ] );
153
  $query_string = http_build_query( $query_params );
154
- if( $query_string != '' ) {
155
  $query_string = '?' . $query_string;
156
  }
157
 
158
  $redirect_url = 'http';
159
- if( isset( $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] == 'on' ) {
160
  $redirect_url .= 's';
161
  }
162
- $redirect_url .= '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'PHP_SELF' ] . $query_string;
163
 
164
  // Redirect
165
  wp_redirect( $redirect_url );
@@ -173,15 +179,18 @@ class WhatTheFile
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
  }
@@ -190,7 +199,7 @@ class WhatTheFile
190
  $this->template_name = basename( $template_name );
191
 
192
  // Do Roots Theme check
193
- if( function_exists( 'roots_template_path' ) ) {
194
  $this->template_name = basename( roots_template_path() );
195
  }
196
 
@@ -200,24 +209,24 @@ class WhatTheFile
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 ) );
204
 
205
  // Check if template file exists in child theme
206
  $theme = get_stylesheet();
207
- if( !$this->file_exists_in_child_theme( $this->get_current_page() ) ) {
208
  $theme = get_template();
209
  }
210
 
211
  $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=' . $theme ) );
212
 
213
- if( count( $this->template_parts ) > 0 ) {
214
  $wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-template-parts', 'parent' => 'wtf-bar', 'title' => 'Template Parts', 'href' => false ) );
215
 
216
- foreach( $this->template_parts as $template_part ) {
217
 
218
  // Check if template part exists in child theme
219
  $theme = get_stylesheet();
220
- if( !$this->file_exists_in_child_theme( $template_part ) ) {
221
  $theme = get_template();
222
  }
223
 
@@ -228,7 +237,7 @@ class WhatTheFile
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
  }
1
  <?php
2
+
3
  /*
4
  Plugin Name: What The File
5
  Plugin URI: http://www.barrykooij.com/what-the-file/
6
  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>.
7
+ Version: 1.4.1
8
  Author: Barry Kooij
9
  Author URI: http://www.barrykooij.com/
10
  License: GPL v3
26
  along with this program. If not, see <http://www.gnu.org/licenses/>.
27
  */
28
 
29
+ class WhatTheFile {
30
+ const OPTION_INSTALL_DATE = 'whatthefile-install-date';
31
+ const OPTION_ADMIN_NOTICE_KEY = 'whatthefile-hide-notice';
32
+ private $template_name = '';
33
+ private $template_parts = array();
 
34
 
35
  public static function plugin_activation() {
36
  self::insert_install_date();
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
+
48
  return $date_string;
49
  }
50
 
51
  private function get_install_date() {
52
+ $date_string = get_site_option( self::OPTION_INSTALL_DATE, '' );
53
+ if ( $date_string == '' ) {
54
  // There is no install date, plugin was installed before version 1.2.0. Add it now.
55
  $date_string = self::insert_install_date();
56
  }
57
+
58
  return new DateTime( $date_string );
59
  }
60
 
64
 
65
  private function get_admin_querystring_array() {
66
  parse_str( $_SERVER['QUERY_STRING'], $params );
67
+
68
  return $params;
69
  }
70
 
71
  private function hooks() {
72
 
73
  // Check if user is an administrator
74
+ if ( ! current_user_can( 'manage_options' ) ) {
75
  return false;
76
  }
77
 
80
 
81
  // Is admin notice hidden?
82
  $current_user = wp_get_current_user();
83
+ $hide_notice = get_user_meta( $current_user->ID, self::OPTION_ADMIN_NOTICE_KEY, true );
84
 
85
+ if ( current_user_can( 'install_plugins' ) && $hide_notice == '' ) {
86
  // Get installation date
87
  $datetime_install = $this->get_install_date();
88
+ $datetime_past = new DateTime( '-10 days' );
89
 
90
+ if ( $datetime_past >= $datetime_install ) {
91
  // 10 or more days ago, show admin notice
92
  add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
93
  }
94
  }
95
 
96
  // Don't add admin bar option in admin panel
97
+ if ( is_admin() || ! is_admin_bar_showing() ) {
98
  return;
99
  }
100
 
101
  // WTF actions and filers
102
+ add_action( 'wp_head', array( $this, 'print_css' ) );
103
+ add_filter( 'template_include', array( $this, 'save_current_page' ), 1000 );
104
+ add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
105
 
106
  // BuddyPress hook
107
+ if ( class_exists( 'BuddyPress' ) ) {
108
  add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
109
  }
110
 
116
  return file_exists( STYLESHEETPATH . '/' . $file );
117
  }
118
 
119
+ public function save_template_parts( $tag, $slug = null, $name = null ) {
120
+ if ( 0 !== strpos( $tag, 'get_template_part_' ) ) {
121
  return;
122
  }
123
 
124
  // Check if slug is set
125
+ if ( $slug != null ) {
126
 
127
  // Templates array
128
  $templates = array();
129
 
130
  // Add possible template part to array
131
+ if ( $name != null ) {
132
  $templates[] = "{$slug}-{$name}.php";
133
+ }
134
 
135
  // Add possible template part to array
136
  $templates[] = "{$slug}.php";
137
 
138
  // Get the correct template part
139
+ $template_part = str_replace( get_template_directory() . '/', '', locate_template( $templates ) );
140
+ $template_part = str_replace( get_stylesheet_directory() . '/', '', $template_part );
141
 
142
  // Add template part if found
143
+ if ( $template_part != '' ) {
144
  $this->template_parts[] = $template_part;
145
+ }
146
  }
147
 
148
  }
149
 
150
  public function catch_hide_notice() {
151
+ if ( isset( $_GET[self::OPTION_ADMIN_NOTICE_KEY] ) && current_user_can( 'install_plugins' ) ) {
152
  // Add user meta
153
  global $current_user;
154
  add_user_meta( $current_user->ID, self::OPTION_ADMIN_NOTICE_KEY, '1', true );
155
 
156
  // Build redirect URL
157
  $query_params = $this->get_admin_querystring_array();
158
+ unset( $query_params[self::OPTION_ADMIN_NOTICE_KEY] );
159
  $query_string = http_build_query( $query_params );
160
+ if ( $query_string != '' ) {
161
  $query_string = '?' . $query_string;
162
  }
163
 
164
  $redirect_url = 'http';
165
+ if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) {
166
  $redirect_url .= 's';
167
  }
168
+ $redirect_url .= '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $query_string;
169
 
170
  // Redirect
171
  wp_redirect( $redirect_url );
179
  $query_string = '?' . http_build_query( array_merge( $query_params, array( self::OPTION_ADMIN_NOTICE_KEY => '1' ) ) );
180
 
181
  echo '<div class="updated"><p>';
182
+ 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 );
183
  echo "</p></div>";
184
 
185
  }
186
 
187
  public function save_buddy_press_template( $template ) {
188
 
189
+ if ( $this->template_name == '' ) {
190
+ $template_name = $template;
191
+ $template_name = str_ireplace( get_template_directory() . '/', '', $template_name );
192
+ $template_name = str_ireplace( get_stylesheet_directory() . '/', '', $template_name );
193
+ $this->template_name = $template_name;
194
  }
195
 
196
  }
199
  $this->template_name = basename( $template_name );
200
 
201
  // Do Roots Theme check
202
+ if ( function_exists( 'roots_template_path' ) ) {
203
  $this->template_name = basename( roots_template_path() );
204
  }
205
 
209
  public function admin_bar_menu() {
210
  global $wp_admin_bar;
211
 
212
+ $wp_admin_bar->add_menu( array( 'id' => 'wtf-bar', 'parent' => 'top-secondary', 'title' => __( 'What The File', 'what-the-file' ), 'href' => false ) );
213
 
214
  // Check if template file exists in child theme
215
  $theme = get_stylesheet();
216
+ if ( ! $this->file_exists_in_child_theme( $this->get_current_page() ) ) {
217
  $theme = get_template();
218
  }
219
 
220
  $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=' . $theme ) );
221
 
222
+ if ( count( $this->template_parts ) > 0 ) {
223
  $wp_admin_bar->add_menu( array( 'id' => 'wtf-bar-template-parts', 'parent' => 'wtf-bar', 'title' => 'Template Parts', 'href' => false ) );
224
 
225
+ foreach ( $this->template_parts as $template_part ) {
226
 
227
  // Check if template part exists in child theme
228
  $theme = get_stylesheet();
229
+ if ( ! $this->file_exists_in_child_theme( $template_part ) ) {
230
  $theme = get_template();
231
  }
232
 
237
  }
238
 
239
  public function print_css() {
240
+ 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;} #wp-admin-bar-wtf-bar-template-parts.menupop > .ab-item:before{ right:auto !important; }</style>\n";
241
  }
242
 
243
  }