|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The file that defines the core plugin class |
|
5
|
|
|
* |
|
6
|
|
|
* A class definition that includes attributes and functions used across both the |
|
7
|
|
|
* public-facing side of the site and the admin area. |
|
8
|
|
|
* |
|
9
|
|
|
* @link https://github.com/austinheap/wordpress-security-txt |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
* |
|
12
|
|
|
* @package WordPress_Security_Txt |
|
13
|
|
|
* @subpackage WordPress_Security_Txt/includes |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The core plugin class. |
|
18
|
|
|
* |
|
19
|
|
|
* This is used to define internationalization, admin-specific hooks, and |
|
20
|
|
|
* public-facing site hooks. |
|
21
|
|
|
* |
|
22
|
|
|
* Also maintains the unique identifier of this plugin as well as the current |
|
23
|
|
|
* version of the plugin. |
|
24
|
|
|
* |
|
25
|
|
|
* @since 1.0.0 |
|
26
|
|
|
* @package WordPress_Security_Txt |
|
27
|
|
|
* @subpackage WordPress_Security_Txt/includes |
|
28
|
|
|
* @author Austin Heap <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
class WordPress_Security_Txt |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The loader that's responsible for maintaining and registering all hooks that power |
|
35
|
|
|
* the plugin. |
|
36
|
|
|
* |
|
37
|
|
|
* @since 1.0.0 |
|
38
|
|
|
* @access protected |
|
39
|
|
|
* @var WordPress_Security_Txt_Loader $loader Maintains and registers all hooks for the plugin. |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $loader; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The unique identifier of this plugin. |
|
45
|
|
|
* |
|
46
|
|
|
* @since 1.0.0 |
|
47
|
|
|
* @access protected |
|
48
|
|
|
* @var string $plugin_name The string used to uniquely identify this plugin. |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $plugin_name; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The current version of the plugin. |
|
54
|
|
|
* |
|
55
|
|
|
* @since 1.0.0 |
|
56
|
|
|
* @access protected |
|
57
|
|
|
* @var string $version The current version of the plugin. |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $version; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Define the core functionality of the plugin. |
|
63
|
|
|
* |
|
64
|
|
|
* Set the plugin name and the plugin version that can be used throughout the plugin. |
|
65
|
|
|
* Load the dependencies, define the locale, and set the hooks for the admin area and |
|
66
|
|
|
* the public-facing side of the site. |
|
67
|
|
|
* |
|
68
|
|
|
* @since 1.0.0 |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct() |
|
71
|
|
|
{ |
|
72
|
|
|
if (defined('WORDPRESS_SECURITY_TXT_VERSION')) { |
|
73
|
|
|
$this->version = WORDPRESS_SECURITY_TXT_VERSION; |
|
74
|
|
|
} else { |
|
75
|
|
|
$this->version = '1.0.1'; |
|
76
|
|
|
} |
|
77
|
|
|
$this->plugin_name = 'wordpress-security-txt'; |
|
78
|
|
|
|
|
79
|
|
|
$this->load_dependencies(); |
|
80
|
|
|
$this->set_locale(); |
|
81
|
|
|
$this->define_admin_hooks(); |
|
82
|
|
|
$this->define_public_hooks(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Load the required dependencies for this plugin. |
|
87
|
|
|
* |
|
88
|
|
|
* Include the following files that make up the plugin: |
|
89
|
|
|
* |
|
90
|
|
|
* - WordPress_Security_Txt_Loader. Orchestrates the hooks of the plugin. |
|
91
|
|
|
* - WordPress_Security_Txt_i18n. Defines internationalization functionality. |
|
92
|
|
|
* - WordPress_Security_Txt_Admin. Defines all hooks for the admin area. |
|
93
|
|
|
* - WordPress_Security_Txt_Public. Defines all hooks for the public side of the site. |
|
94
|
|
|
* |
|
95
|
|
|
* Create an instance of the loader which will be used to register the hooks |
|
96
|
|
|
* with WordPress. |
|
97
|
|
|
* |
|
98
|
|
|
* @since 1.0.0 |
|
99
|
|
|
* @access private |
|
100
|
|
|
*/ |
|
101
|
|
|
private function load_dependencies() |
|
102
|
|
|
{ |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* The class responsible for orchestrating the actions and filters of the |
|
106
|
|
|
* core plugin. |
|
107
|
|
|
*/ |
|
108
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordpress-security-txt-loader.php'; |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* The class responsible for defining internationalization functionality |
|
112
|
|
|
* of the plugin. |
|
113
|
|
|
*/ |
|
114
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordpress-security-txt-i18n.php'; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* The class responsible for defining all actions that occur in the admin area. |
|
118
|
|
|
*/ |
|
119
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordpress-security-txt-admin.php'; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* The class responsible for rendering all fields that occur in the admin area. |
|
123
|
|
|
*/ |
|
124
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordpress-security-txt-builder.php'; |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* The class responsible for registering all fields that occur in the admin area. |
|
128
|
|
|
*/ |
|
129
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordpress-security-txt-field.php'; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* The class responsible for sanitizing all fields that occur in the admin area. |
|
133
|
|
|
*/ |
|
134
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordpress-security-txt-sanitizer.php'; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* The class responsible for defining all actions that occur in the public-facing |
|
138
|
|
|
* side of the site. |
|
139
|
|
|
*/ |
|
140
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-wordpress-security-txt-public.php'; |
|
141
|
|
|
|
|
142
|
|
|
$this->loader = new WordPress_Security_Txt_Loader(); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Define the locale for this plugin for internationalization. |
|
147
|
|
|
* |
|
148
|
|
|
* Uses the WordPress_Security_Txt_i18n class in order to set the domain and to register the hook |
|
149
|
|
|
* with WordPress. |
|
150
|
|
|
* |
|
151
|
|
|
* @since 1.0.0 |
|
152
|
|
|
* @access private |
|
153
|
|
|
*/ |
|
154
|
|
|
private function set_locale() |
|
155
|
|
|
{ |
|
156
|
|
|
$plugin_i18n = new WordPress_Security_Txt_i18n(); |
|
157
|
|
|
|
|
158
|
|
|
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Register all of the hooks related to the admin area functionality |
|
163
|
|
|
* of the plugin. |
|
164
|
|
|
* |
|
165
|
|
|
* @since 1.0.0 |
|
166
|
|
|
* @access private |
|
167
|
|
|
*/ |
|
168
|
|
|
private function define_admin_hooks() |
|
169
|
|
|
{ |
|
170
|
|
|
$plugin_admin = new WordPress_Security_Txt_Admin($this->get_plugin_name(), $this->get_version()); |
|
171
|
|
|
|
|
172
|
|
|
if (isset($_GET['page']) && ($_GET['page'] == 'wordpress-security-txt' || $_GET['page'] == 'wordpress-security-txt-help')) { |
|
173
|
|
|
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
174
|
|
|
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
$this->loader->add_action('admin_menu', $plugin_admin, 'add_options_page'); |
|
178
|
|
|
$this->loader->add_action('admin_init', $plugin_admin, 'register_settings'); |
|
179
|
|
|
$this->loader->add_action('admin_init', $plugin_admin, 'register_sections'); |
|
180
|
|
|
$this->loader->add_action('admin_init', $plugin_admin, 'register_fields'); |
|
181
|
|
|
$this->loader->add_filter('plugin_action_links_' . WORDPRESS_SECURITY_TXT_FILE, $plugin_admin, |
|
182
|
|
|
'link_settings'); |
|
183
|
|
|
$this->loader->add_action('plugin_row_meta', $plugin_admin, 'link_row', 10, 2); |
|
184
|
|
|
$this->loader->add_action('wp_before_admin_bar_render', $plugin_admin, 'admin_bar'); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* The name of the plugin used to uniquely identify it within the context of |
|
189
|
|
|
* WordPress and to define internationalization functionality. |
|
190
|
|
|
* |
|
191
|
|
|
* @since 1.0.0 |
|
192
|
|
|
* @return string The name of the plugin. |
|
193
|
|
|
*/ |
|
194
|
|
|
public function get_plugin_name() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->plugin_name; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Retrieve the version number of the plugin. |
|
201
|
|
|
* |
|
202
|
|
|
* @since 1.0.0 |
|
203
|
|
|
* @return string The version number of the plugin. |
|
204
|
|
|
*/ |
|
205
|
|
|
public function get_version() |
|
206
|
|
|
{ |
|
207
|
|
|
return $this->version; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Register all of the hooks related to the public-facing functionality |
|
212
|
|
|
* of the plugin. |
|
213
|
|
|
* |
|
214
|
|
|
* @since 1.0.0 |
|
215
|
|
|
* @access private |
|
216
|
|
|
*/ |
|
217
|
|
|
private function define_public_hooks() |
|
218
|
|
|
{ |
|
219
|
|
|
$plugin_public = new WordPress_Security_Txt_Public($this->get_plugin_name(), $this->get_version()); |
|
220
|
|
|
|
|
221
|
|
|
$this->loader->add_action('plugins_loaded', $plugin_public, 'route'); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Send event to server for processing. |
|
226
|
|
|
* |
|
227
|
|
|
* @since 1.0.0 |
|
228
|
|
|
* @return void |
|
229
|
|
|
*/ |
|
230
|
|
|
public static function event($name, $version = WORDPRESS_SECURITY_TXT_VERSION) |
|
231
|
|
|
{ |
|
232
|
|
|
$options = WordPress_Security_Txt_Admin::get_options(); |
|
233
|
|
|
|
|
234
|
|
|
if (isset($options['statistics']) && $options['statistics']) { |
|
235
|
|
|
$cache_file = WordPress_Security_Txt_Public::cache_file(); |
|
236
|
|
|
$cache_readable = is_readable($cache_file); |
|
237
|
|
|
$payload = [ |
|
238
|
|
|
'name' => $name, |
|
239
|
|
|
'version' => $version, |
|
240
|
|
|
'url' => get_site_url(), |
|
|
|
|
|
|
241
|
|
|
'document' => [ |
|
242
|
|
|
'contents' => $cache_readable ? file_get_contents($cache_file) : null, |
|
243
|
|
|
'ctime' => is_readable($cache_file) ? filectime($cache_file) : null, |
|
244
|
|
|
'mtime' => is_readable($cache_file) ? filemtime($cache_file) : null, |
|
245
|
|
|
], |
|
246
|
|
|
]; |
|
247
|
|
|
$result = wp_remote_post('https://austinheap.com/projects/wordpress-security-txt/', $payload); |
|
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
unset($result); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Run the loader to execute all of the hooks with WordPress. |
|
255
|
|
|
* |
|
256
|
|
|
* @since 1.0.0 |
|
257
|
|
|
*/ |
|
258
|
|
|
public function run() |
|
259
|
|
|
{ |
|
260
|
|
|
$this->loader->run(); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* The reference to the class that orchestrates the hooks with the plugin. |
|
265
|
|
|
* |
|
266
|
|
|
* @since 1.0.0 |
|
267
|
|
|
* @return WordPress_Security_Txt_Loader Orchestrates the hooks of the plugin. |
|
268
|
|
|
*/ |
|
269
|
|
|
public function get_loader() |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->loader; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Imports php-security-txt. |
|
276
|
|
|
* |
|
277
|
|
|
* @since 1.0.0 |
|
278
|
|
|
* @return void |
|
279
|
|
|
*/ |
|
280
|
|
|
public static function import_lib() |
|
281
|
|
|
{ |
|
282
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Directives/Acknowledgement.php'; |
|
|
|
|
|
|
283
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Directives/Contact.php'; |
|
284
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Directives/Disclosure.php'; |
|
285
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Directives/Encryption.php'; |
|
286
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/SecurityTxtInterface.php'; |
|
287
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/SecurityTxt.php'; |
|
288
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Writer.php'; |
|
289
|
|
|
require_once plugin_dir_path(dirname(__FILE__)) . 'lib/src/Reader.php'; |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
|