-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclass.splotbox-theme-options.php
More file actions
947 lines (744 loc) · 29.7 KB
/
class.splotbox-theme-options.php
File metadata and controls
947 lines (744 loc) · 29.7 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
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
<?php
// manages all of the theme options
// heavy lifting via http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/
// Revision Oct 27, 2017 as jQuery update killed TAB UI
class splotbox_Theme_Options {
/* Array of sections for the theme options page */
private $sections;
private $checkboxes;
private $settings;
private $section_callbacks;
/* Initialize */
function __construct() {
// This will keep track of the checkbox options for the validate_settings function.
$this->checkboxes = array();
$this->settings = array();
$this->section_callbacks = array();
$this->get_settings();
$this->sections['general'] = __( 'All Settings' );
// create a colllection of callbacks for each section heading
foreach ( $this->sections as $slug => $title ) {
$this->section_callbacks[$slug] = 'display_' . $slug;
}
// enqueue scripts for media uploader
add_action( 'admin_enqueue_scripts', 'splotbox_enqueue_options_scripts' );
add_action( 'admin_menu', array( &$this, 'add_pages' ) );
add_action( 'admin_init', array( &$this, 'register_settings' ) );
if ( ! get_option( 'splotbox_options' ) )
$this->initialize_settings();
}
/* Add page(s) to the admin menu */
public function add_pages() {
$admin_page = add_theme_page( 'Splotbox Options', 'Splotbox Options', 'manage_options', 'splotbox-options', array( &$this, 'display_page' ) );
// documents page, but don't add to menu
$docs_page = add_theme_page( 'Splotbox Documentation', '', 'manage_options', 'splotbox-docs', array( &$this, 'display_docs' ) );
}
/* HTML to display the theme options page */
public function display_page() {
echo '<div class="wrap">
<h2>Splotbox Options</h2>';
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true )
echo '<div class="updated fade"><p>' . __( 'Theme options updated.' ) . '</p></div>';
echo '<form action="options.php" method="post" enctype="multipart/form-data">';
settings_fields( 'splotbox_options' );
echo '<h2 class="nav-tab-wrapper"><a class="nav-tab nav-tab-active" href="?page=splotbox-options">Settings</a>
<a class="nav-tab" href="?page=splotbox-docs">Documentation</a></h2>';
do_settings_sections( $_GET['page'] );
echo '<p class="submit"><input name="Submit" type="submit" class="button-primary" value="' . __( 'Save Changes' ) . '" /></p>
</form>
</div>';
}
/* display documentation in a tab */
public function display_docs() {
// This displays on the "Documentation" using docsify-this to render directly from repo
echo '<div class="wrap">
<h1>Splotbox Documentation</h1>
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="?page=splotbox-options">Settings</a>
<a class="nav-tab nav-tab-active" href="?page=splotbox-docs">Documentation</a></h2>
<p>The most current SPOLOTbox documentation is displayed below (<a href="https://docsify-this.net/?basePath=https://raw.githubusercontent.com/cogdog/splotbox/master/&toc=true" target="_blank">view in a new window</a>). Generated with <a href="https://docsify-this.net/" target="_blank">Docsify This</a>.</p>';
echo '<div class="iframe-container">
<iframe src="https://docsify-this.net/?basePath=https://raw.githubusercontent.com/cogdog/splotbox/master/" title="SPLOTbox Documentation" allowfullscreen><a href="https://docsify-this.net/?basePath=https://raw.githubusercontent.com/cogdog/splotbox/master/&toc=true" target="_blank">View Documentation</a></iframe>
</div>
</div>';
}
/* Define all settings and their defaults */
public function get_settings() {
// for file upload checks
$max_upload_size = round(wp_max_upload_size() / 1000000);
/* General Settings
===========================================*/
// ------- access options
$this->settings['access_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Access and Publishing Controls',
'std' => '',
'type' => 'heading'
);
$this->settings['accesscode'] = array(
'title' => __( 'Access Code' ),
'desc' => __( 'Set code to access the sharing tool; leave blank to allow open access (if you are worried about unwanted content being uploaded to your site, we recommend setting the <strong>Status for New Items</strong> below to <code>draft</code> or <code>Pending</code> so you can moderate submissions)' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
$this->settings['accesshint'] = array(
'title' => __( 'Access Hint' ),
'desc' => __( 'Suggestion if someone cannot guess the code. Not super secure, but hey.' ),
'std' => 'Name of this site (lower the case, Ace!)',
'type' => 'text',
'section' => 'general'
);
$this->settings['pages_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Special Pages Setup',
'std' => 'Choose the pages for special purposes in the SPLOTbox',
'type' => 'heading'
);
// get all pages on site with template for the Sharing Form
$found_pages = get_pages_with_template('page-share.php');
$page_desc = 'Set the Page that should be used for the Sharing form.';
// the function returns an array of id => page title, first item is the menu selection item
if ( count( $found_pages ) > 1 ) {
$page_std = array_keys( $found_pages)[1];
} else {
$trypage = get_page_by_path('share');
if ( $trypage ) {
$page_std = $trypage->ID;
$found_pages = array( 0 => 'Select Page', $page_std => $trypage->post_title );
} else {
$page_desc = 'No pages have been created with the Sharing Form template. This is required to enable access to the writing form. <a href="' . admin_url( 'post-new.php?post_type=page') . '">Create a new Page</a> and under <strong>Page Attributes</strong> select <code>Sharing Form</code> for the Template.';
$page_std = '';
}
}
$this->settings['share_page'] = array(
'section' => 'general',
'title' => __( 'Page For Sharing Form'),
'desc' => $page_desc,
'type' => 'select',
'std' => $page_std,
'choices' => $found_pages
);
// get all pages on site with template for the View by Licebse
$found_pages = get_pages_with_template('page-licensed.php');
$page_desc = 'Set the Page that should be used for viewing content by Rights/Licensing.';
// the function returns an array of id => page title, first item is the menu selection item
if ( count( $found_pages ) > 1 ) {
$page_std = array_keys( $found_pages)[1];
} else {
$trypage = get_page_by_path('licensed');
if ( $trypage ) {
$page_std = $trypage->ID;
$found_pages = array( 0 => 'Select Page', $page_std => $trypage->post_title );
} else {
$page_desc = 'No pages have been created with the Licenses/Rights template. This is required to show a view of items bu the type of reuse licensed applied. <a href="' . admin_url( 'post-new.php?post_type=page') . '">Create a new Page</a> and under <strong>Page Attributes</strong> select <code>Licenses/Rights</code> for the Template.';
$page_std = '';
}
}
$this->settings['licensed_page'] = array(
'section' => 'general',
'title' => __( 'Page For View by License/Rights'),
'desc' => $page_desc,
'type' => 'select',
'std' => $page_std,
'choices' => $found_pages
);
// ------- publish options
$this->settings['publish_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Publish Settings',
'std' => '',
'type' => 'heading'
);
$this->settings['new_item_status'] = array(
'section' => 'general',
'title' => __( 'Status For New Items' ),
'desc' => __( 'Set to draft or pending to moderate submissions (depending what review flow you prefer.' ),
'type' => 'radio',
'std' => 'publish',
'choices' => array(
'publish' => 'Publish immediately',
'pending' => 'Set as pending',
'draft' => 'Keep as draft',
)
);
$this->settings['allow_comments'] = array(
'section' => 'general',
'title' => __( 'Allow Comments?' ),
'desc' => __( 'Enable comments on items.' ),
'type' => 'checkbox',
'std' => 0 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
// ------- media options
// str_replace('^', '', $splotbox_supports)
$extender_support = ( function_exists('splotboxplus_exists') ) ? 'In addition, via the SplotBox Extender plugin, this site also supports <strong>' . str_replace('^', '', implode( ', ', splotboxplus_supports())) . '</strong>.' : '';
$this->settings['media_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Media Support',
'std' => 'The following services are supported by SPLOTbox. Check the ones to make available on the share form. ' . $extender_support,
'type' => 'heading'
);
$this->settings['use_url_entry'] = array(
'section' => 'general',
'title' => __( 'Allow entry of media URLs; disable to only use upload or media record options'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No, hide this field',
'1' => 'Yes for media urls enabled below'
)
);
$this->settings['mtoggle'] = array(
'section' => 'general',
'title' => __( 'Toggle selection' ),
'desc' => __( 'Check for all, uncheck for none' ),
'type' => 'checkbox',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_spark'] = array(
'section' => 'general',
'title' => __( 'Media Sources supported...' ),
'desc' => __( 'Adobe Spark Pages/Videos https://spark.adobe.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_audioboom'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Audioboom https://audioboom.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_flickr'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Flickr photos https://flickr.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_giphy'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Giphy gifs https://giphy.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_archive'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Internet Archive Audio and Video https://archive.org' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_loom'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Loom Screencasts https://loom.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_mixcloud'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Mixcloud Audio https://mixcloud.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_boombox'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Sodaphonic Audio https://sodaphonic.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_audioboom'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Audioboom https://audioboom.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_soundcloud'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Soundcloud Audio https://soundcloud.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_speakerdeck'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Speakerdeck Presentations https://speakerdeck.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_ted'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Ted Talk Video https://ted.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_tiktok'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'TikTok Video https://tiktok.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_vimeo'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Vimeo video https://vimeo.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_vocaroo'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Vocaroo Audio https://vocaroo.com' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['m_youtube'] = array(
'section' => 'general',
'title' => __( '' ),
'desc' => __( 'Youtube video https://youtube.com/' ),
'type' => 'checkbox',
'class' => 'mtype',
'std' => 1 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['use_linked_media'] = array(
'section' => 'general',
'title' => __( 'Allow linking to audio/image files by URL (direct links to <code>.png .jpg .gif</code> for images; <code>.mp3 .m4a .ogg</code> for audio)'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No',
'1' => 'Yes for audio and image URLs',
'2' => 'Yes for image URLs only',
'3' => 'Yes for audio URLs only',
)
);
$this->settings['use_upload_media'] = array(
'section' => 'general',
'title' => __( 'Allow uploads for audio/image files (<code>.png .jpg .gif</code> for images; <code>.mp3 .m4a .ogg</code> for audio'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No',
'1' => 'Yes, allow upload of both audio and image files',
'2' => 'Yes, allow upload of image files only',
'3' => 'Yes, allow upload of audio files only',
)
);
$this->settings['upload_max'] = array(
'title' => __( 'Maximum Upload File Size' ),
'desc' => __( 'Set limit for file uploads in Mb (maximum possible for this site is ' . $max_upload_size . ' Mb).' ),
'std' => $max_upload_size,
'type' => 'text',
'section' => 'general'
);
if ( is_ssl() ) {
$this->settings['use_media_recorder'] = array(
'section' => 'general',
'title' => __( 'Enable HTML5 audio recorder for direct saving to media library. Requires site running under SSL'),
'desc' => '',
'type' => 'radio',
'std' => '0',
'choices' => array (
'0' => 'No',
'1' => 'Yes',
)
);
$this->settings['max_record_time'] = array(
'title' => __( 'Maximum Recording Time' ),
'desc' => __( 'Set time limit for recording (in minutes) ' ),
'std' => 5,
'type' => 'text',
'section' => 'general'
);
}
// ------- sort options
$this->settings['sort_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Item Sorting',
'std' => '',
'type' => 'heading'
);
$this->settings['sort_by'] = array(
'section' => 'general',
'title' => __( 'Sort Items by'),
'desc' => '',
'type' => 'radio',
'std' => 'date',
'choices' => array (
'date' => 'Date Published',
'title' => 'Title',
)
);
$this->settings['sort_direction'] = array(
'section' => 'general',
'title' => __( 'Sort Order'),
'desc' => '',
'type' => 'radio',
'std' => 'DESC',
'choices' => array (
'DESC' => 'Descending',
'ASC' => 'Ascending',
)
);
$this->settings['sort_applies'] = array(
'section' => 'general',
'title' => __( 'Sort Applied To'),
'desc' => '',
'type' => 'radio',
'std' => 'all',
'choices' => array (
'all' => 'All Items',
'front' => 'Front Page Only',
'cat' => 'Categories Only',
'tag' => 'Tags Only',
'tagcat' => 'Categories and Tags'
)
);
// ------- single item display
$this->settings['single_item_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Single Item Display',
'std' => '',
'type' => 'heading'
);
// Options for categories
$this->settings['show_cats'] = array(
'section' => 'general',
'title' => __( 'Show/use categories?'),
'desc' => 'Use categories as options for submission or only for admin use',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No, do not use categories',
'1' => 'Yes, options on share form and display on single item',
'2' => 'Yes, but used only by admin to organize (not on share form)'
)
);
// Build array to hold options for select, an array of post categories
// Walk those cats, store as array index=ID
$all_cats = get_categories('hide_empty=0');
foreach ( $all_cats as $item ) {
$cat_options[$item->term_id] = $item->name;
}
$this->settings['def_cat'] = array(
'section' => 'general',
'title' => __( 'Default Category for New Item'),
'desc' => '',
'type' => 'select',
'std' => get_option('default_category'),
'choices' => $cat_options
);
$this->settings['show_tags'] = array(
'section' => 'general',
'title' => __( 'Show/use tags?'),
'desc' => 'Use tags as options for submission or only for admin use',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No, do not use tags',
'1' => 'Yes, options on share form and display on single item',
'2' => 'Yes, but used only by admin to organize (not on share form)'
)
);
$this->settings['use_caption'] = array(
'section' => 'general',
'title' => __( 'Use description field on submission form and item display?'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No',
'1' => 'Yes, but make it optional',
'2' => 'Yes, and make it required'
)
);
$this->settings['caption_field'] = array(
'section' => 'general',
'title' => __( 'Caption Editing Field'),
'desc' => __( 'Use a plain text entry field or rich text editor.'),
'type' => 'radio',
'std' => 's',
'choices' => array (
's' => 'Simple plain text input field',
'r' => 'Rich text editor'
)
);
$this->settings['use_source'] = array(
'section' => 'general',
'title' => __( 'Use source field (e.g. to provide credit for media) on submission form and item display?'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No',
'1' => 'Yes, but make it optional',
'2' => 'Yes, and make it required'
)
);
// ------- single item display
$this->settings['single_item_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Single Item Display',
'std' => '',
'type' => 'heading'
);
$this->settings['admin_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Admin Settings',
'std' => '',
'type' => 'heading'
);
$this->settings['notify'] = array(
'title' => __( 'Notification Emails' ),
'desc' => __( 'Send notifications to these addresses (separate multiple wth commas). They must have an Editor Role on this site to be able to moderate' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
// ------- licenseing
$this->settings['License and Attribution'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'License and Attribution',
'std' => '',
'type' => 'heading'
);
$this->settings['use_license'] = array(
'section' => 'general',
'title' => __( 'Use rights license on submission form and item display?'),
'desc' => '',
'type' => 'radio',
'std' => '0',
'choices' => array (
'0' => 'No',
'1' => 'Yes, but make it optional',
'2' => 'Yes, and make it required'
)
);
$this->settings['show_attribution'] = array(
'section' => 'general',
'title' => __( 'Cut and Paste Attribution' ),
'desc' => __( 'If license options used, show cut and paste attribution on single item displays?' ),
'type' => 'radio',
'std' => '0',
'choices' => array(
'0' => 'No',
'1' => 'Yes',
)
);
/* Reset
===========================================*/
$this->settings['reset_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'With Great Power Comes...',
'std' => '',
'type' => 'heading'
);
$this->settings['reset_theme'] = array(
'section' => 'general',
'title' => __( 'Reset All Options' ),
'type' => 'checkbox',
'std' => 0,
'class' => 'warning', // Custom class for CSS
'desc' => __( 'Check this box and click "Save Changes" below to reset theme options to their defaults.' )
);
}
public function display_general() {
// section heading for general setttings
echo '<p>These settings manage the behavior and appearance of your SPLOTbox site. See <a href="' . admin_url( 'themes.php?page=splotbox-docs') . '">the documentation</a> for help or visit the <a href="https://github.com/cogdog/splotbox" target="_blank">theme source on GitHub</a>.</p><p>If this kind of stuff has any value to you, please consider supporting me so I can do more!</p><p style="text-align:center"><a href="https://patreon.com/cogdog" target="_blank"><img src="https://cogdog.github.io/images/badge-patreon.png" alt="donate on patreon"></a> <a href="https://paypal.me/cogdog" target="_blank"><img src="https://cogdog.github.io/images/badge-paypal.png" alt="donate on paypal"></a></p> ';
}
public function display_reset() {
// section heading for reset section setttings
}
/* HTML output for individual settings */
public function display_setting( $args = array() ) {
extract( $args );
$options = get_option( 'splotbox_options' );
if ( ! isset( $options[$id] ) && $type != 'checkbox' )
$options[$id] = $std;
elseif ( ! isset( $options[$id] ) )
$options[$id] = 0;
$options['new_types'] = 'New Type Name'; // always reset
$field_class = '';
if ( $class != '' )
$field_class = ' ' . $class;
switch ( $type ) {
case 'heading':
echo '<tr><td colspan="2" class="alternate"><h3>' . $desc . '</h3><p>' . $std . '</p></td></tr>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="splotbox_options[' . $id . ']" value="1" ' . checked( $options[$id], "1", false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="splotbox_options[' . $id . ']">';
foreach ( $choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
echo '</select>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'radio':
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="splotbox_options[' . $id . ']" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
if ( $i < count( $options ) - 1 )
echo '<br />';
$i++;
}
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="splotbox_options[' . $id . ']" placeholder="' . $std . '" rows="5" cols="60">' . format_for_editor( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'medialoader':
echo '<div id="uploader_' . $id . '">';
if ( $options[$id] ) {
$front_img = wp_get_attachment_image_src( $options[$id], 'garfunkel' );
echo '<img id="previewimage_' . $id . '" src="' . $front_img[0] . '" width="640" height="300" alt="default thumbnail" />';
} else {
echo '<img id="previewimage_' . $id . '" src="https://placehold.it/640x300" alt="default header image" />';
}
echo '<input type="hidden" name="splotbox_options[' . $id . ']" id="' . $id . '" value="' . $options[$id] . '" />
<br /><input type="button" class="upload_image_button button-primary" name="_splotbox_button' . $id .'" id="_splotbox_button' . $id .'" data-options_id="' . $id . '" data-uploader_title="Set Default Header Image" data-uploader_button_text="Select Image" value="Set/Change Image" />
</div><!-- uploader -->';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="splotbox_options[' . $id . ']" value="' . esc_attr( $options[$id] ) . '" /> <input type="button" id="showHide" value="Show" /> ';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'text':
default:
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="splotbox_options[' . $id . ']" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' ) {
if ($id == 'def_thumb') $desc .= '<br /><a href="' . $options[$id] . '" target="_blank"><img src="' . $options[$id] . '" style="overflow: hidden;" width="' . $options["index_thumb_w"] . '"></a>';
echo '<br /><span class="description">' . $desc . '</span>';
}
break;
}
}
/**
* Description for Docs section
*
* @since 1.0
*/
public function display_docs_section() {
// This displays on the "Documentation" tab.
include( get_stylesheet_directory() . '/includes/splotbox-theme-options-docs.php');
}
/* Initialize settings to their default values */
public function initialize_settings() {
$default_settings = array();
foreach ( $this->settings as $id => $setting ) {
if ( $setting['type'] != 'heading' )
$default_settings[$id] = $setting['std'];
}
update_option( 'splotbox_options', $default_settings );
}
/* Register settings via the WP Settings API */
public function register_settings() {
register_setting( 'splotbox_options', 'splotbox_options', array ( &$this, 'validate_settings' ) );
foreach ( $this->sections as $slug => $title ) {
add_settings_section( $slug, $title, array( &$this, $this->section_callbacks[$slug] ), 'splotbox-options' );
}
$this->get_settings();
foreach ( $this->settings as $id => $setting ) {
$setting['id'] = $id;
$this->create_setting( $setting );
}
}
/* tool to create settings fields */
public function create_setting( $args = array() ) {
$defaults = array(
'id' => 'default_field',
'title' => 'Default Field',
'desc' => 'This is a default description.',
'std' => '',
'type' => 'text',
'section' => 'general',
'choices' => array(),
'class' => ''
);
extract( wp_parse_args( $args, $defaults ) );
$field_args = array(
'type' => $type,
'id' => $id,
'desc' => $desc,
'std' => $std,
'choices' => $choices,
'label_for' => $id,
'class' => $class
);
if ( $type == 'checkbox' )
$this->checkboxes[] = $id;
add_settings_field( $id, $title, array( $this, 'display_setting' ), 'splotbox-options', $section, $field_args );
}
public function validate_settings( $input ) {
if ( ! isset( $input['reset_theme'] ) ) {
$options = get_option( 'splotbox_options' );
if ( $input['notify'] != $options['notify'] ) {
$input['notify'] = str_replace(' ', '', $input['notify']);
}
foreach ( $this->checkboxes as $id ) {
if ( isset( $options[$id] ) && ! isset( $input[$id] ) )
unset( $options[$id] );
}
// SSL required for media recorder
if ( !is_ssl() ) $input['use_media_recorder'] = 0;
// make sure the max file upload is integer and less than max possible
$max_upload_size = round(wp_max_upload_size() / 1000000);
$input['upload_max'] = min( intval( $input['upload_max'] ), $max_upload_size );
return $input;
}
return false;
}
}
$theme_options = new splotbox_Theme_Options();
function splotbox_option( $option ) {
$options = get_option( 'splotbox_options' );
if ( isset( $options[$option] ) )
return $options[$option];
else
return false;
}
?>