-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
133 lines (118 loc) · 2.74 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
<?php
namespace [namespace];
/**
* The core plugin class.
*
* This is used to define internationalization, dashboard-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since [initial_version]
*/
class Plugin {
/**
* The unique identifier of this plugin.
*
* @since [initial_version]
* @access protected
* @var string
*/
protected $name;
/**
* The current version of the plugin.
*
* @since [initial_version]
* @access protected
* @var string
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* @since [initial_version]
* @param string $name The plugin identifier.
* @param string $version Current version of the plugin.
*/
public function __construct( $name, $version ) {
$this->name = $name;
$this->version = $version;
}
/**
* Run the loader to execute all the hooks with WordPress.
*
* Load the dependencies, define the locale, and set the hooks for the
* Dashboard and the public-facing side of the site.
*
* @since [initial_version]
*/
public function run() {
$this->set_locale();
$this->define_admin_hooks();
$this->define_frontend_hooks();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since [initial_version]
* @return string The name of the plugin.
*/
public function get_name() {
return $this->name;
}
/**
* Returns the version number of the plugin.
*
* @since [initial_version]
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the I18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since [initial_version]
* @access private
*/
private function set_locale() {
$i18n = new I18n();
$i18n->set_domain( $this->get_name() );
$i18n->load_plugin_textdomain();
}
/**
* Register all of the hooks related to the dashboard functionality
* of the plugin.
*
* @since [initial_version]
* @access private
*/
private function define_admin_hooks() {
$components = [
'admin' => new Admin( $this ),
];
foreach ( $components as $component ) {
$component->register();
}
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since [initial_version]
* @access private
*/
private function define_frontend_hooks() {
$components = [
'frontend' => new Frontend( $this ),
];
foreach ( $components as $component ) {
$component->register();
}
}
}