This repository was archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcybosm.php
More file actions
766 lines (678 loc) · 21.8 KB
/
cybosm.php
File metadata and controls
766 lines (678 loc) · 21.8 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
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
<?php
/**
* Plugin Name: Cybosm
* Plugin URI: https://github.com/cyrillbolliger/cybosm
* Version: 1.3.0
* Description: Yet another social sharing plugin. Extremly lightwight.
* Author: Cyrill Bolliger
* Author URI: http://www.cyrillbolliger.ch
* Text Domain: cybosm
* Domain Path: languages
* GitHub Plugin URI: cyrillbolliger/cybosm
* License: GPL 2.
*/
/**
* Copyright 2015 Cyrill Bolliger (email: bolliger@gmx.ch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* lock out script kiddies: die an direct call
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* abspath to plugins directory
*/
define( 'CYBOSM_PLUGIN_PATH', dirname( __FILE__ ) );
/**
* version number (dont forget to change it also in the header)
*/
define( 'CYBOSM_VERSION', '1.3.0' );
/**
* plugin prefix
*/
define( 'CYBOSM_PLUGIN_PREFIX', 'cybosm' );
/**
* load settings class
*/
require_once( CYBOSM_PLUGIN_PATH . '/includes/class-cybosm-settings.php' );
if ( ! class_exists( 'Cybosm_Main' ) ) {
class Cybosm_Main extends Cybosm_Settings {
/*
* Construct the plugin object
*/
public function __construct() {
parent::__construct();
register_activation_hook( __FILE__, array( &$this, 'activate' ) );
register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
add_action( 'init', array( &$this, 'init' ) );
add_action( 'init', array( &$this, 'fe_init' ) );
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_menu', array( &$this, 'add_menu' ) );
add_action( 'plugins_loaded', array( &$this, 'i18n' ) );
add_action( 'plugins_loaded', array( &$this, 'upgrade' ) );
add_action( 'wp_enqueue_scripts', array( &$this, 'load_resources' ) );
add_action( 'admin_enqueue_scripts', array( &$this, 'load_resources' ) );
add_action( 'widgets_init', array( &$this, 'cybosm_load_widget' ) );
}
/**
* Activate the plugin
*/
public function activate() {
$this->set_version_number();
$this->add_roles_on_plugin_activation();
$this->add_capabilities_on_plugin_activation();
$this->create_tables_on_plugin_activation();
$this->create_default_options_on_first_plugin_activation();
}
/**
* Deactivate the plugin
*/
public function deactivate() {
$this->remove_capabilities_on_plugin_deactivation();
$this->remove_roles_on_plugin_deactivation();
}
/**
* Hook into WP's init action hook.
*/
public function init() {
}
/**
* Hook into WP's init action hook for frontend pages
*/
public function fe_init() {
if ( ! is_admin() ) {
// load the frontend
require_once( CYBOSM_PLUGIN_PATH . '/includes/class-cybosm-frontend.php' );
}
}
/**
* Hook into WP's admin_init action hook
*/
public function admin_init() {
$this->init_options();
}
/**
* write version number to db
*/
public function set_version_number() {
update_option( CYBOSM_PLUGIN_PREFIX . '_version_number', CYBOSM_VERSION );
}
/**
* upgrade routine
*/
public function upgrade() {
$current_version = get_option( CYBOSM_PLUGIN_PREFIX . '_version_number' );
// if everything is up to date stop here
if ( CYBOSM_VERSION == $current_version ) {
return; // BREAKPOINT
}
// run the upgrade routine for versions smaller 1.2.0
if ( -1 == version_compare( $current_version, '1.2.0' ) ) {
// add defaults for the print button
$options = get_option( CYBOSM_PLUGIN_PREFIX . '_options' );
$options[ CYBOSM_PLUGIN_PREFIX . '_pt_option' ] = 'off';
update_option( CYBOSM_PLUGIN_PREFIX . '_options', $options );
}
// run the upgrade routine for versions smaller 1.3.0
if ( -1 == version_compare( $current_version, '1.3.0' ) ) {
// add defaults for the print button
$options = get_option( CYBOSM_PLUGIN_PREFIX . '_options' );
$options[ CYBOSM_PLUGIN_PREFIX . '_ig_option' ] = 'off';
$options[ CYBOSM_PLUGIN_PREFIX . '_ig_url' ] = '';
update_option( CYBOSM_PLUGIN_PREFIX . '_options', $options );
}
// set the current version number
$this->set_version_number();
}
/**
* Initialize some custom settings
*/
public function init_options() {
register_setting( CYBOSM_PLUGIN_PREFIX . '_options', CYBOSM_PLUGIN_PREFIX . '_options' );
$this->register_facebook_settings();
$this->register_twitter_settings();
$this->register_instagram_settings();
$this->register_youtube_settings();
$this->register_email_settings();
$this->register_print_settings();
}
/**
* register the facebook settings
*/
public function register_facebook_settings() {
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_facebook_options',
__( 'Facebook', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_fb_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_facebook_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_fb_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'share' => __( 'Share button', 'cybosm' ),
'visit' => __( 'Link to fanpage', 'cybosm' ),
),
)
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_fb_url',
__( 'Link to your fanpage', 'cybosm' ),
array( &$this, 'render_options_url_input' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_facebook_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_fb_url',
)
);
}
/**
* register the twitter settings
*/
public function register_twitter_settings() {
/**
* TWITTER
*/
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_twitter_options',
__( 'Twitter', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_tw_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_twitter_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_tw_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'share' => __( 'Share button', 'cybosm' ),
'visit' => __( 'Link to profile', 'cybosm' ),
)
)
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_tw_url',
__( 'Link to your twitter profile', 'cybosm' ),
array( &$this, 'render_options_url_input' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_twitter_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_tw_url',
)
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_tw_via',
__( 'Username (@example)', 'cybosm' ),
array( &$this, 'render_options_text_input' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_twitter_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_tw_via',
)
);
}
/**
* register the instagram settings
*/
public function register_instagram_settings() {
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_instagram_options',
__( 'Instagram', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_ig_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_instagram_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_ig_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'visit' => __( 'Link to profile', 'cybosm' ),
)
)
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_ig_url',
__( 'Link to your Instagram profile', 'cybosm' ),
array( &$this, 'render_options_url_input' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_instagram_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_ig_url',
)
);
}
/**
* register the youtube settings
*/
public function register_youtube_settings() {
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_youtube_options',
__( 'Youtube', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_yt_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_youtube_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_yt_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'visit' => __( 'Link to chanel', 'cybosm' ),
)
)
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_yt_url',
__( 'Link to your Youtube chanel', 'cybosm' ),
array( &$this, 'render_options_url_input' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_youtube_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_yt_url',
)
);
}
/**
* register the email settings
*/
public function register_email_settings() {
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_email_options',
__( 'Email', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_em_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_email_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_em_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'share' => __( 'Share by email', 'cybosm' ),
)
)
);
}
/**
* register the print settings
*/
public function register_print_settings() {
add_settings_section(
CYBOSM_PLUGIN_PREFIX . '_print_options',
__( 'Print', 'cybosm' ),
array( &$this, 'display_section_description' ),
CYBOSM_PLUGIN_PREFIX . '_options'
);
add_settings_field(
CYBOSM_PLUGIN_PREFIX . '_pt_option',
__( 'Choose the functionality of the button', 'cybosm' ),
array( &$this, 'render_options_radiobuttons' ),
CYBOSM_PLUGIN_PREFIX . '_options',
CYBOSM_PLUGIN_PREFIX . '_print_options',
array(
'id' => CYBOSM_PLUGIN_PREFIX . '_pt_option',
'options' => array(
'off' => __( 'Off', 'cybosm' ),
'print' => __( 'Print', 'cybosm' ),
)
)
);
}
/**
* Render the html for options radiobuttons
*/
public function render_options_radiobuttons( $args ) {
$options = get_option( CYBOSM_PLUGIN_PREFIX . '_options' );
foreach ( $args['options'] as $option_id => $option_title ) {
if ( isset( $options[ $args['id'] ] ) ) {
$checked = checked( $options[ $args['id'] ], $option_id, false );
} else {
$checked = '';
}
echo "<input type='radio' name='".CYBOSM_PLUGIN_PREFIX."_options[{$args['id']}]'".
" class='{$args['id']}' id='{$args['id']}_$option_id' value='$option_id' $checked>$option_title</br>\n";
}
}
/**
* Render the html for options url input
*/
public function render_options_url_input( $args ) {
$options = get_option( CYBOSM_PLUGIN_PREFIX . '_options' );
echo "<input type='url' id='{$args['id']}' name='".CYBOSM_PLUGIN_PREFIX."_options[{$args['id']}]' value='{$options[$args['id']]}'>\n";
}
/**
* Render the html for options text input
*/
public function render_options_text_input( $args ) {
$options = get_option( CYBOSM_PLUGIN_PREFIX . '_options' );
echo "<input type='text' id='{$args['id']}' name='".CYBOSM_PLUGIN_PREFIX."_options[{$args['id']}]' value='{$options[$args['id']]}'>\n";
}
/**
* The description of the $section of the options page
*
* @var string $section name of the section
*/
public function display_section_description( $section ) {
echo sprintf( __( 'Enter your options for the %s button here.', 'cybosm' ), $section['title'] );
}
/**
* Add a menu
*/
public function add_menu() {
add_options_page( __('Cybo Social Sharing Options', 'cybosm'), __('Cybo Social Sharing', 'cybosm'), 'manage_options', CYBOSM_PLUGIN_PREFIX . '_options', array( &$this, 'plugin_options_page' ) );
}
/**
* Menu Callback
*/
public function plugin_options_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.', 'cybosm' ) );
}
// Render the settings template
include CYBOSM_PLUGIN_PATH . '/admin/options.php';
}
/**
* Register and load the widget
*/
public function cybosm_load_widget() {
// load the widget class
require_once CYBOSM_PLUGIN_PATH . '/includes/class-cybosm-widget.php';
// register the widget
register_widget( 'cybosm_widget' );
}
/**
* I18n.
*
* Note: Put the translation in the languages folder in the plugins directory,
* name the translation files like "nameofplugin-lanugage_COUUNTRY.po". Ex: "cybosm-fr_FR.po"
*/
public function i18n() {
$path = dirname( plugin_basename(__FILE__) ) . '/languages';
load_plugin_textdomain( 'cybosm', false, $path );
}
/**
* Add roles on plugin activation
*/
public function add_roles_on_plugin_activation() {
if ( is_multisite() ) {
global $wpdb;
$blogs_list = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ( ! empty( $blogs_list ) ) {
foreach ($blogs_list as $blog) {
switch_to_blog($blog['blog_id']);
$this->add_roles_for_sigle_blog();
restore_current_blog();
}
}
} else {
$this->add_roles_for_sigle_blog();
}
}
/**
* actually adds the roles
*/
private function add_roles_for_sigle_blog() {
foreach( $this->roles as $role ) {
add_role( $role[0], $role[1], $role[2] );
}
}
/**
* Remove roles on plugin deactivation
*/
public function remove_roles_on_plugin_deactivation() {
if ( is_multisite() ) {
global $wpdb;
$blogs_list = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ( ! empty( $blogs_list ) ) {
foreach ($blogs_list as $blog) {
switch_to_blog($blog['blog_id']);
$this->remove_roles_for_sigle_blog();
restore_current_blog();
}
}
} else {
$this->remove_roles_for_sigle_blog();
}
}
/**
* actually removes the roles
*/
private function remove_roles_for_sigle_blog() {
foreach( $this->roles as $role ) {
remove_role( $role[0] );
}
}
/**
* Add capabilities on plugin activation
*/
public function add_capabilities_on_plugin_activation() {
if ( is_multisite() ) {
global $wpdb;
$blogs_list = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ( ! empty( $blogs_list ) ) {
foreach ($blogs_list as $blog) {
switch_to_blog($blog['blog_id']);
$this->add_capabilities_for_single_blog();
restore_current_blog();
}
}
} else {
$this->add_capabilities_for_single_blog();
}
}
/**
* Actually add capabilities
*/
private function add_capabilities_for_single_blog() {
$capabilities = array();
$this->add_plugin_capabilities_for( 'administrator' , $capabilities );
}
/**
* Remove capabilities on plugin deactivation
*/
public function remove_capabilities_on_plugin_deactivation() {
if ( is_multisite() ) {
global $wpdb;
$blogs_list = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ( ! empty( $blogs_list ) ) {
foreach ($blogs_list as $blog) {
switch_to_blog($blog['blog_id']);
$this->remove_capabilities_for_single_blog();
restore_current_blog();
}
}
} else {
$this->remove_capabilities_for_single_blog();
}
}
/**
* Actually remove capabilities
*/
private function remove_capabilities_for_single_blog() {
$capabilities = array();
$this->remove_plugin_capabilities_for( 'administrator' , $capabilities );
}
/**
* Add capabilities
*
* @var string $role_name subject
* @var string|array $capabilities caps to add
*/
public function add_plugin_capabilities_for( $role_name, $capabilities ) {
$role = get_role( $role_name );
foreach ( (array) $capabilities as $capability ) {
$role->add_cap( $capability );
}
}
/**
* Remove capabilities
*
* @var string $role_name subject
* @var string|array $capabilities caps to remove
*/
public function remove_plugin_capabilities_for( $role_name, $capabilities ) {
$role = get_role( $role_name );
foreach ( (array) $capabilities as $capability ) {
$role->remove_cap( $capability );
}
}
/**
* Add tables on plugin activation if they dont exist yet
*/
public function create_tables_on_plugin_activation() {
// dont forget to check if tables dont exist yet
// dont forget to use $this->network_tables and $this->single_blog_tables (with $wpdb->prefix) as table names
}
/**
* Create options on plugin activation it they dont exist yet. Nothing will be overwritten.
*/
public function create_default_options_on_first_plugin_activation() {
// single blog options
if ( is_multisite() ) {
global $wpdb;
$blogs_list = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ( ! empty( $blogs_list ) ) {
foreach ($blogs_list as $blog) {
switch_to_blog($blog['blog_id']);
$this->add_options_for_sigle_blog();
restore_current_blog();
}
}
} else {
$this->add_options_for_sigle_blog();
}
// options for all blogs (network options)
$this->add_site_options();
}
/**
* Actually adds the options. If the option already exists it will simply be skiped.
* So nothing will be overwritten. This function will only add single blog options.
*/
private function add_options_for_sigle_blog() {
foreach( $this->single_blog_options as $option_name => $option_data ) {
add_option( $option_name, $option_data );
}
}
/**
* Actually adds the options. If the option already exists it will simply be skiped.
* So nothing will be overwritten. This function will only add network options.
*/
private function add_site_options() {
foreach( $this->network_options as $option_name => $option_data ) {
add_site_option( $option_name, $option_data );
}
}
/**
* handle short code
*
* @var array $atts provided from WP's add_shortcode() function
* @return string
*/
public function short_code_handler( $atts ) {
$frontend = new Cybosm_Frontend();
return $frontend->process_short_code( $atts );
}
/**
* load ressources (js, css)
*/
public function load_resources() {
foreach ( $this->styles as $style ) {
if ( is_admin() && $style['scope'] == ( 'admin' || 'shared' ) ) {
if ( ! wp_style_is( $style['handle'], 'enqueued' ) ) {
$this->register_style( $style );
wp_enqueue_style( $style['handle'] );
}
}
if ( ! is_admin() && $style['scope'] == ( 'frontend' || 'shared' ) ) {
if ( ! wp_style_is( $style['handle'], 'enqueued' ) ) {
$this->register_style( $style );
wp_enqueue_style( $style['handle'] );
}
}
}
foreach ( $this->scripts as $script ) {
if ( is_admin() && $script['scope'] == ( 'admin' || 'shared' ) ) {
if ( ! wp_script_is( $script['handle'], 'enqueued' ) ) {
$this->register_script( $script );
wp_enqueue_script( $script['handle'] );
}
}
if ( ! is_admin() && $script['scope'] == ( 'frontend' || 'shared' ) ) {
if ( ! wp_script_is( $script['handle'], 'enqueued' ) ) {
$this->register_script( $script );
wp_enqueue_script( $script['handle'] );
}
}
}
}
/**
* register script
*
* @var array $script for params see __construct in Cybosm_Settings
*/
public function register_script( $script ) {
wp_register_script(
$script['handle'],
plugins_url( $script['src'], __FILE__ ),
$script['deps'],
CYBOSM_VERSION,
$script['in_footer']
);
}
/**
* register style
*
* @var array $style for params see __construct in Cybosm_Settings
*/
public function register_style( $style ) {
wp_register_style(
$style['handle'],
plugins_url( $style['src'], __FILE__ ),
$style['deps'],
CYBOSM_VERSION,
$style['media']
);
}
} // END class Cybosm_Main
} // END if ( ! class_exists( 'Cybosm_Main' ) )
if ( class_exists( 'Cybosm_Main' ) ) {
if ( ! is_admin() ) {
require_once( CYBOSM_PLUGIN_PATH . '/includes/class-cybosm-frontend.php' );
}
$cybosm_main = new Cybosm_Main();
}