-
Notifications
You must be signed in to change notification settings - Fork 3
/
class-wm-amplifier.php
638 lines (500 loc) · 15.2 KB
/
class-wm-amplifier.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/**
* WebMan Amplifier class
*
* Contains and loads the main plugin functionality.
*
* @package WebMan Amplifier
* @copyright WebMan Design, Oliver Juhas
*
* @since 1.0.0
* @version 1.5.11
*/
if ( ! class_exists( 'WM_Amplifier' ) ) {
class WM_Amplifier {
/**
* VARIABLES DEFINITION
*/
/**
* @var array
*/
public $errors = array();
/**
* SINGLETON
*/
/**
* Main WebMan Amplifier Instance
*
* Please load it only one time.
*
* Insures that only one instance of WebMan Amplifier exists in memory
* at any one time.
* Also prevents needing to define globals all over the place.
*
* @since 1.0
* @version 1.0.9.15
* @access public
*
* @return The one true WebMan Amplifier
*/
public static function instance() {
//Store the instance locally to avoid private static replication
static $instance = null;
//Only run these methods if they haven't been ran previously
if ( null === $instance ) {
$instance = new WM_Amplifier;
$instance->setup_actions();
$instance->setup_features();
}
//Always return the instance
return $instance;
} // /instance
/**
* SETUP METHODS
*/
/**
* Setup the default hooks and actions
*
* @since 1.0
* @version 1.5.11
*
* @access public
*/
public function setup_actions() {
// Helper variables
$actions = array(
'register_metaboxes' => 'plugins_loaded', // Register metaboxes
'register_widgets' => 'init|-10', // Register widgets
'save_permalinks' => 'init', // Save custom permalinks
'register_post_types' => 'init|0', // Register post types - before `widgets_init` fires (@link https://codex.wordpress.org/Plugin_API/Action_Reference)
'custom_taxonomies' => 'init|98', // Register additional custom taxonomies
'register_shortcodes' => 'init|5', // Register shortcodes (shortcodes contain an init hook with priority as early as 7, so we need to use lower one here)
'register_visual_editor_addons' => 'init', // Register Visual Editor addons
'register_icons' => 'init', // Register icon font
'admin_notices' => 'admin_notices', // Display admin notices
'deactivate' => 'switch_theme|10|2', // Deactivate plugin when theme changed
);
// Processing
foreach( $actions as $class_action => $hook ) {
$hook = explode( '|', $hook );
if ( ! isset( $hook[1] ) ) {
$hook[1] = 10;
}
if ( ! isset( $hook[2] ) ) {
$hook[2] = 1;
}
add_action( $hook[0], array( $this, $class_action ), $hook[1], $hook[2] );
} // /foreach
// Add filters
add_filter( 'request', array( $this, 'post_types_in_feed' ) );
add_filter( 'plugin_action_links_' . plugin_basename( WMAMP_PLUGIN_FILE ), array( $this, 'setup_action_links' ) );
// Loaded action
do_action( 'wmhook_wmamp_' . 'loaded' );
} // /setup_actions
/**
* Setup WordPress features
*
* @since 1.0
* @version 1.3.10
*
* @access public
*/
public function setup_features() {
// Load assets (JS and CSS)
add_action( 'admin_enqueue_scripts', array( $this, 'assets' ), 998 );
} // /setup_features
/**
* Setup WordPress plugin action links
*
* @since 1.1
* @version 1.1
*
* @access public
*/
public function setup_action_links( $links ) {
//Preparing output
//Icon font setup link
if (
apply_filters( 'wmhook_wmamp_' . 'enable_iconfont', true )
&& ! wma_supports_subfeature( 'disable-fonticons' )
) {
$links[] = '<a href="' . get_admin_url( null, 'themes.php?page=icon-font' ) . '">' . _x( 'Icon Font', 'Plugin action link.', 'webman-amplifier' ) . '</a>';
}
//Themes link
$links[] = '<a href="http://www.webmandesign.eu/" target="_blank" style="color: #83A552;">WebMan Themes</a>';
//Output
return $links;
} // /setup_action_links
/**
* PUBLIC METHODS
*/
/**
* Register (and include) styles and scripts
*
* @since 1.0
* @version 1.3.3
*
* @access public
*/
public function assets() {
//Helper variables
global $current_screen, $wp_version;
$display_isotope = apply_filters( 'wmhook_wmamp_' . 'notice_isotope_licence', true ) && ! wma_supports_subfeature( 'disable-isotope-notice' );
$pointers_seen = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
//Register
//Styles
wp_register_style( 'wmamp-admin-styles', WMAMP_ASSETS_URL . 'css/admin-addons.css', false, WMAMP_VERSION, 'screen' );
//Enqueue (only on specific admin pages)
if ( in_array( $current_screen->base, array( 'edit', 'post' ) ) ) {
//Styles
wp_enqueue_style( 'wmamp-admin-styles' );
}
} // /assets
/**
* Save permalinks
*
* @since 1.0
* @access public
*/
public function save_permalinks() {
if ( ! is_admin() ) {
return;
}
//We need to save the options ourselves.
//Settings api does not trigger save for the permalinks page.
if ( isset( $_POST['permalink_structure'] ) && isset( $_POST['wmamp-permalinks'] ) ) {
$permalinks = $_POST['wmamp-permalinks'];
//Validation
if ( ! $permalinks || ! is_array( $permalinks ) ) {
$permalinks = array();
} else {
foreach ( $permalinks as $key => $permalink ) {
$permalinks[$key] = untrailingslashit( trim( $permalink ) );
}
}
//Save permalinks
update_option( 'wmamp-permalinks', $permalinks );
//Flush rewrite rules
// flush_rewrite_rules();
}
} // /save_permalinks
/**
* Setup the post types
*
* @since 1.0
* @version 1.1.4
*
* @access public
*/
public function register_post_types() {
//Content Modules
if ( wma_supports_subfeature( 'cp-modules' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'custom-posts/modules.php' );
}
//Logos
if ( wma_supports_subfeature( 'cp-logos' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'custom-posts/logos.php' );
}
//Projects
if ( wma_supports_subfeature( 'cp-projects' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'custom-posts/projects.php' );
}
//Staff
if ( wma_supports_subfeature( 'cp-staff' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'custom-posts/staff.php' );
}
//Testimonials
if ( wma_supports_subfeature( 'cp-testimonials' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'custom-posts/testimonials.php' );
}
//Plugin register custom posts action
do_action( 'wmhook_wmamp_' . 'register_post_types' );
} // /register_post_types
/**
* Register additional custom taxonomies
*
* This function provides a taxonomy help for WordPress themes.
* In case your theme needs to register taxonomy, hook into the
* 'wmhook_wmamp_custom_taxonomies' and add your own taxonomy
* args. The array is set up like this:
* array(
* 'taxonomy_id' => array(
* 'object_type' => array(),
* 'args' => array()
* )
* @link http://codex.wordpress.org/Function_Reference/register_taxonomy
*
* @since 1.0.9.15
* @access public
*/
public function custom_taxonomies() {
//Helper variables
$taxonomies = (array) apply_filters( 'wmhook_wmamp_' . 'custom_taxonomies', array() );
//Requirements check
if ( empty( $taxonomies ) ) {
return;
}
//Processing
foreach ( $taxonomies as $taxonomy_id => $taxonomy ) {
if ( isset( $taxonomy['object_type'] ) && isset( $taxonomy['args'] ) ) {
register_taxonomy( $taxonomy_id, $taxonomy['object_type'], $taxonomy['args'] );
}
} // /foreach
} // /custom_taxonomies
/**
* Custom post types in feed
*
* @since 1.0
* @version 1.1.3
*
* @access public
*
* @param array $query
*
* @return array Modified feed query
*/
public function post_types_in_feed( $query ) {
if (
isset( $query['feed'] )
&& ! isset( $query['post_type'] )
) {
//First, make sure to display standard posts
$query['post_type'] = array( 'post' );
//Content Modules
if (
wma_supports_subfeature( 'cp-modules' )
&& apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_' . 'wm_modules', false )
) {
$query['post_type'][] = 'wm_modules';
}
//Logos
if (
wma_supports_subfeature( 'cp-logos' )
&& apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_' . 'wm_logos', false )
) {
$query['post_type'][] = 'wm_logos';
}
//Projects
if (
wma_supports_subfeature( 'cp-projects' )
&& apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_' . 'wm_projects', true )
) {
$query['post_type'][] = 'wm_projects';
}
//Staff
if (
wma_supports_subfeature( 'cp-staff' )
&& apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_' . 'wm_staff', false )
) {
$query['post_type'][] = 'wm_staff';
}
//Testimonials
if (
wma_supports_subfeature( 'cp-testimonials' )
&& apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_' . 'wm_testimonials', false )
) {
$query['post_type'][] = 'wm_testimonials';
}
}
//Output
return apply_filters( 'wmhook_wmamp_' . 'post_types_in_feed_query', $query );
} // /post_types_in_feed
/**
* Register metaboxes
*
* @since 1.0
* @version 1.1
*
* @access public
*
* @uses WM_Metabox
*/
public function register_metaboxes() {
if ( is_admin() ) {
require( WMAMP_INCLUDES_DIR . 'metabox/class-metabox.php' );
}
} // /register_metaboxes
/**
* Register shortcodes
*
* @since 1.0.0
* @version 1.5.0
*/
public function register_shortcodes() {
// Processing
if (
apply_filters( 'wmhook_wmamp_enable_shortcodes', true )
&& ! wma_supports_subfeature( 'disable-shortcodes' )
) {
require_once( WMAMP_INCLUDES_DIR . 'shortcodes/class-shortcodes.php' );
}
} // /register_shortcodes
/**
* Register Visual Editor addons
*
* @since 1.1
* @version 1.1
*
* @access public
*
* @uses Visual Editor addons
*/
public function register_visual_editor_addons() {
if (
apply_filters( 'wmhook_wmamp_' . 'enable_visual_editor_addons', true )
&& ! wma_supports_subfeature( 'disable-visual-editor-addons' )
) {
require( WMAMP_INCLUDES_DIR . 'visual-editor/visual-editor.php' );
}
} // /register_visual_editor_addons
/**
* Register icon font file
*
* @since 1.0
* @version 1.2.2
*
* @access public
*
* @uses WM_Icons
*/
public function register_icons() {
// Output
if (
apply_filters( 'wmhook_wmamp_' . 'enable_iconfont', true )
&& ! wma_supports_subfeature( 'disable-fonticons' )
) {
require( WMAMP_INCLUDES_DIR . 'icons/class-icon-font.php' );
return WM_Icons::instance();
}
} // /register_icons
/**
* Register widgets
*
* @since 1.0
* @version 1.1.3
*
* @access public
*/
public function register_widgets() {
//Contact widget
if ( wma_supports_subfeature( 'widget-contact' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-contact.php' );
}
//Content Module widget
if ( wma_supports_subfeature( 'widget-module' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-module.php' );
}
//Posts widget
if ( wma_supports_subfeature( 'widget-posts' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-posts.php' );
}
//Sub navigation widget
if ( wma_supports_subfeature( 'widget-subnav' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-subnav.php' );
}
//Tabbed widgets widget
if ( wma_supports_subfeature( 'widget-tabbed-widgets' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-tabbed-widgets.php' );
}
//Twitter widget
if ( wma_supports_subfeature( 'widget-twitter' ) ) {
include_once( WMAMP_INCLUDES_DIR . 'widgets/w-twitter.php' );
}
} // /register_widgets
/**
* Admin notices
*
* Displays the message stored in "wmamp-admin-notice" transient cache
* once or multiple times, than deletes the message cache.
* Transient structure:
* set_transient(
* 'wmamp-admin-notice',
* array( $text, $class, $capability, $number_of_displays )
* );
*
* @since 1.0
* @version 1.1.3
*
* @access public
*/
public function admin_notices() {
//Requirements check
if ( ! is_admin() ) {
return;
}
//Helper variables
$output = '';
$class = 'updated';
$repeat = 0;
$capability = apply_filters( 'wmhook_wmamp_' . 'notice_capability', 'switch_themes' );
$message = get_transient( 'wmamp-admin-notice' );
//Requirements check
if ( empty( $message ) ) {
return;
}
//Preparing output
if ( ! is_array( $message ) ) {
$message = array( $message, $class, $capability, $repeat );
}
if ( ! isset( $message[1] ) || empty( $message[1] ) ) {
$message[1] = $class;
}
if ( ! isset( $message[2] ) || empty( $message[2] ) ) {
$message[2] = $capability;
}
if ( ! isset( $message[3] ) ) {
$message[3] = $repeat;
}
if ( $message[0] && current_user_can( $message[2] ) ) {
$output .= '<div class="' . trim( 'wm-notice ' . $message[1] ) . '"><p>' . $message[0] . '</p></div>';
delete_transient( 'wmamp-admin-notice' );
}
//Delete the transient cache after specific number of displays
if ( 1 < intval( $message[3] ) ) {
$message[3] = intval( $message[3] ) - 1;
set_transient( 'wmamp-admin-notice', $message, ( 60 * 60 * 48 ) );
}
//Output
if ( $output ) {
echo apply_filters( 'wmhook_wmamp_' . 'admin_notices_output', $output, $message );
}
} // /admin_notices
/**
* Plugin deactivation
*
* @since 1.0.9.9
* @version 1.2
*
* @access public
*/
public function deactivate( $newname, $newtheme ) {
if (
current_user_can( 'activate_plugins' )
&& wp_get_theme()->get( 'Name' ) !== $newname
&& get_transient( 'wmamp-deactivate' )
) {
delete_transient( 'wmamp-deactivate' );
deactivate_plugins( plugin_basename( WMAMP_PLUGIN_FILE ) );
}
} // /deactivate
/**
* 100) Helpers
*/
/**
* Fixing URLs in `is_ssl()` returns TRUE
*
* @since 1.3.5
* @version 1.3.5
*
* @param string $content
*/
static public function fix_ssl_urls( $content ) {
// Processing
if ( is_ssl() ) {
$content = str_ireplace( 'http:', 'https:', $content );
}
// Output
return $content;
} // /fix_ssl_urls
} // /WM_Amplifier
} // /class WM_Amplifier check