-
Notifications
You must be signed in to change notification settings - Fork 9
/
class.ds106bank-theme-options.php
1127 lines (905 loc) · 38.5 KB
/
class.ds106bank-theme-options.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
// manages all of the theme options
// heavy lifting via http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/
// Revision July 26, 2016 by @cogdog as jQuery update killed TAB UI
class bank106_Theme_Options {
/* Array of sections for the theme options page */
private $sections;
private $checkboxes;
private $settings;
/* Initialize */
function __construct() {
// be styling
$this->styles();
// This will keep track of the checkbox options for the validate_settings function.
$this->checkboxes = array();
$this->settings = array();
// go get ;em
$this->get_settings();
// Sections for the options, always have General and Reset
$this->sections['general'] = __( 'General Settings' );
$this->sections['types'] = __( 'Types of ' . bank106_option( 'pluralthings' ) );
$this->sections['reset'] = __( 'Reset Options to Defaults' );
// 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', 'bank106_enqueue_options_scripts' );
// Do the rest of the set up stuff, Clyde
add_action( 'admin_menu', array( &$this, 'add_pages' ) );
add_action( 'admin_init', array( &$this, 'register_settings' ) );
if ( ! get_option( 'ds106banker_options' ) )
$this->initialize_settings();
}
/* Add page(s) to the admin menu */
public function add_pages() {
// options page added
$admin_page = add_theme_page( 'Bank Options', 'Bank Options', 'manage_options', 'ds106bank-options', array( &$this, 'display_page' ) );
// documents page, but don't add to menu
$docs_page = add_theme_page( 'Bank Documentation', '', 'manage_options', 'ds106bank-docs', array( &$this, 'display_docs' ) );
}
/* HTML to display the theme options page and it's tabs */
public function display_page() {
$settings_headings = array(
'theme_setup' => 'Theme',
'thing_heading' => 'Things',
'examples_heading' => 'Responses',
'thumbnail_heading' => 'Media',
'login_heading' => 'Users',
'cc_heading' => 'Licensing',
'ratings_heading' => 'Ratings',
'notify_heading' => 'Notifications',
'twitter_heading' => 'Twitter',
'syndication_heading' => 'Syndication',
'captcha_heading' => 'Captcha',
'thing_type_heading' => 'Types',
'reset_heading' => 'Reset'
);
$nav = '';
foreach ($settings_headings as $label => $heading) {
$nav .= '<a href="#' . $label . '" class="button-primary">' . $heading . '</a>';
}
echo '<div class="wrap">
<h1>Bank Options</h1><p>' . $nav . '</p>' ;
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ) {
echo '<div class="notice notice-success"><p>' . __( 'Theme options updated.' ) . '</p></div>';
}
echo '<form action="options.php" method="post" enctype="multipart/form-data">';
// set up the settings
settings_fields( 'ds106banker_options' );
// tabbed navigation stuff
echo '<h2 class="nav-tab-wrapper"><a class="nav-tab nav-tab-active" href="?page=ds106bank-options">Settings</a>
<a class="nav-tab" href="?page=ds106bank-docs">Documentation</a></h2>';
// generates all the form stuff, it's like MAGIC
do_settings_sections( $_GET['page'] );
// do not forget a button!
echo '<p class="submit"><input name="Submit" type="submit" class="button-primary" value="' . __( 'Save Changes' ) . '" /></p>
</form><p>' . $nav . '</p>
</div>';
// some extra jQuery suff to make the forms even more spiffier
echo '<script type="text/javascript">
jQuery(document).ready(function($) {
$("input[type=text], textarea").each(function() {
if ($(this).val() == $(this).attr("placeholder") || $(this).val() == "")
$(this).css("color", "#999");
});
$("input[type=text], textarea").focus(function() {
if ($(this).val() == $(this).attr("placeholder") || $(this).val() == "") {
$(this).val("");
$(this).css("color", "#000");
}
}).blur(function() {
if ($(this).val() == "" || $(this).val() == $(this).attr("placeholder")) {
$(this).val($(this).attr("placeholder"));
$(this).css("color", "#999");
}
});
// This will make the "warning" checkbox class really stand out when checked.
// I use it here for the Reset checkbox.
$(".warning").change(function() {
if ($(this).is(":checked"))
$(this).parent().css("background", "#c00").css("color", "#fff").css("fontWeight", "bold");
else
$(this).parent().css("background", "none").css("color", "inherit").css("fontWeight", "normal");
});
});
</script>';
}
/* Insert custom CSS */
public function styles() {
//wp_register_style( 'ds106bank-admin', get_template_directory_uri() . '/ds106bank-options.css' );
//wp_enqueue_style( 'ds106bank-admin' );
}
/* Display documentation in a tab */
public function display_docs() {
// This displays on the "Documentation" tab.
echo '<div class="wrap">
<h1>Bank Options</h1>
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="?page=ds106bank-options">Settings</a>
<a class="nav-tab nav-tab-active" href="?page=ds106bank-docs">Documentation</a></h2>';
// doc tab content in HTML
include( get_template_directory() . '/includes/ds106bank-theme-options-docs.php');
echo '</div>';
}
/* Define all settings and their defaults */
public function get_settings() {
$max_upload_size = round(wp_max_upload_size() / 1000000);
// ---------- tool to make the necessary pages
$this->settings['theme_setup'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Theme Setup',
'std' => 'When first set up or at any time check to <a href="' . admin_url('admin-post.php?action=make_bank_pages') . '" target="_blank" class="button-secondary">Create Theme Specific Pages</a>.',
'type' => 'heading'
);
// Build array to hold options for selecting the page to use for adding new things
$page_options = array( '--' => 'Select Page');
// get pages using the proper template
$all_pages = get_pages(
array( 'meta_key' => '_wp_page_template', 'meta_value' => 'page-add-assignment.php' )
);
if ($all_pages) {
foreach ( $all_pages as $item ) {
$page_options[$item->post_name] = $item->post_title;
}
$page_warning = '';
} else {
$page_warning = ' No pages have been created using this template. One needs to be created to enable this form.';
}
$this->settings['add_thing_form_page'] = array(
'section' => 'general',
'title' => __( 'Page for Adding a New ' . ucfirst( bank106_option( 'thingname' ) )),
'desc' => __( 'Existing page for form to add new ' . bank106_option( 'pluralthings' ) . ' ; one using <strong>Submit Thing Form</strong> as template' . $page_warning ),
'type' => 'select',
'std' => '--',
'choices' => $page_options
);
// Build array to hold options for selecting pages for adding Examples/Tutorials
$page_options = array( '--' => 'Select Page');
// get pages using the proper template
$all_pages = get_pages(
array( 'meta_key' => '_wp_page_template', 'meta_value' => 'page-add-example.php' )
);
if ($all_pages) {
foreach ( $all_pages as $item ) {
$page_options[$item->post_name] = $item->post_title;
}
$page_warning = '';
} else {
$page_warning = ' No pages have been created using this template. One needs to be created to enable this form.';
}
$this->settings['example_form_page'] = array(
'section' => 'general',
'title' => __( 'Page for Adding Responses/Tutorials'),
'desc' => __( 'Existing page for form to add new responses; one using <strong>Submit Response/Tutorial Form</strong> as template' . $page_warning ),
'type' => 'select',
'std' => '--',
'choices' => $page_options
);
// ---------- The Things
$this->settings['thing_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Things in this Bank',
'std' => '',
'type' => 'heading'
);
$this->settings['thingname'] = array(
'title' => __( 'Name for Things in the Bank' ),
'desc' => __( 'What is the name for the kind of thing banked here? Assignment? Challenge? Task? Must be singular and should not contain numbers (0-9) or spaces.' ),
'std' => 'Assignment',
'type' => 'text',
'section' => 'general'
);
$this->settings['pluralthings'] = array(
'title' => __( 'Plural Name for the Things' ),
'desc' => __( 'Usually it\'s as simple as adding an "s" but what if it ends in "y"? Or is some weird Latin word?' ),
'std' => 'Assignments',
'type' => 'text',
'section' => 'general'
);
$this->settings['new_thing_status'] = array(
'section' => 'general',
'title' => __( 'Status For New Things' ),
'desc' => __( 'Set to draft to moderate submissions via web form.' ),
'type' => 'radio',
'std' => 'publish',
'choices' => array(
'publish' => 'Publish immediately',
'draft' => 'Set to draft',
)
);
$this->settings['use_thing_cats'] = array(
'section' => 'general',
'title' => __( 'Use Categories for ' . bank106_option( 'pluralthings' ) ),
'desc' => __( 'Offer another way to organize them across types. You can present available categories on the form to let users assign them, or do it on the back end as a task for site admins.'),
'type' => 'radio',
'std' => '0',
'choices' => array (
'0' => 'No, do not use categories',
'1' => 'Yes, and let ' . bank106_option( 'thingname' ) . ' creators assign categories',
'2' => 'Yes, but leave it for admins to assign categories'
)
);
$this->settings['thing_cat_name'] = array(
'title' => __( 'Label for Category' ),
'desc' => __( 'You can use another label besides the default \'Category\'- it should be singular.' ),
'std' => 'Category',
'type' => 'text',
'section' => 'general'
);
// ---------- example setup options
$this->settings['examples_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Settings for ' . bank106_option( 'thingname' ) . ' Responses and Tutorials',
'std' => '',
'type' => 'heading'
);
$this->settings['show_ex'] = array(
'section' => 'general',
'title' => __( 'Display on Single ' . bank106_option( 'thingname' ) ),
'desc' => __( 'Manage display of associated responses and/or tutorials on single ' . bank106_option( 'thingname' ) . ' view' ),
'type' => 'radio',
'std' => 'both',
'choices' => array(
'both' => 'Responses and Tutorials',
'ex' => 'Responses only',
'tut' => 'Tutorials only',
'none' => 'Neither'
)
);
$this->settings['examples_upload'] = array(
'section' => 'general',
'title' => __( 'Allow Uploads for Responses'),
'desc' => __( 'Enable using file upload to WordPress media library for examples of response; the uploaded URL inserted after upload. Possible impact on site storage limits.'),
'type' => 'radio',
'std' => '1',
'choices' => array (
'1' => 'Yes, allow uploads',
'0' => 'No, do not allow uploads',
)
);
$this->settings['upload_max'] = array(
'title' => __( 'Maximum Upload File Size' ),
'desc' => __( 'Set limit for file uploads in Mb (maxium possible for this site is ' . $max_upload_size . ' Mb).' ),
'std' => $max_upload_size,
'type' => 'text',
'section' => 'general'
);
$this->settings['examplesperview'] = array(
'section' => 'general',
'title' => __( 'Number of Responses to Display at a Time' ),
'desc' => __( 'How many to show per click of \'More\' button. ' . bank106_alm_installed() ),
'std' => '10',
'type' => 'text',
'section' => 'general'
);
$this->settings['link_examples'] = array(
'section' => 'general',
'title' => __( 'Link to Form Submitted Responses'),
'desc' => __( 'Link for responses go to external URLs or show as a full entry on this site '),
'type' => 'radio',
'std' => '0',
'choices' => array (
'1' => 'No, links go to response URL (short summary entry)',
'0' => 'Yes, links go to entry on the bank site (full media editor)',
)
);
$this->settings['example_gen'] = array(
'title' => __( 'Response Form Instructions' ),
'desc' => __( 'Any additional details that should be added to the entry form for every submitted response (' . bank106_option( 'thingname' ) . ' specific instructions can also be added per item).' ),
'std' => '',
'type' => 'textarea',
'section' => 'general'
);
$this->settings['new_example_status'] = array(
'section' => 'general',
'title' => __( 'Status For New Responses' ),
'desc' => __( 'How new responses added are processed when submitted via a form' ),
'type' => 'radio',
'std' => 'draft',
'choices' => array(
'publish' => 'Publish immediately',
'draft' => 'Set to draft',
)
);
$this->settings['helpthingname'] = array(
'title' => __( 'Name for Support Things' ),
'desc' => __( 'What is the name for the kind of support offerings for each Thing? e.g. Tutorial? Resource? Link? This must be singular, and first letter should be capitalized.' ),
'std' => 'Tutorial',
'type' => 'text',
'section' => 'general'
);
// ---------- media- thumbnail sizes, default image
$this->settings['thumbnail_heading'] = array(
'section' => 'general',
'title' => '' ,// Not used for headings.
'desc' => 'Media Settings',
'std' => 'If you change the thumbnail size settings, you will need to regenerate the image sizes to adjust existing media, e.g. by installing the <a href="http://wordpress.org/plugins/regenerate-thumbnails/">Regenerate Thumbnails plugin</a>.',
'type' => 'heading'
);
$this->settings['thumb_w'] = array(
'title' => __( 'Thumbnail Images Width' ),
'desc' => __( 'Width of thumbnail images (in pixels)' ),
'std' => '640',
'type' => 'text',
'section' => 'general'
);
$this->settings['thumb_h'] = array(
'title' => __( 'Thumbnail Images Height' ),
'desc' => __( 'Height of images in pixels' ),
'std' => '480',
'type' => 'text',
'section' => 'general'
);
$this->settings['def_thumb'] = array(
'title' => __( 'Set default ' . lcfirst(bank106_option( 'thingname' )) . ' thumbnail image' ),
'desc' => __( 'This image will be used if none is defined.' ),
'std' => 'Default ' . lcfirst(bank106_option( 'thingname' )) . ' Thumbnail',
'type' => 'medialoader',
'section' => 'general'
);
$this->settings['def_thumb_credits'] = array(
'title' => __( 'Thumbnail Attribution' ),
'desc' => __( 'Credit for default thumbnail (e.g. Creative Commons Attribution). HTML Ok.' ),
'std' => '',
'type' => 'textarea',
'section' => 'general'
);
$this->settings['media_icon'] = array(
'section' => 'general',
'title' => __( 'Embed Media For Icon' ),
'desc' => __( 'Embed example (if embeddable, e.g. YouTube/vimeo video, tweet) as icon on index and archive views' ),
'type' => 'radio',
'std' => '0',
'choices' => array(
'0' => 'No',
'1' => 'Yes'
)
);
// ---------- login options
$this->settings['login_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'User Options',
'std' => '',
'type' => 'heading'
);
$this->settings['use_wp_login'] = array(
'section' => 'general',
'title' => __( 'Use Wordpress accounts for adding responses and/or items to the bank.'),
'desc' => __( 'Option to use and/or require a login for submissions. An individual\'s work can be tracked via <code>' . home_url() . '/author/' . '<username></code>'),
'type' => 'radio',
'std' => '0',
'choices' => array (
'0' => 'Do not use Wordpress logins',
'1' => 'Yes, but make it optional',
'2' => 'Yes, and make it required'
)
);
$this->settings['register_btn_name'] = array(
'title' => __( 'Register Button Label' ),
'desc' => __( 'Text for the button leading to registration info' ),
'std' => 'Register',
'type' => 'text',
'section' => 'general'
);
$this->settings['register_btn_link'] = array(
'title' => __( 'Register Button Link' ),
'desc' => __( 'URL for register button destination, use <strong>#</strong> to deactivate' ),
'std' => '#',
'type' => 'text',
'section' => 'general'
);
$this->settings['user_code_name'] = array(
'section' => 'general',
'title' => __( 'User names on submission forms?'),
'desc' => __( 'Use and/or require a user name with submission (not specifically twitter, just unique), if used will be added as a tag to entries. An individual\'s work can be tracked via <code>' . home_url() . '/exampletags/' . '<username></code>'),
'type' => 'radio',
'std' => '0',
'choices' => array (
'0' => 'No',
'1' => 'Yes, but make it optional',
'2' => 'Yes, and make it required'
)
);
$this->settings['default_user'] = array(
'title' => __( 'Default User' ),
'desc' => __( 'A display name for a user where none is provided.' ),
'std' => 'Anonymous',
'type' => 'text',
'section' => 'general'
);
// ---------- creative commons options
$this->settings['cc_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Apply Creative Commons to Each ' . bank106_option( 'thingname' ),
'std' => '',
'type' => 'heading'
);
$this->settings['use_cc'] = array(
'section' => 'general',
'title' => __( 'Usage Mode' ),
'desc' => __( 'How licenses are applied' ),
'type' => 'radio',
'std' => 'site',
'choices' => array(
'none' => 'No Creative Commons',
'site' => 'Apply one license to every ' . lcfirst(bank106_option( 'thingname' )),
'user' => 'Enable users to choose license when submitting a ' . lcfirst(bank106_option( 'thingname' ))
)
);
$this->settings['cc_site'] = array(
'section' => 'general',
'title' => __( 'License for Every ' . bank106_option( 'thingname' )),
'desc' => __( 'Choose a license that will appear sitewide' ),
'type' => 'select',
'std' => 'by',
'choices' => array(
'0' =>'CC0 Public Domain',
'by' => 'CC BY Attribution',
'by-sa' => 'CC Attribution-ShareAlike',
'by-nd' => 'CC BY-ND Attribution-NoDerivs',
'by-nc' => 'CC BY-NC Attribution-NonCommercial',
'by-nc-sa' => 'CC BY-NC-SA Attribution-NonCommercial-ShareAlike',
'by-nc-nd' => 'CC BY-NC-ND Attribution-NonCommercial-NoDerivs',
)
);
// ---------- rating options
$this->settings['ratings_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => bank106_option( 'thingname' ) . ' Ratings',
'std' => bank106_wp_ratings_installed(),
'type' => 'heading'
);
$this->settings['difficulty_rating'] = array(
'section' => 'general',
'title' => __( 'Allow Author Difficulty Rating' ),
'desc' => __( 'When a new ' . lcfirst(bank106_option( 'thingname' )) . ' is created, author assigns a 1-5 difficulty rating shown on the entry' ),
'type' => 'checkbox',
'std' => 0 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
// ------- email notification options
$this->settings['notify_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Email Notifications',
'std' => 'If the option <strong>Status for New Things</strong> is <code>Publish Immediately</code>, checking a box below will send messages when something new is published; for <code>Save as Draft</code> the notification will alert you to moderate the item.',
'type' => 'heading'
);
$this->settings['notify'] = array(
'title' => __( 'Addresses to Notify' ),
'desc' => __( 'Send notifications to all these email addresses (separate multiple ones wth commas). ' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
$this->settings['notify_things'] = array(
'section' => 'general',
'title' => __( 'Submitted new ' . lcfirst( bank106_option( 'pluralthings' ) ) ),
'desc' => __( 'Notify if moderation required / when published' ),
'type' => 'checkbox',
'std' => 0 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['notify_responses'] = array(
'section' => 'general',
'title' => __( 'Responses to ' . lcfirst( bank106_option( 'pluralthings' ) ) ),
'desc' => __( 'Notify if moderation required / when published' ),
'type' => 'checkbox',
'std' => 0 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
// ------- twitter options
$this->settings['twitter_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Twitter Options',
'std' => '',
'type' => 'heading'
);
$this->settings['show_tweet_button'] = array(
'section' => 'general',
'title' => __( 'Show a Tweet This button on published items?'),
'desc' => '',
'type' => 'radio',
'std' => '1',
'choices' => array (
'0' => 'No',
'1' => 'Yes'
)
);
$this->settings['hashtag'] = array(
'title' => __( 'Twitter Hashtag' ),
'desc' => __( 'Optional to be included on Tweet This buttons (do not include the #!)' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
// ---------- syndication options
$this->settings['syndication_heading'] = array(
'section' => 'general',
'title' => '', // Not used for headings.
'desc' => 'Syndication for Responses',
'std' => 'Choose how/if to use Feed WordPress to aggregate responses from either an internal aggregator on this site or from an external source.',
'type' => 'heading'
);
$this->settings['use_fwp'] = array(
'section' => 'general',
'title' => __( 'Feed Wordpress Mode' ),
'desc' => bank106_fwp_installed() . __( 'See documentation tab for more information on these options.' ),
'type' => 'radio',
'std' => 'none',
'choices' => array(
'none' => 'No syndication. Responses are added only via web form (if enabled above) or only via WordPress Admin.',
'internal' => 'Use a local install of Feed Wordpress to aggregate responses to this site.',
'external' => 'Syndicate from an external site that is already aggregating participant content.',
)
);
// settings only if external syndication mode
$this->settings['extra_tag'] = array(
'title' => __( 'Required Tag' ),
'desc' => __( 'Only used for external syndication option. Tag for responses to be externally syndicated. This will be displayed on each assignment and will also define the feed that needs to be added to local install of Feed WordPress.' ),
'std' => 'bank106',
'type' => 'text',
'section' => 'general'
);
$this->settings['syndication_site_name'] = array(
'title' => __( 'External Syndication Site ' ),
'desc' => __( 'Only used for external syndication option.' ),
'std' => 'Groovy Syndication Site Name',
'type' => 'text',
'section' => 'general'
);
$this->settings['syndication_site_url'] = array(
'title' => __( 'External Syndication Site URL' ),
'desc' => __( 'Only used for external syndication option.' ),
'std' => 'http://',
'type' => 'text',
'section' => 'general'
);
// ---------- captcha options, if we need 'em
$this->settings['captcha_heading'] = array(
'section' => 'general',
'title' => '' ,// Not used for headings.
'desc' => 'Captcha Settings',
'std' => 'To reduce spam activate a captcha for submission forms',
'type' => 'heading'
);
$this->settings['use_captcha'] = array(
'section' => 'general',
'title' => __( 'Use reCaptcha' ),
'desc' => __( 'Activate a google captcha for all submission forms; <a href="https://www.google.com/recaptcha/admin/create" target="_blank">get your access keys</a>' ),
'type' => 'checkbox',
'std' => 0 // Set to 1 to be checked by default, 0 to be unchecked by default.
);
$this->settings['captcha_pub'] = array(
'title' => __( 'reCaptcha Site Key' ),
'desc' => __( '' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
$this->settings['captcha_pri'] = array(
'title' => __( 'reCaptcha Secret Key' ),
'desc' => __( '' ),
'std' => '',
'type' => 'text',
'section' => 'general'
);
// ---------- Types of Things Settings
$this->settings['thing_type_heading'] = array(
'section' => 'types',
'title' => '' ,// Not used for headings.
'desc' => bank106_option( 'type_name' ) . ' Organization',
'std' => 'Identify different types of ' . lcfirst( bank106_option( 'pluralthings' ) ) . ' and how they are ordered in index pages',
'type' => 'heading'
);
$this->settings['type_name'] = array(
'title' => __( 'Label for the Types of Things' ),
'desc' => __( 'Things are organized into groups defined below. What should the name for these? (singular)' ),
'std' => 'Type',
'type' => 'text',
'section' => 'types'
);
// note, this is misnamed, it ought to be "type_order" Sue me.
$this->settings['thing_order'] = array(
'section' => 'types',
'title' => __( 'Type Display Order' ),
'desc' => __( 'On the front page, the order in which types of things are listed' ),
'type' => 'radio',
'std' => 'name',
'choices' => array(
'name' => 'Title',
'id' => 'Date Created',
'count' => 'Count',
)
);
// note, this is misnamed, it ought to be "type_orderny" Sue me again.
$this->settings['thing_orderby'] = array(
'section' => 'types',
'title' => __( 'Type Order Sorting' ),
'desc' => __( 'On the front page, which to list first?' ),
'type' => 'radio',
'std' => 'ASC',
'choices' => array(
'ASC' => 'Ascending',
'DESC' => 'Descending',
)
);
$this->settings['exlen'] = array(
'title' => __( 'Excerpt Length' ),
'desc' => __( 'Number of words to show for the descriptions of the types of things used on the front page and archives.' ),
'std' => '55',
'type' => 'text',
'section' => 'types'
);
$this->settings['type_mod_heading'] = array(
'section' => 'types',
'title' => '' ,// Not used for headings.
'desc' => bank106_option( 'type_name' ) . ' Editing',
'std' => 'Edit names, desciptions, and thumbnail images',
'type' => 'heading'
);
// lets get all the existing assignment types
$assigntypes = get_assignment_types( bank106_option( 'thing_order'), bank106_option( 'thing_orderby') );
$i = 0;
foreach ( $assigntypes as $atype ) {
$i++;
$setting_name = 'thing_type_' . $atype->term_id;
// settings for each type of thing: name, delete option, description, thumbnail
$this->settings["$setting_name"] =
array(
'title' => __( bank106_option( 'thingname' ) . ' Type #' . $i ),
'desc' => __( '' ),
'std' => '',
'type' => 'text',
'section' => 'types'
);
$this->settings['del_' . $setting_name] = array(
'section' => 'types',
'title' => __( 'Delete this Type' ),
'desc' => __( 'Be careful, this cannot be undone!'),
'type' => 'checkbox',
'std' => 0
);
$this->settings[$setting_name . '_descrip' ] =
array(
'title' => __( 'Short Description of this Type' ),
'desc' => __( '' ),
'std' => '',
'type' => 'textarea',
'section' => 'types'
);
$this->settings[$setting_name . '_thumb'] =
array(
'title' => __( ucfirst($atype->name) . ' Thumbnail' ),
'desc' => __( '<hr /><p> </p>' ),
'std' => 'https://place-hold.it' . ( bank106_option('thumb_w') / 2 ) . 'x' . (bank106_option('thumb_h') / 2),
'type' => 'medialoader',
'section' => 'types'
);
}
// ------- field so users can add new types of things
$this->settings['new_type_heading'] = array(
'section' => 'types',
'title' => '', // Not used for headings.
'desc' => 'Create New Types',
'std' => 'Description and thumbnails can be added after saving changes. If one of the same name exists, a repeated name will be ignored.',
'type' => 'heading'
);
$this->settings['new_types'] = array(
'title' => __( 'Names for New Types' ),
'desc' => __( 'Enter new names, one per line' ),
'std' => 'Name of A New Type',
'type' => 'textarea',
'section' => 'types'
);
/* Reset checkbox
===========================================*/
// ------- field so users can add new types of things
$this->settings['reset_heading'] = array(
'section' => 'reset',
'title' => '', // Not used for headings.
'desc' => 'With Great Power Comes...',
'std' => 'Be careful with this powerful checkbox, there is no undoing.',
'type' => 'heading'
);
$this->settings['reset_theme'] = array(
'section' => 'reset',
'title' => __( 'Reset Options' ),
'type' => 'checkbox',
'std' => 0,
'class' => 'warning', // Custom class for CSS
'desc' => __( 'Check this box then click "Save Changes" below to reset all options to their defaults.' )
);
}
public function display_general() {
// section heading for general setttings
echo '<p>These settings manage the behavior and appearance of your Assignment Bank. See <a href="' . admin_url( 'themes.php?page=ds106bank-docs') . '">the documentation</a> for help or visit the <a href="https://github.com/cogdog/ds106bank" 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_types() {
// section heading for assignment type setttings
echo '<p>Add and edit the titles, icons, and descriptions for the types of things in your bank. You can also organize how they are ordered when listed and also change the name of them from "Type" to a more approporiate name for the groups of Things.</p>';
}
public function display_reset() {
// section heading for reset section setttings, none needed
}
/* HTML output for individual settings */
public function display_setting( $args = array() ) {
extract( $args );
$options = get_option( 'ds106banker_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 id="' . $id . '">' . $desc . '</h3><p>' . $std . '</p></td></tr>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="ds106banker_options[' . $id . ']" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="ds106banker_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':
if ( $desc != '' )
echo '<span class="description">' . $desc . '</span><br /><br />';
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="ds106banker_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++;
}
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="ds106banker_options[' . $id . ']" placeholder="' . $std . '" rows="5" style="width:80%">' . format_for_editor( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'medialoader':
if ( strpos ( $options[$id], 'http') !==false ) {
echo '<img id="previewimage_' . $id . '" src="' . $options[$id] . '" width="' . (bank106_option('thumb_w') / 2 ) . '" height="' . (bank106_option('thumb_h') / 2 ) . '" alt="default thumbnail" />';
} else {
echo '<img id="previewimage_' . $id . '" src="https://place-hold.it' . ( bank106_option('thumb_w') / 2 ) . 'x' . (bank106_option('thumb_h') / 2 ) . '" alt="default thumbnail" />';
}
echo '<input type="hidden" name="ds106banker_options[' . $id . ']" id="' . $id . '" value="' . esc_attr( $options[$id] ) . '" />
<br /><input type="button" class="upload_image_button button-primary" name="_ds106banker_button' . $id .'" id="_ds106banker_button' . $id .'" data-options_id="' . $id . '" data-uploader_title="Set ' . bank106_option( 'thingname' ) . ' Thumbnail" data-uploader_button_text="Select Thumbnail" value="Set/Change Thumbnail" />
</div><!-- uploader -->';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<label for="my-text-field">' . $title . '</label><input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="ds106banker_options[' . $id . ']" value="' . esc_attr( $options[$id] ) . '" />';
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="ds106banker_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;
}
}
/* 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( 'ds106banker_options', $default_settings );
}
/* Register settings via the WP Settings API */
public function register_settings() {
register_setting( 'ds106banker_options', 'ds106banker_options', array ( &$this, 'validate_settings' ) );