forked from WPChill/epsilon-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-epsilon-framework.php
359 lines (323 loc) · 9.23 KB
/
class-epsilon-framework.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
if ( ! defined( 'WPINC' ) ) {
die;
}
require_once dirname( __FILE__ ) . '/class-epsilon-autoloader.php';
/**
* Class Epsilon_Framework
*/
class Epsilon_Framework {
/**
* By default, it loads all controls
*
* @var array|mixed
*/
private $controls = array(
'toggle',
'typography',
'slider',
'repeater',
'section-repeater',
'image',
'text-editor',
'icon-picker',
'customizer-navigation',
'color-scheme',
'button-group',
'separator',
'page-changer',
'image-dimensions',
);
/**
* By default, it loads all sections
*
* @var array|mixed
*/
private $sections = array(
'recommended-actions',
'pro',
'doubled',
);
/**
* By default, load all panels
*
* @var array
*/
private $panels = array(
'regular',
);
/**
* @var bool
*/
private $plugin = false;
/**
* If we're in a plugin, set up uri manually
*
* @var string
*/
private $plugin_uri = '';
/**
* If we're in a plugin, set up paths manually
*
* @var string
*/
private $plugin_path = '';
/**
* Default path is in /inc/libraries
*
* @var mixed|string
*/
private $path = '/inc/libraries';
/**
* At the current moment, backup is a must
*
* @var bool
*/
private $backup = true;
/**
* Epsilon_Framework constructor.
*
* @param $args array
*/
public function __construct( $args = array() ) {
foreach ( $args as $k => $v ) {
if ( ! in_array(
$k, array(
'controls',
'sections',
'panels',
'plugin',
'path',
'backup',
'plugin_uri',
'plugin_dir',
)
) ) {
continue;
}
$this->$k = $v;
}
if ( $this->backup ) {
/**
* Let's initiate a backup instance
*/
$backup = Epsilon_Content_Backup::get_instance();
}
/**
* Define Framework uri and paths
*/
$this->define_paths();
/**
* Enqueue scripts and styles
*/
$this->start_enqueues();
/**
* Add quick links
*/
$this->add_action_links();
/**
* AJAX handling moved to a different class
*/
new Epsilon_Ajax_Controller();
}
/**
* Init custom controls
*
* @param object $wp_customize
*/
public function init_controls( $wp_customize ) {
foreach ( $this->controls as $control ) {
if ( file_exists( EPSILON_PATH . '/customizer/controls/class-epsilon-control-' . $control . '.php' ) ) {
require_once EPSILON_PATH . '/customizer/controls/class-epsilon-control-' . $control . '.php';
}
if ( file_exists( EPSILON_PATH . '/customizer/settings/class-epsilon-setting-' . $control . '.php' ) ) {
require_once EPSILON_PATH . '/customizer/settings/class-epsilon-setting-' . $control . '.php';
}
}
foreach ( $this->sections as $section ) {
if ( file_exists( EPSILON_PATH . '/customizer/sections/class-epsilon-section-' . $section . '.php' ) ) {
require_once EPSILON_PATH . '/customizer/sections/class-epsilon-section-' . $section . '.php';
}
}
foreach ( $this->panels as $panel ) {
if ( file_exists( EPSILON_PATH . '/customizer/panels/class-epsilon-panel-' . $panel . '.php' ) ) {
require_once EPSILON_PATH . '/customizer/panels/class-epsilon-panel-' . $panel . '.php';
}
}
/**
* Expose Manager to the Epsilon Customizer class.
*/
Epsilon_Customizer::get_instance( $wp_customize );
}
/**
* Add quick links to point in customizer
*/
public function add_action_links() {
add_filter( 'display_post_states', array( 'Epsilon_Customizer', 'add_display_post_states' ), 99, 2 );
add_filter( 'page_row_actions', array( 'Epsilon_Customizer', 'add_action_links' ), 99, 2 );
add_action( 'edit_form_after_title', array( 'Epsilon_Customizer', 'add_action_link_to_page' ), 99 );
add_action( 'edit_form_after_title', array( 'Epsilon_Customizer', 'replace_rich_editor' ), 99 );
}
/**
* Centralize scripts and styles in a function for easier maintenance
*
* @since 1.1.0
*/
public function start_enqueues() {
/**
* Admin enqueues
*/
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
/**
* Customizer enqueues & controls
*/
add_action( 'customize_register', array( $this, 'init_controls' ), 10 );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'customizer_enqueue_scripts' ), 25 );
add_action( 'customize_preview_init', array( $this, 'customize_preview_styles' ), 25 );
/**
* Repeater fields templates
*/
add_action(
'customize_controls_print_footer_scripts', array(
'Epsilon_Repeater_Templates',
'field_repeater_js_template',
), 0
);
add_action(
'customize_controls_print_footer_scripts', array(
'Epsilon_Repeater_Templates',
'section_repeater_js_template',
), 0
);
}
/**
* @since 1.0.0
*/
public function enqueue() {
wp_enqueue_script( 'epsilon-admin', EPSILON_URI . '/assets/js/epsilon-framework-admin.js', array( 'jquery' ) );
wp_localize_script(
'epsilon-admin', 'EpsilonWPUrls', array(
'siteurl' => get_option( 'siteurl' ),
'theme' => get_template_directory_uri(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax_nonce' => wp_create_nonce( 'epsilon_nonce' ),
'post_page' => Epsilon_Helper::get_blogpage_permalink(),
'front_page' => Epsilon_Helper::get_static_frontpage_permalink(),
)
);
wp_enqueue_style( 'epsilon-admin', EPSILON_URI . '/assets/css/style-admin.css' );
if ( apply_filters( 'show_epsilon_quickie_bar', true ) ) {
/**
* Enqueue Quickie bar for Epsilon FW
*
* @return void
*/
wp_enqueue_script( 'epsilon-quickie-bar', EPSILON_URI . '/assets/js/epsilon-framework-quickie.js', array( 'jquery' ) );
wp_localize_script( 'epsilon-quickie-bar', 'EpsilonQuickieObj',
apply_filters( 'epsilon_quickie_bar_shortcuts',
array(
'links' => array(
array(
'link_to' => 'colors',
'icon' => 'dashicons dashicons-admin-appearance',
'link_type' => 'section',
),
array(
'link_to' => 'portum_typography_section',
'icon' => 'dashicons dashicons-editor-textcolor',
'link_type' => 'section',
),
array(
'link_to' => 'portum_repeatable_section',
'icon' => 'dashicons dashicons-editor-table',
'link_type' => 'section',
),
array(
'link_to' => 'nav_menus',
'icon' => 'dashicons dashicons-menu',
'link_type' => 'panel',
),
array(
'link_to' => 'portum_panel_general',
'icon' => 'dashicons dashicons-admin-settings',
'link_type' => 'panel',
),
array(
'link_to' => 'custom_css',
'icon' => 'dashicons dashicons-editor-code',
'link_type' => 'section',
),
),
'logo' => array(
'url' => EPSILON_URI . '/assets/img/epsilon-logo.png',
'alt' => 'Epsilon Builder Logo',
),
) ) );
}
}
/**
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
*/
public function customize_preview_styles() {
wp_enqueue_style( 'epsilon-styles', EPSILON_URI . '/assets/css/style.css' );
wp_enqueue_script( 'epsilon-previewer', EPSILON_URI . '/assets/js/epsilon-framework-previewer.js', array(
'jquery',
'customize-preview',
), 2, true );
wp_localize_script( 'epsilon-previewer',
'EpsilonWPUrls', array(
'siteurl' => get_option( 'siteurl' ),
'theme' => get_template_directory_uri(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax_nonce' => wp_create_nonce( 'epsilon_nonce' ),
'post_page' => Epsilon_Helper::get_blogpage_permalink(),
'front_page' => Epsilon_Helper::get_static_frontpage_permalink(),
) );
}
/*
* Our Customizer script
*
* Dependencies: Customizer Controls script (core)
*/
public function customizer_enqueue_scripts() {
wp_enqueue_script( 'epsilon-object', EPSILON_URI . '/assets/js/epsilon-framework-customizer.js', array(
'jquery',
'customize-controls',
), false, true );
wp_localize_script( 'epsilon-object',
'EpsilonWPUrls', array(
'siteurl' => get_option( 'siteurl' ),
'theme' => get_template_directory_uri(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax_nonce' => wp_create_nonce( 'epsilon_nonce' ),
'post_page' => Epsilon_Helper::get_blogpage_permalink(),
'front_page' => Epsilon_Helper::get_static_frontpage_permalink(),
) );
wp_localize_script( 'epsilon-object',
'EpsilonTranslations', array(
'remove' => esc_html__( 'Remove', 'epsilon-framework' ),
'add' => esc_html__( 'Add', 'epsilon-framework' ),
'selectFile' => esc_html__( 'Upload image', 'epsilon-framework' ),
'row' => esc_html__( 'Row', 'epsilon-framework' ),
) );
wp_enqueue_style( 'font-awesome', EPSILON_URI . '/assets/vendors/fontawesome/font-awesome.css' );
wp_enqueue_style( 'epsilon-styles', EPSILON_URI . '/assets/css/style.css' );
}
/**
* Define epsilon loading paths
*/
public function define_paths() {
$dir_uri = get_template_directory_uri();
$dir = get_template_directory();
if ( $this->plugin ) {
$dir_uri = $this->plugin_uri;
$dir = $this->plugin_path;
}
/**
* Define URI and PATH for the framework
*/
define( 'EPSILON_URI', $dir_uri . $this->path . '/epsilon-framework' );
define( 'EPSILON_PATH', $dir . $this->path . '/epsilon-framework' );
define( 'EPSILON_BACKUP', $this->backup );
}
}