-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-show-template.php
More file actions
74 lines (63 loc) · 1.51 KB
/
class-show-template.php
File metadata and controls
74 lines (63 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Plugin Name: Show Template
* Description: Show's the template file being used at the top of the page
* Version: 1.0
* Author: Mike Estrada
*
* @package dev-toolbox
*
* Notes:
* - This class is initiated at the bottom of the file.
* - Define your preferred action/comment inside the __construct method
*/
if ( ! class_exists( 'Show_Template' ) ) {
/**
* Show_Template
*/
class Show_Template {
/**
* Instance of this class
*
* @var boolean
*/
public static $instance = false;
/**
* Add all actions & filters and initial build setup
*/
public function __construct() {
$this->action_hook = 'wp_head';
$this->comment_output = true;
add_action( 'init', [ $this, 'show_template' ] );
}
/**
* Singleton
*
* Returns a single instance of the current class.
*/
public static function singleton() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Print the full path of the current template to a specific location
*
* @return void
*/
public function show_template() {
add_action( $this->action_hook, function() {
global $template;
$path = print_r( $template, true );
if ( $this->comment_output ) {
$path = sprintf( "<!-- Template path: \n %s \n --> \n", $path );
}
$allowed_tags = wp_kses_allowed_html( 'post' );
echo wp_kses_post( $path );
} );
}
} // End class definition
// Initiate the class.
Show_Template::singleton();
} // End if class_exists