-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-viewer.php
63 lines (53 loc) · 1.73 KB
/
template-viewer.php
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
<?php
/**
* Plugin Name: Template Viewer
* Plugin URI: https://wpdev.life
* Description: lets authors easily see which template a page is using and also see only pages using a particular template.
* Author: Jay Hill
* Author URI: https://wpdev.life
* Text Domain: template-viewer
* Domain Path: /languages
* Version: 0.1.0
*
* @package Template_Viewer
*/
namespace WPDevLife\TemplateViewer;
define(__NAMESPACE__ . '\PATH', plugin_dir_path(__FILE__));
spl_autoload_register(
function ( $class ) {
$base_dir = __DIR__ . '/inc/';
$len = strlen(__NAMESPACE__);
if (strncmp(__NAMESPACE__, $class, $len) !== 0 ) {
return;
}
// Remove the namespace prefix.
// Replace namespace separators with directory separators in the class name.
// Replace underscores with dashes in the class name.
// Append with .php extension.
$class_file_name = str_replace([ '\\', '_' ], [ '/', '-' ], strtolower(substr($class, $len + 1))) . '.php';
// Add `class-` to file name so we meet WPCS standards.
$class_file_name = preg_replace('/([\w-]+)\.php/', 'class-$1.php', $class_file_name);
$file = $base_dir . $class_file_name;
// If the file exists, require it.
if (file_exists($file) ) {
include $file;
}
}
);
function activated()
{
//add filters and things on activation
}
register_activation_hook(__FILE__, __NAMESPACE__ . '\activated');
function deactivated()
{
// remove filters and things on deactivation
}
register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivated');
add_action(
'plugins_loaded',
function () {
TemplateViewer::init();
}
)
?>