-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-controls.php
1318 lines (1253 loc) · 47 KB
/
custom-controls.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
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Yourseobook Customizer Custom Controls
*
*/
if ( class_exists( 'WP_Customize_Control' ) ) {
/**
* Custom Control Base Class
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Custom_Control extends WP_Customize_Control {
protected function get_yourseobook_resource_url() {
if( strpos( wp_normalize_path( __DIR__ ), wp_normalize_path( WP_PLUGIN_DIR ) ) === 0 ) {
// We're in a plugin directory and need to determine the url accordingly.
return plugin_dir_url( __DIR__ );
}
return trailingslashit( get_template_directory_uri() );
}
}
/**
* Custom Section Base Class
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Custom_Section extends WP_Customize_Section {
protected function get_yourseobook_resource_url() {
if( strpos( wp_normalize_path( __DIR__ ), wp_normalize_path( WP_PLUGIN_DIR ) ) === 0 ) {
// We're in a plugin directory and need to determine the url accordingly.
return plugin_dir_url( __DIR__ );
}
return trailingslashit( get_template_directory_uri() );
}
}
/**
* Image Checkbox Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Image_Checkbox_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'image_checkbox';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="image_checkbox_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<?php $chkboxValues = explode( ',', esc_attr( $this->value() ) ); ?>
<input type="hidden" id="<?php echo esc_attr( $this->id ); ?>" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" class="customize-control-multi-image-checkbox" <?php $this->link(); ?> />
<?php foreach ( $this->choices as $key => $value ) { ?>
<label class="checkbox-label">
<input type="checkbox" name="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( in_array( esc_attr( $key ), $chkboxValues ), 1 ); ?> class="multi-image-checkbox"/>
<img src="<?php echo esc_attr( $value['image'] ); ?>" alt="<?php echo esc_attr( $value['name'] ); ?>" title="<?php echo esc_attr( $value['name'] ); ?>" />
</label>
<?php } ?>
</div>
<?php
}
}
/**
* Text Radio Button Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Text_Radio_Button_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'text_radio_button';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="text_radio_button_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<div class="radio-buttons" style="width:100%;">
<?php foreach ( $this->choices as $key => $value ) { ?>
<label class="radio-button-label">
<input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php $this->link(); ?> <?php checked( esc_attr( $key ), $this->value() ); ?>/>
<span><?php echo esc_attr( $value ); ?></span>
</label>
<?php } ?>
</div>
</div>
<?php
}
}
/**
* Image Radio Button Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Image_Radio_Button_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'image_radio_button';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="image_radio_button_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<?php foreach ( $this->choices as $key => $value ) { ?>
<label class="radio-button-label">
<input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php $this->link(); ?> <?php checked( esc_attr( $key ), $this->value() ); ?>/>
<img src="<?php echo esc_attr( $value['image'] ); ?>" alt="<?php echo esc_attr( $value['name'] ); ?>" title="<?php echo esc_attr( $value['name'] ); ?>" />
</label>
<?php } ?>
</div>
<?php
}
}
/**
* Single Accordion Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Single_Accordion_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'single_accordion';
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'target' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'i' => array(
'class' => array()
),
);
?>
<div class="single-accordion-custom-control">
<div class="single-accordion-toggle"><?php echo esc_html( $this->label ); ?><span class="accordion-icon-toggle dashicons dashicons-plus"></span></div>
<div class="single-accordion customize-control-description">
<?php
if ( is_array( $this->description ) ) {
echo '<ul class="single-accordion-description">';
foreach ( $this->description as $key => $value ) {
echo '<li>' . $key . wp_kses( $value, $allowed_html ) . '</li>';
}
echo '</ul>';
}
else {
echo wp_kses( $this->description, $allowed_html );
}
?>
</div>
</div>
<?php
}
}
/**
* Simple Notice Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Simple_Notice_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'simple_notice';
/**
* Render the control in the customizer
*/
public function render_content() {
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'target' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'i' => array(
'class' => array()
),
'span' => array(
'class' => array(),
),
'code' => array(),
);
?>
<div class="simple-notice-custom-control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo wp_kses( $this->description, $allowed_html ); ?></span>
<?php } ?>
</div>
<?php
}
}
/**
* Slider Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Slider_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'slider_control';
/**
* Enqueue our scripts and styles
*/
// /public_html/wp-content/themes/yourseobook/inc/assets/js/customizer.js
public function enqueue() {
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js');
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css');
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="slider-custom-control">
<span class="customize-control-title">
<?php echo esc_html( $this->label ); ?></span>
<input type="number" id="<?php echo esc_attr( $this->id ); ?>" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" class="customize-control-slider-value" <?php $this->link(); ?> />
<div class="slider" slider-min-value="<?php echo esc_attr( $this->input_attrs['min'] ); ?>" slider-max-value="<?php echo esc_attr( $this->input_attrs['max'] ); ?>" slider-step-value="<?php echo esc_attr( $this->input_attrs['step'] ); ?>">
</div><span class="slider-reset dashicons dashicons-image-rotate" slider-reset-value="<?php echo esc_attr( $this->value() ); ?>"></span>
</div>
<?php
}
}
/**
* Toggle Switch Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Toggle_Switch_Custom_control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'toggle_switch';
/**
* Enqueue our scripts and styles
*/
public function enqueue(){
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content(){
?>
<div class="toggle-switch-control">
<div class="toggle-switch">
<input type="checkbox" id="<?php echo esc_attr($this->id); ?>" name="<?php echo esc_attr($this->id); ?>" class="toggle-switch-checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?>>
<label class="toggle-switch-label" for="<?php echo esc_attr( $this->id ); ?>">
<span class="toggle-switch-inner"></span>
<span class="toggle-switch-switch"></span>
</label>
</div>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
</div>
<hr>
<?php
}
}
/**
* Sortable Repeater Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Sortable_Repeater_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'sortable_repeater';
/**
* Button labels
*/
public $button_labels = array();
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Merge the passed button labels with our default labels
$this->button_labels = wp_parse_args( $this->button_labels,
array(
'add' => __( 'Add', 'yourseobook' ),
)
);
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js', array( 'jquery', 'jquery-ui-core' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="sortable_repeater_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<input type="hidden" id="<?php echo esc_attr( $this->id ); ?>" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" class="customize-control-sortable-repeater" <?php $this->link(); ?> />
<div class="sortable_repeater sortable">
<div class="repeater">
<input type="text" value="" class="repeater-input"/><span class="dashicons dashicons-sort"></span><a class="customize-control-sortable-repeater-delete" href="#"><span class="dashicons dashicons-no-alt"></span></a>
</div>
</div>
<button class="button customize-control-sortable-repeater-add" type="button"><?php echo $this->button_labels['add']; ?></button>
</div>
<?php
}
}
/**
* Dropdown Select2 Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Dropdown_Select2_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'dropdown_select2';
/**
* The type of Select2 Dropwdown to display. Can be either a single select dropdown or a multi-select dropdown. Either false for true. Default = false
*/
private $multiselect = false;
/**
* The Placeholder value to display. Select2 requires a Placeholder value to be set when using the clearall option. Default = 'Please select...'
*/
private $placeholder = 'Please select...';
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Check if this is a multi-select field
if ( isset( $this->input_attrs['multiselect'] ) && $this->input_attrs['multiselect'] ) {
$this->multiselect = true;
}
// Check if a placeholder string has been specified
if ( isset( $this->input_attrs['placeholder'] ) && $this->input_attrs['placeholder'] ) {
$this->placeholder = $this->input_attrs['placeholder'];
}
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'yourseobook-select2-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/select2.full.min.js', array( 'jquery' ), '4.0.13', true );
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js', array( 'yourseobook-select2-js' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.1', 'all' );
wp_enqueue_style( 'yourseobook-select2-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/select2.min.css', array(), '4.0.13', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
$defaultValue = $this->value();
if ( $this->multiselect ) {
$defaultValue = explode( ' , ', $this->value() );
}
?>
<div class="dropdown_select2_control">
<?php if( !empty( $this->label ) ) { ?>
<label for="<?php echo esc_attr( $this->id ); ?>" class="customize-control-title">
<?php echo esc_html( $this->label ); ?>
</label>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<input type="hidden" id="<?php echo esc_attr( $this->id ); ?>" class="customize-control-dropdown-select2" value="<?php echo esc_attr( $this->value() ); ?>" name="<?php echo esc_attr( $this->id ); ?>" <?php $this->link(); ?> />
<select name="select2-list-<?php echo ( $this->multiselect ? 'multi[]' : 'single' ); ?>" class="customize-control-select2" data-placeholder="<?php echo $this->placeholder; ?>" <?php echo ( $this->multiselect ? 'multiple="multiple" ' : '' ); ?>>
<?php
if ( !$this->multiselect ) {
// When using Select2 for single selection, the Placeholder needs an empty <option> at the top of the list for it to work (multi-selects dont need this)
echo '<option></option>';
}
foreach ( $this->choices as $key => $value ) {
if ( is_array( $value ) ) {
echo '<optgroup label="' . esc_attr( $key ) . '">';
foreach ( $value as $optgroupkey => $optgroupvalue ) {
if( $this->multiselect ){
echo '<option value="' . esc_attr( $optgroupkey ) . '" ' . ( in_array( esc_attr( $optgroupkey ), $defaultValue ) ? 'selected="selected"' : '' ) . '>' . esc_attr( $optgroupvalue ) . '</option>';
}
else{
echo '<option value="' . esc_attr( $optgroupkey ) . '" ' . selected( esc_attr( $optgroupkey ), $defaultValue, false ) . '>' . esc_attr( $optgroupvalue ) . '</option>';
}
}
echo '</optgroup>';
}
else {
if( $this->multiselect ){
echo '<option value="' . esc_attr( $key ) . '" ' . ( in_array( esc_attr( $key ), $defaultValue ) ? 'selected="selected"' : '' ) . '>' . esc_attr( $value ) . '</option>';
}
else{
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $key ), $defaultValue, false ) . '>' . esc_attr( $value ) . '</option>';
}
}
}
?>
</select>
</div>
<?php
}
}
/**
* Dropdown Posts Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Dropdown_Posts_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'dropdown_posts';
/**
* Posts
*/
private $posts = array();
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Get our Posts
$this->posts = get_posts( $this->input_attrs );
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="dropdown_posts_control">
<?php if( !empty( $this->label ) ) { ?>
<label for="<?php echo esc_attr( $this->id ); ?>" class="customize-control-title">
<?php echo esc_html( $this->label ); ?>
</label>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<select name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>" <?php $this->link(); ?>>
<?php
if( !empty( $this->posts ) ) {
foreach ( $this->posts as $post ) {
printf( '<option value="%s" %s>%s</option>',
$post->ID,
selected( $this->value(), $post->ID, false ),
$post->post_title
);
}
}
?>
</select>
</div>
<?php
}
}
// TinyMCE Custom Control
class Yourseobook_TinyMCE_Custom_control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'tinymce_editor';
/**
* Enqueue our scripts and styles
*/
//
public function enqueue(){
//wp_enqueue_script( 'chat-gpt-js', $this->get_yourseobook_resource_url() . 'api/assets/js/chat-gpt.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
wp_enqueue_editor();
}
/**
* Pass our TinyMCE toolbar string to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['yourseobooktinymcetoolbar1'] = isset( $this->input_attrs['toolbar1'] ) ? esc_attr( $this->input_attrs['toolbar1'] ) : 'formatselect bold italic bullist numlist alignleft aligncenter alignright link wp_adv';
$this->json['yourseobooktinymcetoolbar2'] = isset( $this->input_attrs['toolbar2'] ) ? esc_attr( $this->input_attrs['toolbar2'] ) : 'redo undo underline forecolor blockquote outdent indent';
$this->json['yourseobookmediabuttons'] = isset( $this->input_attrs['mediaButtons'] ) && ( $this->input_attrs['mediaButtons'] === true ) ? true : false;
}
/**
* Render the control in the customizer
*/
public function render_content(){
?>
<div class="tinymce-control">
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<textarea id="<?php echo esc_attr( $this->id ); ?>" class="customize-control-tinymce-editor" <?php $this->link(); ?>><?php echo esc_attr( $this->value() ); ?></textarea>
</div>
<?php
}
}
/**
* Google Font Select Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Google_Font_Select_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'google_fonts';
/**
* The list of Google Fonts
*/
private $fontList = false;
/**
* The saved font values decoded from json
*/
private $fontValues = [];
/**
* The index of the saved font within the list of Google fonts
*/
private $fontListIndex = 0;
/**
* The number of fonts to display from the json file. Either positive integer or 'all'. Default = 'all'
*/
private $fontCount = 'all';
/**
* The font list sort order. Either 'alpha' or 'popular'. Default = 'alpha'
*/
private $fontOrderBy = 'alpha';
/**
* Get our list of fonts from the json file
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Get the font sort order
if ( isset( $this->input_attrs['orderby'] ) && strtolower( $this->input_attrs['orderby'] ) === 'popular' ) {
$this->fontOrderBy = 'popular';
}
// Get the list of Google fonts
if ( isset( $this->input_attrs['font_count'] ) ) {
if ( 'all' != strtolower( $this->input_attrs['font_count'] ) ) {
$this->fontCount = ( abs( (int) $this->input_attrs['font_count'] ) > 0 ? abs( (int) $this->input_attrs['font_count'] ) : 'all' );
}
}
$this->fontList = $this->yourseobook_getGoogleFonts( 'all' );
// Decode the default json font value
$this->fontValues = json_decode( $this->value() );
// Find the index of our default font within our list of Google fonts
$this->fontListIndex = $this->yourseobook_getFontIndex( $this->fontList, $this->fontValues->font );
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'yourseobook-select2-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/select2.full.min.js', array( 'jquery' ), '4.0.13', true );
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'inc/assets/js/customizer.js', array( 'yourseobook-select2-js' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.1', 'all' );
wp_enqueue_style( 'yourseobook-select2-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/select2.min.css', array(), '4.0.13', 'all' );
}
/**
* Export our List of Google Fonts to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['yourseobookfontslist'] = $this->fontList;
}
/**
* Render the control in the customizer
*/
public function render_content() {
$fontCounter = 0;
$isFontInList = false;
$fontListStr = '';
if( !empty($this->fontList) ) {
?>
<div class="google_fonts_select_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<input type="hidden" id="<?php echo esc_attr( $this->id ); ?>" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" class="customize-control-google-font-selection" <?php $this->link(); ?> />
<div class="google-fonts">
<select class="google-fonts-list" control-name="<?php echo esc_attr( $this->id ); ?>">
<?php
foreach( $this->fontList as $key => $value ) {
$fontCounter++;
$fontListStr .= '<option value="' . $value->family . '" ' . selected( $this->fontValues->font, $value->family, false ) . '>' . $value->family . '</option>';
if ( $this->fontValues->font === $value->family ) {
$isFontInList = true;
}
if ( is_int( $this->fontCount ) && $fontCounter === $this->fontCount ) {
break;
}
}
if ( !$isFontInList && $this->fontListIndex ) {
// If the default or saved font value isn't in the list of displayed fonts, add it to the top of the list as the default font
$fontListStr = '<option value="' . $this->fontList[$this->fontListIndex]->family . '" ' . selected( $this->fontValues->font, $this->fontList[$this->fontListIndex]->family, false ) . '>' . $this->fontList[$this->fontListIndex]->family . ' (default)</option>' . $fontListStr;
}
// Display our list of font options
echo $fontListStr;
?>
</select>
</div>
<div class="customize-control-description"><?php esc_html_e( 'Select weight & style for regular text', 'yourseobook' ) ?></div>
<div class="weight-style">
<select class="google-fonts-regularweight-style">
<?php
foreach( $this->fontList[$this->fontListIndex]->variants as $key => $value ) {
echo '<option value="' . $value . '" ' . selected( $this->fontValues->regularweight, $value, false ) . '>' . $value . '</option>';
}
?>
</select>
</div>
<div class="customize-control-description"><?php esc_html_e( 'Select weight for', 'yourseobook' ) ?> <italic><?php esc_html_e( 'italic text', 'yourseobook' ) ?></italic></div>
<div class="weight-style">
<select class="google-fonts-italicweight-style" <?php disabled( in_array( 'italic', $this->fontList[$this->fontListIndex]->variants ), false ); ?>>
<?php
$optionCount = 0;
foreach( $this->fontList[$this->fontListIndex]->variants as $key => $value ) {
// Only add options that are italic
if( strpos( $value, 'italic' ) !== false ) {
echo '<option value="' . $value . '" ' . selected( $this->fontValues->italicweight, $value, false ) . '>' . $value . '</option>';
$optionCount++;
}
}
if( $optionCount == 0 ) {
echo '<option value="">Not Available for this font</option>';
}
?>
</select>
</div>
<div class="customize-control-description"><?php esc_html_e( 'Select weight for', 'yourseobook' ) ?> <strong><?php esc_html_e( 'bold text', 'yourseobook' ) ?></strong></div>
<div class="weight-style">
<select class="google-fonts-boldweight-style">
<?php
$optionCount = 0;
foreach( $this->fontList[$this->fontListIndex]->variants as $key => $value ) {
// Only add options that aren't italic
if( strpos( $value, 'italic' ) === false ) {
echo '<option value="' . $value . '" ' . selected( $this->fontValues->boldweight, $value, false ) . '>' . $value . '</option>';
$optionCount++;
}
}
// This should never evaluate as there'll always be at least a 'regular' weight
if( $optionCount == 0 ) {
echo '<option value="">Not Available for this font</option>';
}
?>
</select>
</div>
<input type="hidden" class="google-fonts-category" value="<?php echo $this->fontValues->category; ?>">
</div>
<?php
}
}
/**
* Find the index of the saved font in our multidimensional array of Google Fonts
*/
public function yourseobook_getFontIndex( $haystack, $needle ) {
foreach( $haystack as $key => $value ) {
if( $value->family == $needle ) {
return $key;
}
}
return false;
}
/**
* Return the list of Google Fonts from our json file. Unless otherwise specfied, list will be limited to 30 fonts.
*/
public function yourseobook_getGoogleFonts( $count = 30 ) {
// Google Fonts json generated from https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=YOUR-API-KEY
$fontFile = $this->get_yourseobook_resource_url() . 'inc/app/fonts/json/google-fonts-alphabetical.json';
if ( $this->fontOrderBy === 'alpha' ) {
$fontFile = $this->get_yourseobook_resource_url() . 'inc/app/fonts/json/google-fonts-popularity.json';
}
$request = wp_remote_get( $fontFile );
if( is_wp_error( $request ) ) {
return "";
}
$body = wp_remote_retrieve_body( $request );
$content = json_decode( $body );
if( $count == 'all' ) {
return $content->items;
} else {
return array_slice( $content->items, 0, $count );
}
}
}
/**
* Alpha Color Picker Custom Control
*
* @author Braad Martin <http://braadmartin.com>
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/BraadMartin/components/tree/master/customizer/alpha-color-picker
*/
class Yourseobook_Customize_Alpha_Color_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'alpha-color';
/**
* Add support for palettes to be passed in.
*
* Supported palette values are true, false, or an array of RGBa and Hex colors.
*/
public $palette;
/**
* Add support for showing the opacity value on the slider handle.
*/
public $show_opacity;
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'yourseobook-custom-controls-js', $this->get_yourseobook_resource_url() . 'js/customizer.js', array( 'jquery', 'wp-color-picker' ), '1.0', true );
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'css/customizer.css', array( 'wp-color-picker' ), '1.0', 'all' );
}
/**
* Render the control in the customizer
*/
public function render_content() {
// Process the palette
if ( is_array( $this->palette ) ) {
$palette = implode( '|', $this->palette );
} else {
// Default to true.
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true';
}
// Support passing show_opacity as string or boolean. Default to true.
$show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true';
?>
<label>
<?php // Output the label and description if they were passed in.
if ( isset( $this->label ) && '' !== $this->label ) {
echo '<span class="customize-control-title">' . sanitize_text_field( $this->label ) . '</span>';
}
if ( isset( $this->description ) && '' !== $this->description ) {
echo '<span class="description customize-control-description">' . sanitize_text_field( $this->description ) . '</span>';
} ?>
</label>
<input class="alpha-color-control" type="text" data-show-opacity="<?php echo $show_opacity; ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php $this->link(); ?> />
<?php
}
}
/**
* WPColorPicker Alpha Color Picker Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*
* Props @kallookoo for WPColorPicker script with Alpha Channel support
*
* @author Sergio <https://github.com/kallookoo>
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/kallookoo/wp-q-picker-alpha
*/
class Yourseobook_Alpha_Color_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'wpcolorpicker-alpha-color';
/**
* ColorPicker Attributes
*/
public $attributes = "";
/**
* Color palette defaults
*/
public $defaultPalette = array(
'#ff6900',
'#5886a7',
'#242021',
'#e65100',
'#ef6c00',
'#f57c00',
'#fb8c00',
'#ff9800',
);
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
$this->attributes .= 'data-default-color="' . esc_attr( $this->value() ) . '"';
$this->attributes .= 'data-alpha="true"';
$this->attributes .= 'data-reset-alpha="' . ( isset( $this->input_attrs['resetalpha'] ) ? $this->input_attrs['resetalpha'] : 'true' ) . '"';
$this->attributes .= 'data-custom-width="0"';
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_style( 'yourseobook-custom-controls-css', $this->get_yourseobook_resource_url() . 'inc/assets/css/customizer.css', array(), '1.0', 'all' );
wp_enqueue_script( 'wp-color-picker-alpha', $this->get_yourseobook_resource_url() . 'inc/assets/js/wp-color-picker-alpha.js', array( 'wp-color-picker' ), '1.0', true );
wp_enqueue_style( 'wp-color-picker' );
}
/**
* Pass our Palette colours to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['colorpickerpalette'] = isset( $this->input_attrs['palette'] ) ? $this->input_attrs['palette'] : $this->defaultPalette;
}
/**
* Render the control in the customizer
*/
public function render_content() {
?>
<div class="wpcolorpicker_alpha_color_control">
<?php if( !empty( $this->label ) ) { ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php } ?>
<?php if( !empty( $this->description ) ) { ?>
<span class="customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
<input type="text" class="color-picker"
id="<?php echo esc_attr( $this->id ); ?>" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" class="customize-control-colorpicker-alpha-color" <?php echo $this->attributes; ?>
<?php $this->link(); ?> />
</div>
<hr>
<?php
}
}
/**
* Sortable Pill Checkbox Custom Control
*
* @author Dimitar Krumov <https://seobookpro.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/seobookpro
*/
class Yourseobook_Pill_Checkbox_Custom_Control extends Yourseobook_Custom_Control {
/**
* The type of control being rendered
*/
public $type = 'pill_checkbox';
/**
* Define whether the pills can be sorted using drag 'n drop. Either false or true. Default = false
*/
private $sortable = false;
/**
* The width of the pills. Each pill can be auto width or full width. Default = false
*/
private $fullwidth = false;
/**
* Constructor
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Check if these pills are sortable
if ( isset( $this->input_attrs['sortable'] ) && $this->input_attrs['sortable'] ) {
$this->sortable = true;
}
// Check if the pills should be full width
if ( isset( $this->input_attrs['fullwidth'] ) && $this->input_attrs['fullwidth'] ) {
$this->fullwidth = true;
}
} /**
* Enqueue our scripts and styles