-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
141 lines (120 loc) · 2.78 KB
/
Plugin.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Image tag generator.
*
* Plugin name: Image Tag Generator
* Plugin URI: https://github.com/crstauf/image_tag
* Description: WordPress drop-in to generate <code>img</code> tags.
* Author: Caleb Stauffer
* Author URI: https://develop.calebstauffer.com
* Version: 2.3
* Requires at least: 5.1
* Requires PHP: 7.1
*
* @todo add CLI command: clear common colors from attachment meta data
* @todo add CLI command: clear LQIPs from attachment meta data
*/
declare( strict_types=1 );
namespace Image_Tag;
defined( 'WPINC' ) || die();
/**
* Class: Image_Tag\Plugin
*/
final class Plugin {
/**
* @var float
*/
const VERSION = 2.3;
/**
* Get instance.
*
* @return self
*/
public static function instance() : self {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new self; // @codeCoverageIgnore
}
return $instance;
}
/**
* Construct.
*
* @codeCoverageIgnore
*/
protected function __construct() {
add_action( 'template_redirect', array( $this, 'action__template_redirect' ), 100 );
add_action( 'admin_init', array( $this, 'action__admin_init' ) );
}
/**
* Action: template_redirect
*
* - include files, hopefully after any processing and redirection
*
* @uses static::includes()
*
* @codeCoverageIgnore
*/
public function action__template_redirect() : void {
static::include_files();
}
/**
* Action: admin_init
*
* - include files, except for AJAX requests
*
* @uses static::includes()
*
* @codeCoverageIgnore
*/
public function action__admin_init() : void {
if ( ! wp_doing_ajax() ) {
return;
}
static::include_files();
}
/**
* Get plugin directory path.
*
* @return string
*/
public static function dir() : string {
return trailingslashit( __DIR__ );
}
/**
* Get includes directory path.
*
* @uses static::dir()
* @return string
*/
public static function inc() : string {
return static::dir() . 'includes/';
}
/**
* Include all the core files.
*
* @see Image_Tag::create() for loading of image tag types.
* @uses static::inc()
*
* @codeCoverageIgnore
*/
public static function include_files() : void {
$dir = static::inc();
# Interfaces.
require_once $dir . 'interfaces/Conversion.php';
require_once $dir . 'interfaces/Data_Store.php';
require_once $dir . 'interfaces/Dynamic_Source.php';
require_once $dir . 'interfaces/Output.php';
require_once $dir . 'interfaces/Validation.php';
# Abstracts.
require_once $dir . 'abstracts/Base.php';
require_once $dir . 'abstracts/Data_Store.php';
require_once $dir . 'abstracts/WordPress.php';
# Data.
require_once $dir . 'data_stores/Attributes.php';
require_once $dir . 'data_stores/Settings.php';
# Base.
require_once $dir . 'types/Image_Tag.php';
}
}
Plugin::instance();