Version Description
- Only add edit link if direct file editing is allowed. Props szepeviktor
- Wrapped initiation in hooks and split frontend and admin code.
- Removed use of create_function.
- Various code optimizations.
Download this release
Release Info
Developer | barrykooij |
Plugin | What The File |
Version | 1.5.0 |
Comparing to | |
See all releases |
Code changes from version 1.4.1 to 1.5.0
- assets/images/never5-logo.png +0 -0
- classes/class-nag.php +120 -0
- classes/class-plugin-links.php +24 -0
- readme.txt +16 -6
- what-the-file.php +163 -100
assets/images/never5-logo.png
ADDED
Binary file
|
classes/class-nag.php
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WTF_Nag {
|
4 |
+
|
5 |
+
/**
|
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 |
+
/**
|
19 |
+
* Catch the hide nag request
|
20 |
+
*/
|
21 |
+
private function catch_hide_notice() {
|
22 |
+
if ( isset( $_GET[ WhatTheFile::OPTION_ADMIN_NOTICE_KEY ] ) && current_user_can( 'install_plugins' ) ) {
|
23 |
+
// Add user meta
|
24 |
+
global $current_user;
|
25 |
+
add_user_meta( $current_user->ID, WhatTheFile::OPTION_ADMIN_NOTICE_KEY, '1', true );
|
26 |
+
|
27 |
+
// Build redirect URL
|
28 |
+
$query_params = $this->get_admin_querystring_array();
|
29 |
+
unset( $query_params[ WhatTheFile::OPTION_ADMIN_NOTICE_KEY ] );
|
30 |
+
$query_string = http_build_query( $query_params );
|
31 |
+
if ( $query_string != '' ) {
|
32 |
+
$query_string = '?' . $query_string;
|
33 |
+
}
|
34 |
+
|
35 |
+
$redirect_url = 'http';
|
36 |
+
if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) {
|
37 |
+
$redirect_url .= 's';
|
38 |
+
}
|
39 |
+
$redirect_url .= '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $query_string;
|
40 |
+
|
41 |
+
// Redirect
|
42 |
+
wp_redirect( $redirect_url );
|
43 |
+
exit;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Bind nag message
|
49 |
+
*/
|
50 |
+
private function bind() {
|
51 |
+
// Is admin notice hidden?
|
52 |
+
$current_user = wp_get_current_user();
|
53 |
+
$hide_notice = get_user_meta( $current_user->ID, WhatTheFile::OPTION_ADMIN_NOTICE_KEY, true );
|
54 |
+
|
55 |
+
// Check if we need to display the notice
|
56 |
+
if ( current_user_can( 'install_plugins' ) && '' == $hide_notice ) {
|
57 |
+
// Get installation date
|
58 |
+
$datetime_install = $this->get_install_date();
|
59 |
+
$datetime_past = new DateTime( '-10 days' );
|
60 |
+
|
61 |
+
if ( $datetime_past >= $datetime_install ) {
|
62 |
+
// 10 or more days ago, show admin notice
|
63 |
+
add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Get the install data
|
70 |
+
*
|
71 |
+
* @return DateTime
|
72 |
+
*/
|
73 |
+
private function get_install_date() {
|
74 |
+
$date_string = get_site_option( WhatTheFile::OPTION_INSTALL_DATE, '' );
|
75 |
+
if ( $date_string == '' ) {
|
76 |
+
// There is no install date, plugin was installed before version 1.2.0. Add it now.
|
77 |
+
$date_string = self::insert_install_date();
|
78 |
+
}
|
79 |
+
|
80 |
+
return new DateTime( $date_string );
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Parse the admin query string
|
85 |
+
*
|
86 |
+
* @return array
|
87 |
+
*/
|
88 |
+
private function get_admin_querystring_array() {
|
89 |
+
parse_str( $_SERVER['QUERY_STRING'], $params );
|
90 |
+
|
91 |
+
return $params;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Insert the install date
|
96 |
+
*
|
97 |
+
* @return string
|
98 |
+
*/
|
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, '', 'no' );
|
103 |
+
|
104 |
+
return $date_string;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Display the admin notice
|
109 |
+
*/
|
110 |
+
public function display_admin_notice() {
|
111 |
+
|
112 |
+
$query_params = $this->get_admin_querystring_array();
|
113 |
+
$query_string = '?' . http_build_query( array_merge( $query_params, array( WhatTheFile::OPTION_ADMIN_NOTICE_KEY => '1' ) ) );
|
114 |
+
|
115 |
+
echo '<div class="updated"><p>';
|
116 |
+
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><br/><br/><small><a href='http://www.never5.com/' target='_blank'>Check out other Never5 plugins</a></small>" ), 'http://wordpress.org/support/view/plugin-reviews/what-the-file', $query_string );
|
117 |
+
echo "</p></div>";
|
118 |
+
|
119 |
+
}
|
120 |
+
}
|
classes/class-plugin-links.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WTF_Plugin_Links {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Setup class
|
7 |
+
*/
|
8 |
+
public function setup() {
|
9 |
+
add_filter( 'plugin_action_links_what-the-file/what-the-file.php', array( $this, 'add_links' ) );
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Add to links
|
14 |
+
*
|
15 |
+
* @param array $links
|
16 |
+
*
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
+
public function add_links( $links ) {
|
20 |
+
array_unshift( $links, '<a href="http://www.never5.com/?utm_source=plugin&utm_medium=link&utm_campaign=what-the-file" target="_blank" style="color:#ffa100;font-weight:bold;">' . __( 'More Never5 Plugins', 'what-the-file' ) . '</a>' );
|
21 |
+
return $links;
|
22 |
+
}
|
23 |
+
|
24 |
+
}
|
readme.txt
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
=== What The File ===
|
2 |
-
Contributors: barrykooij
|
3 |
-
Donate link:
|
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
|
7 |
-
Stable tag: 1.
|
8 |
License: GPL v3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
-
What The File
|
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
|
16 |
|
17 |
More information can be found <a href='http://www.barrykooij.com/what-the-file/'>here</a>.
|
18 |
For support please visit the <a href='http://wordpress.org/support/plugin/what-the-file'>Support forum</a>.
|
@@ -40,12 +40,22 @@ Yes it does.
|
|
40 |
|
41 |
Yes it does.
|
42 |
|
|
|
|
|
|
|
|
|
43 |
== Screenshots ==
|
44 |
|
45 |
1. What The File shows you what template file is used.
|
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).
|
1 |
=== What The File ===
|
2 |
+
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 |
+
Tested up to: 4.3
|
7 |
+
Stable tag: 1.5.0
|
8 |
License: GPL v3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
+
What The File is the best tool to find out what template parts are used to display the page you're currently viewing!
|
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. You can click the file name to directly edit it through the theme editor, though I don't recommend this for bigger changes. What The File supports BuddyPress and Roots Theme based themes.
|
16 |
|
17 |
More information can be found <a href='http://www.barrykooij.com/what-the-file/'>here</a>.
|
18 |
For support please visit the <a href='http://wordpress.org/support/plugin/what-the-file'>Support forum</a>.
|
40 |
|
41 |
Yes it does.
|
42 |
|
43 |
+
= You saved me so much time, is there any way I can thank you? =
|
44 |
+
|
45 |
+
Glad to hear I could help you! You can thank me in various ways, please see [my donation page](http://www.barrykooij.com/donate/) to find out more.
|
46 |
+
|
47 |
== Screenshots ==
|
48 |
|
49 |
1. What The File shows you what template file is used.
|
50 |
|
51 |
== Changelog ==
|
52 |
|
53 |
+
= 1.5.0 =
|
54 |
+
* Only add edit link if direct file editing is allowed. Props szepeviktor
|
55 |
+
* Wrapped initiation in hooks and split frontend and admin code.
|
56 |
+
* Removed use of create_function.
|
57 |
+
* Various code optimizations.
|
58 |
+
|
59 |
= 1.4.1 =
|
60 |
* Fixed wrongly aligned arrow in MP6 - props [remyvv](https://github.com/remyvv).
|
61 |
* Template parts are now correctly shown in child themes - props [remyvv](https://github.com/remyvv).
|
what-the-file.php
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/*
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
License: GPL v3
|
11 |
|
12 |
What The File Plugin
|
13 |
-
Copyright (C) 2012-
|
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
|
@@ -27,73 +26,69 @@
|
|
27 |
*/
|
28 |
|
29 |
class WhatTheFile {
|
30 |
-
|
|
|
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 |
-
|
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 |
-
|
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 |
-
|
|
|
59 |
}
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
return $params;
|
69 |
}
|
70 |
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
// Check if user is an administrator
|
74 |
if ( ! current_user_can( 'manage_options' ) ) {
|
75 |
return false;
|
76 |
}
|
77 |
|
78 |
-
//
|
79 |
-
|
80 |
|
81 |
-
//
|
82 |
-
$
|
83 |
-
$
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
$datetime_install = $this->get_install_date();
|
88 |
-
$datetime_past = new DateTime( '-10 days' );
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
}
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
if ( is_admin() || ! is_admin_bar_showing() ) {
|
98 |
return;
|
99 |
}
|
@@ -103,7 +98,7 @@ class WhatTheFile {
|
|
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
|
107 |
if ( class_exists( 'BuddyPress' ) ) {
|
108 |
add_action( 'bp_core_pre_load_template', array( $this, 'save_buddy_press_template' ) );
|
109 |
}
|
@@ -112,10 +107,48 @@ class WhatTheFile {
|
|
112 |
add_action( 'all', array( $this, 'save_template_parts' ), 1, 3 );
|
113 |
}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
private function file_exists_in_child_theme( $file ) {
|
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;
|
@@ -147,46 +180,14 @@ class WhatTheFile {
|
|
147 |
|
148 |
}
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
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 );
|
172 |
-
exit;
|
173 |
-
}
|
174 |
-
}
|
175 |
-
|
176 |
-
public function display_admin_notice() {
|
177 |
-
|
178 |
-
$query_params = $this->get_admin_querystring_array();
|
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 );
|
@@ -195,6 +196,13 @@ class WhatTheFile {
|
|
195 |
|
196 |
}
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
public function save_current_page( $template_name ) {
|
199 |
$this->template_name = basename( $template_name );
|
200 |
|
@@ -206,10 +214,22 @@ class WhatTheFile {
|
|
206 |
return $template_name;
|
207 |
}
|
208 |
|
|
|
|
|
|
|
209 |
public function admin_bar_menu() {
|
210 |
global $wp_admin_bar;
|
211 |
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
// Check if template file exists in child theme
|
215 |
$theme = get_stylesheet();
|
@@ -217,11 +237,26 @@ class WhatTheFile {
|
|
217 |
$theme = get_template();
|
218 |
}
|
219 |
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
@@ -230,17 +265,45 @@ class WhatTheFile {
|
|
230 |
$theme = get_template();
|
231 |
}
|
232 |
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
|
236 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
244 |
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
register_activation_hook( __FILE__, array( 'WhatTheFile', 'plugin_activation' ) );
|
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.5.0
|
7 |
+
Author: Never5
|
8 |
+
Author URI: http://www.never5.com/
|
9 |
License: GPL v3
|
10 |
|
11 |
What The File Plugin
|
12 |
+
Copyright (C) 2012-2015, Never5 - www.never5.com
|
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
|
26 |
*/
|
27 |
|
28 |
class WhatTheFile {
|
29 |
+
|
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 |
+
|
36 |
+
/** @var array $template_parts */
|
37 |
private $template_parts = array();
|
38 |
|
39 |
+
/**
|
40 |
+
* Method run on plugin activation
|
41 |
+
*/
|
42 |
public static function plugin_activation() {
|
43 |
+
// include nag class
|
44 |
+
require_once( plugin_dir_path( __FILE__ ) . '/classes/class-nag.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
// insert install date
|
47 |
+
WTF_Nag::insert_install_date();
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* Constructor
|
52 |
+
*/
|
53 |
+
public function __construct() {
|
54 |
+
add_action( 'init', array( $this, 'frontend_hooks' ) );
|
55 |
+
add_action( 'admin_init', array( $this, 'admin_hooks' ) );
|
|
|
|
|
56 |
}
|
57 |
|
58 |
+
/**
|
59 |
+
* Setup the admin hooks
|
60 |
+
*
|
61 |
+
* @return void
|
62 |
+
*/
|
63 |
+
public function admin_hooks() {
|
64 |
|
65 |
// Check if user is an administrator
|
66 |
if ( ! current_user_can( 'manage_options' ) ) {
|
67 |
return false;
|
68 |
}
|
69 |
|
70 |
+
// include nag class
|
71 |
+
require_once( plugin_dir_path( __FILE__ ) . '/classes/class-nag.php' );
|
72 |
|
73 |
+
// setup nag
|
74 |
+
$nag = new WTF_Nag();
|
75 |
+
$nag->setup();
|
76 |
|
77 |
+
// include plugin links class
|
78 |
+
require_once( plugin_dir_path( __FILE__ ) . '/classes/class-plugin-links.php' );
|
|
|
|
|
79 |
|
80 |
+
// setup plugin links
|
81 |
+
$plugin_links = new WTF_Plugin_Links();
|
82 |
+
$plugin_links->setup();
|
83 |
+
}
|
|
|
84 |
|
85 |
+
/**
|
86 |
+
* Setup the frontend hooks
|
87 |
+
*
|
88 |
+
* @return void
|
89 |
+
*/
|
90 |
+
public function frontend_hooks() {
|
91 |
+
// Don't run in admin or if the admin bar isn't showing
|
92 |
if ( is_admin() || ! is_admin_bar_showing() ) {
|
93 |
return;
|
94 |
}
|
98 |
add_filter( 'template_include', array( $this, 'save_current_page' ), 1000 );
|
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' ) );
|
104 |
}
|
107 |
add_action( 'all', array( $this, 'save_template_parts' ), 1, 3 );
|
108 |
}
|
109 |
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Get the current page
|
113 |
+
*
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
private function get_current_page() {
|
117 |
+
return $this->template_name;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Check if file exists in child theme
|
122 |
+
*
|
123 |
+
* @param $file
|
124 |
+
*
|
125 |
+
* @return bool
|
126 |
+
*/
|
127 |
private function file_exists_in_child_theme( $file ) {
|
128 |
return file_exists( STYLESHEETPATH . '/' . $file );
|
129 |
}
|
130 |
|
131 |
+
/**
|
132 |
+
* Returns if direct file editing through WordPress is allowed
|
133 |
+
*
|
134 |
+
* @return bool
|
135 |
+
*/
|
136 |
+
private function is_file_editing_allowed() {
|
137 |
+
$allowed = true;
|
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_' ) ) {
|
154 |
return;
|
180 |
|
181 |
}
|
182 |
|
183 |
+
/**
|
184 |
+
* Save the BuddyPress template
|
185 |
+
*
|
186 |
+
* @param $template
|
187 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
public function save_buddy_press_template( $template ) {
|
189 |
|
190 |
+
if ( '' == $this->template_name ) {
|
191 |
$template_name = $template;
|
192 |
$template_name = str_ireplace( get_template_directory() . '/', '', $template_name );
|
193 |
$template_name = str_ireplace( get_stylesheet_directory() . '/', '', $template_name );
|
196 |
|
197 |
}
|
198 |
|
199 |
+
/**
|
200 |
+
* Save the current page in our local var
|
201 |
+
*
|
202 |
+
* @param $template_name
|
203 |
+
*
|
204 |
+
* @return mixed
|
205 |
+
*/
|
206 |
public function save_current_page( $template_name ) {
|
207 |
$this->template_name = basename( $template_name );
|
208 |
|
214 |
return $template_name;
|
215 |
}
|
216 |
|
217 |
+
/**
|
218 |
+
* Add the admin bar menu
|
219 |
+
*/
|
220 |
public function admin_bar_menu() {
|
221 |
global $wp_admin_bar;
|
222 |
|
223 |
+
// Check if direct file editing is allowed
|
224 |
+
$edit_allowed = $this->is_file_editing_allowed();
|
225 |
+
|
226 |
+
// Add top menu
|
227 |
+
$wp_admin_bar->add_menu( array(
|
228 |
+
'id' => 'wtf-bar',
|
229 |
+
'parent' => 'top-secondary',
|
230 |
+
'title' => __( 'What The File', 'what-the-file' ) . '<img src="'.plugins_url( 'assets/images/never5-logo.png', __FILE__ ).'" />',
|
231 |
+
'href' => false
|
232 |
+
) );
|
233 |
|
234 |
// Check if template file exists in child theme
|
235 |
$theme = get_stylesheet();
|
237 |
$theme = get_template();
|
238 |
}
|
239 |
|
240 |
+
// Add current page
|
241 |
+
$wp_admin_bar->add_menu( array(
|
242 |
+
'id' => 'wtf-bar-template-file',
|
243 |
+
'parent' => 'wtf-bar',
|
244 |
+
'title' => $this->get_current_page(),
|
245 |
+
'href' => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $this->get_current_page() . '&theme=' . $theme : false )
|
246 |
+
) );
|
247 |
|
248 |
+
// Check if theme uses template parts
|
249 |
if ( count( $this->template_parts ) > 0 ) {
|
|
|
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 |
+
// Loop through template parts
|
260 |
foreach ( $this->template_parts as $template_part ) {
|
261 |
|
262 |
// Check if template part exists in child theme
|
265 |
$theme = get_template();
|
266 |
}
|
267 |
|
268 |
+
// Add template part to sub menu item
|
269 |
+
$wp_admin_bar->add_menu( array(
|
270 |
+
'id' => 'wtf-bar-template-part-' . $template_part,
|
271 |
+
'parent' => 'wtf-bar-template-parts',
|
272 |
+
'title' => $template_part,
|
273 |
+
'href' => ( ( $edit_allowed ) ? get_admin_url() . 'theme-editor.php?file=' . $template_part . '&theme=' . $theme : false )
|
274 |
+
) );
|
275 |
}
|
276 |
|
277 |
}
|
278 |
+
|
279 |
+
// Add powered by
|
280 |
+
$wp_admin_bar->add_menu( array(
|
281 |
+
'id' => 'wtf-bar-powered-by',
|
282 |
+
'parent' => 'wtf-bar',
|
283 |
+
'title' => 'Powered by Never5',
|
284 |
+
'href' => 'http://www.never5.com?utm_source=plugin&utm_medium=wtf-bar&utm_campaign=what-the-file'
|
285 |
+
) );
|
286 |
+
|
287 |
}
|
288 |
|
289 |
+
/**
|
290 |
+
* Print the custom CSS
|
291 |
+
*/
|
292 |
public function print_css() {
|
293 |
+
echo "<style type=\"text/css\" media=\"screen\">#wp-admin-bar-wtf-bar img {margin:-4px 0 0 6px;}#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";
|
294 |
}
|
295 |
|
296 |
}
|
297 |
|
298 |
+
/**
|
299 |
+
* What The File main function
|
300 |
+
*/
|
301 |
+
function __what_the_file_main() {
|
302 |
+
new WhatTheFile();
|
303 |
+
}
|
304 |
+
|
305 |
+
// Init plugin
|
306 |
+
add_action( 'plugins_loaded', '__what_the_file_main' );
|
307 |
+
|
308 |
+
// Register hook
|
309 |
register_activation_hook( __FILE__, array( 'WhatTheFile', 'plugin_activation' ) );
|