-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCore.php
More file actions
227 lines (193 loc) · 6.22 KB
/
Copy pathCore.php
File metadata and controls
227 lines (193 loc) · 6.22 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://rockiger.com
* @since 1.0.0
*
* @package Reactpress
* @subpackage Reactpress/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-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 1.0.0
* @package Reactpress
* @subpackage Reactpress/includes
* @author Marco Laspe <marco@rockiger.com>
*/
namespace ReactPress\Includes;
//* The class responsible for defining all actions that occur in the admin area.
use ReactPress\Admin\Admin;
//* The class responsible for defining internationalization functionality
//* of the plugin.
use ReactPress\Includes\I18n;
//* The class responsible for orchestrating the actions and filters of the
//* core plugin.
use ReactPress\Includes\Loader;
//* The class responsible for defining all actions that occur in the public-facing
//* side of the site.
use ReactPress\User\User;
class Core {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if (defined('REPR_VERSION')) {
$this->version = REPR_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'reactpress';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Reactpress_Loader. Orchestrates the hooks of the plugin.
* - Reactpress_i18n. Defines internationalization functionality.
* - Reactpress_Admin. Defines all hooks for the admin area.
* - Reactpress_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
$this->loader = new Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Reactpress_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new I18n();
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new Admin($this->get_plugin_name(), $this->get_version());
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
$this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menu');
$this->loader->add_action('wp_ajax_repr_admin_ajax_request', $plugin_admin, 'repr_handle_admin_ajax_request');
// Add our custom template to the admin's templates dropdown
$this->loader->add_filter('theme_page_templates', $plugin_admin, 'repr_add_page_template');
// Add our post state (label) for pages used by apps.
$this->loader->add_filter('display_post_states', $plugin_admin, 'add_post_state', 20, 2);
// Check if current current version of plugin is saved in db
$this->loader->add_action('admin_init', $plugin_admin, 'check_plugin_version');
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$plugin_public = new User($this->get_plugin_name(), $this->get_version());
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts', 1000);
// Add template
$this->loader->add_filter('template_include', $plugin_public, 'repr_change_page_template', 99);
$this->loader->add_filter('script_loader_tag', $plugin_public, 'add_type_module_to_scripts', 10, 3);
// Add rewrite rules
$this->loader->add_action('init', $plugin_public, 'add_repr_apps_rewrite_rules');
$this->loader->add_action('generate_rewrite_rules', $plugin_public, 'site_custom_endpoint');
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}