forked from jbrad/standard
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.php
3864 lines (3123 loc) · 123 KB
/
functions.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
/**
* Standard 3.3
* Standard is a sleek, exacting product designed for uncluttered and sophisticated presentation of your content on desktop and mobile devices.
*
* This file enables core features of Standard including sidebars, menus, post thumbnails, post formats, header, backgrounds, and more.
* Some functions are able to be overridden using child themes. These functions will be wrapped in a function_exists() conditional.
*
* This file is broken in the following areas:
*
* 1. Localization
* 2. Theme Settings
* - Menu Page
* - Global Options
* - Layout Options
* - Social Options
* - Publishing
* - Page Options
* - Options Page
* 3. Features
* 4. Custom Header
* 5. Comments Template
* 6. Stylesheet and JavaScript Sources
* 7. Custom Filters
* 8. Helper Functions
*
* @package Standard
* @since 3.0
* @version 3.3
*
*/
// Define a Standard version. This is used for cache-busting stylesheets, JavaScript, and for serializing the version in the database
define( 'STANDARD_THEME_VERSION', '3.4.0' );
/* ----------------------------------------------------------- *
* Dependencies
* ----------------------------------------------------------- */
include_once( get_template_directory() . '/inc/standard-native-seo.php' );
include_once( get_template_directory() . '/inc/header.favicon.php' );
include_once( get_template_directory() . '/inc/header.google-analytics.php' );
include_once( get_template_directory() . '/inc/header.google-plus.php' );
include_once( get_template_directory() . '/inc/footer.google-custom-search.php' );
include_once( get_template_directory() . '/lib/Standard_Nav_Walker.class.php' );
/* ----------------------------------------------------------- *
* Contents
*
* 1. Localization
* 2. Theme Settings
* - Menu Page
* - Layout Options
* - Social Options
* - Global Options
* - Publishing Options
* - Options Page
* 3. Features
* 4. Custom Header
* 5. Comments Template
* 6. Stylesheet and JavaScript Sources
* 7. Custom Filters
* 8. Helper Functions
* ----------------------------------------------------------- */
/* ----------------------------------------------------------- *
* 1. Localization
* ----------------------------------------------------------- */
/**
* Defines the path to the localization files.
*
* @since 3.0
* @version 3.3
*/
function standard_set_theme_localization() {
load_theme_textdomain( 'standard', get_stylesheet_directory() . '/lang' );
} // set_theme_localization
add_action( 'after_setup_theme', 'standard_set_theme_localization' );
/* ----------------------------------------------------------- *
* 2. Theme Settings
* ----------------------------------------------------------- */
/* ----------------------------- *
* Menu Page
* ----------------------------- */
/**
* Adds the menu page and the submenu options to the WordPress Dashboard.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_menu() {
add_menu_page(
__( 'Standard Options', 'standard' ),
__( 'Standard', 'standard' ),
'administrator',
'theme_options',
'standard_theme_options_display',
get_template_directory_uri() . '/images/icn-standard-small.png',
59
);
add_submenu_page(
'theme_options',
__( 'Global', 'standard' ),
__( 'Global', 'standard' ),
'administrator',
'theme_options&tab=standard_theme_global_options',
'standard_theme_options_display'
);
add_submenu_page(
'theme_options',
__( 'Presentation', 'standard' ),
__( 'Presentation', 'standard' ),
'administrator',
'theme_options&tab=standard_theme_presentation_options',
'standard_theme_options_display'
);
add_submenu_page(
'theme_options',
__( 'Social', 'standard' ),
__( 'Social', 'standard' ),
'administrator',
'theme_options&tab=standard_theme_social_options',
'standard_theme_options_display'
);
add_submenu_page(
'theme_options',
__( 'Publishing', 'standard' ),
__( 'Publishing', 'standard' ),
'administrator',
'theme_options&tab=standard_theme_publishing_options',
'standard_theme_options_display'
);
} // end standard_theme_menu
add_action( 'admin_menu', 'standard_theme_menu' );
/* ----------------------------- *
* Layout Options
* ----------------------------- */
/**
* Provides the default values for the Presentation Options.
*
* @since 3.0
* @version 3.2
*/
function get_standard_theme_default_presentation_options() {
$defaults = array(
'fav_icon' => '',
'contrast' => 'light',
'layout' => 'right_sidebar_layout',
'display_breadcrumbs' => 'always',
'display_featured_images' => 'always'
);
return apply_filters ( 'standard_theme_default_presentation_options', $defaults );
} // end standard_theme_default_presentation_options
/**
* Defines the Presentation Options. Specifically, the sections and the settings. Will also
* create the option if it does not already exist in the database.
*
* @since 3.0
* @version 3.2
*/
function standard_setup_theme_presentation_options() {
// If the layout options don't exist, create them.
if( false == get_option( 'standard_theme_presentation_options' ) ) {
add_option( 'standard_theme_presentation_options', apply_filters( 'standard_theme_default_presentation_options', get_standard_theme_default_presentation_options() ) );
} // end if
// Presentation options (composed of layout and content)
add_settings_section(
'presentation',
'',
'standard_theme_presentation_options_display',
'standard_theme_presentation_options'
);
// Layout
add_settings_section(
'layout',
__( 'Layout and Design', 'standard' ),
'standard_theme_layout_options_display',
'standard_theme_presentation_options'
);
add_settings_field(
'logo',
__( 'Logo', 'standard' ),
'logo_display',
'standard_theme_presentation_options',
'layout'
);
add_settings_field(
'fav_icon',
__( 'Site Icon', 'standard' ),
'fav_icon_display',
'standard_theme_presentation_options',
'layout'
);
add_settings_field(
'contrast',
__( 'Contrast', 'standard' ),
'contrast_display',
'standard_theme_presentation_options',
'layout'
);
add_settings_field(
'left_sidebar_layout',
__( 'Left Sidebar', 'standard' ),
'left_sidebar_presentation_display',
'standard_theme_presentation_options',
'layout',
array(
'option_image_path' => get_template_directory_uri() . '/images/layout-left.gif'
)
);
add_settings_field(
'right_sidebar_layout',
__( 'Right Sidebar', 'standard' ),
'right_sidebar_presentation_display',
'standard_theme_presentation_options',
'layout',
array(
'option_image_path' => get_template_directory_uri() . '/images/layout-right.gif'
)
);
add_settings_field(
'full_width_layout',
__( 'No Sidebar / Full Width', 'standard' ),
'full_width_presentation_display',
'standard_theme_presentation_options',
'layout',
array(
'option_image_path' => get_template_directory_uri() . '/images/layout-full.gif'
)
);
// Content
add_settings_section(
'content',
__( 'Content', 'standard' ),
'standard_theme_content_options_display',
'standard_theme_presentation_options'
);
add_settings_field(
'display_breadcrumbs',
__( 'Display Breadcrumbs', 'standard' ),
'display_breadcrumbs_display',
'standard_theme_presentation_options',
'content'
);
add_settings_field(
'display_featured_images',
__( 'Display Featured Images', 'standard' ),
'display_featured_images_display',
'standard_theme_presentation_options',
'content'
);
register_setting(
'standard_theme_presentation_options',
'standard_theme_presentation_options',
'standard_theme_presentation_options_validate'
);
} // end standard_setup_theme_presentation_options
add_action( 'admin_init', 'standard_setup_theme_presentation_options' );
/**
* Placeholder function for the Presentation Options display function. The section contains
* both Layout Design and Content options each of which are responsible for displaying their own
* own options screen.
*
* This function is required by the Settings API.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_presentation_options_display() {} // end standard_theme_presentation_options_display
/**
* Renders the description for the Layout and Design options.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_layout_options_display() {
echo '<p>' . __( 'This section controls positioning and style elements.', 'standard' ) . '</p>';
} // end standard_theme_layout_display
/**
* Renders the description for the Content options.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_content_options_display() {
echo '<p>' . __( 'This section controls when content elements are displayed.', 'standard' ) . '</p>';
} // end standard_theme_content_display
/**
* Renders the option element for the Site Icon.
*
* @since 3.0
* @version 3.2
*/
function fav_icon_display() {
$options = get_option( 'standard_theme_presentation_options' );
$fav_icon = '';
if( isset( $options['fav_icon'] ) ) {
$fav_icon = $options['fav_icon'];
} // end if
$html = '<div id="fav_icon_preview_container">';
$html .= '<img src="' . $fav_icon . '" id="fav_icon_preview" alt="" />';
$html .= '</div>';
$html .= '<input type="hidden" id="fav_icon" name="standard_theme_presentation_options[fav_icon]" value="' . esc_attr( $fav_icon ) . '" class="media-upload-field" />';
$html .= '<input type="button" class="button" id="upload_fav_icon" value="' . __( 'Upload', 'standard' ) . '"/>';
if( '' != trim( $fav_icon ) ) {
$html .= '<input type="button" class="button" id="delete_fav_icon" value="' . __( 'Delete', 'standard' ) . '"/>';
} // end if
$html .= ' <span class="description">' . __( 'Dimensions: 144px x 144px. Used for favicon and mobile devices.', 'standard' ) . ' <a href="http://docs.8bit.io/standard/admin-panel/presentation/" target="_blank">' . __( 'Learn more', 'standard' ) . '</a>.</span>';
echo $html;
} // end fav_icon_display
/**
* Renders the option element for the Contrast setting.
*
* @since 3.0
* @version 3.2
*/
function contrast_display() {
$options = get_option( 'standard_theme_presentation_options' );
$html = '<select id="contrast" name="standard_theme_presentation_options[contrast]">';
$html .= '<option value="light"' . selected( $options['contrast'], 'light', false ) . '>' . __( 'Light', 'standard' ) . '</option>';
$html .= '<option value="dark"' . selected( $options['contrast'], 'dark', false ) . '>' . __( 'Dark', 'standard' ) . '</option>';
$html .= '</select>';
$html .= ' ';
$html .= '<span class="description">' . __( 'Can be used with <a href="themes.php?page=custom-background">custom backgrounds</a>.', 'standard' ) . '</span>';
echo $html;
} // end contrast_display
/**
* Renders the option element for the Logo.
*
* @since 3.0
* @version 3.2
*/
function logo_display() {
$options = get_option( 'standard_theme_presentation_options' );
$logo = '';
if( isset( $options['logo'] ) ) {
$logo = $options['logo'];
} // end if
$html = '<div id="logo_preview_container">';
$html .= '<img src="' . $logo . '" id="logo_preview" alt="" />';
$html .= '</div><!-- #logo_preview_container -->';
$html .= '<input type="hidden" id="logo" name="standard_theme_presentation_options[logo]" value="' . esc_attr( $logo ) . '" class="media-upload-field" />';
$html .= '<input type="button" class="button" id="upload_logo" value="' . __( 'Upload', 'standard' ) . '"/>';
if( '' != trim( $logo ) ) {
$html .= '<input type="button" class="button" id="delete_logo" value="' . __( 'Delete', 'standard' ) . '"/>';
} // end if
$html .= ' <span class="description">' . __( 'Use an image in place of the <a href="options-general.php">Site Title and Tagline</a>. <a href="themes.php?page=custom-header">Custom Headers</a> are also available.', 'standard' ) . '</span>';
echo $html;
} // end logo_display
/**
* Renders the option element for the Left-Sidebar Layout.
*
* @param array $args The array of options used for rendering the option. Includes a path to the option's image.
* @since 3.0
* @version 3.2
*/
function left_sidebar_presentation_display( $args ) {
$options = get_option( 'standard_theme_presentation_options' );
$html = '<input type="radio" id="standard_theme_left_sidebar_layout" name="standard_theme_presentation_options[layout]" value="left_sidebar_layout"' . checked( 'left_sidebar_layout', $options['layout'], false ) . ' />';
$html .= '<img src="' . esc_url( $args['option_image_path'] ) . '" alt="" />';
echo $html;
} // end left_sidebar_presentation_display
/**
* Renders the option element for the Right-Sidebar Layout.
*
* @param array $args The array of options used for rendering the option. Includes a path to the option's image.
* @since 3.0
* @version 3.2
*/
function right_sidebar_presentation_display( $args ) {
$options = get_option( 'standard_theme_presentation_options' );
$html = '<input type="radio" id="standard_theme_right_sidebar_layout" name="standard_theme_presentation_options[layout]" value="right_sidebar_layout"' . checked( 'right_sidebar_layout', $options['layout'], false ) . ' />';
$html .= '<img src="' . esc_url ( $args['option_image_path'] ) . '" alt="" />';
echo $html;
} // end right_sidebar_presentation_display
/**
* Renders the option element for the Full-Width Layout.
*
* @param array $args The array of options used for rendering the option. Includes a path to the option's image.
* @since 3.0
* @version 3.2
*/
function full_width_presentation_display( $args ) {
$options = get_option( 'standard_theme_presentation_options' );
$html = '<input type="radio" id="standard_theme_full_width_layout" name="standard_theme_presentation_options[layout]" value="full_width_layout"' . checked( 'full_width_layout', $options['layout'], false ) . ' />';
$html .= '<img src="' . esc_url ( $args['option_image_path'] ) . '" alt="" />';
echo $html;
} // end full_width_presentation_display
/**
* Renders the option element for the Breadcrumb.
*
* @since 3.0
* @version 3.2
*/
function display_breadcrumbs_display() {
$options = get_option( 'standard_theme_presentation_options' );
$display_breadcrumbs = '';
if( isset( $options['display_breadcrumbs'] ) ) {
$display_breadcrumbs = $options['display_breadcrumbs'];
} // end if
$html = '<select id="display_breadcrumbs" name="standard_theme_presentation_options[display_breadcrumbs]">';
$html .= '<option value="always"'. selected( $options['display_breadcrumbs'], 'always', false ) . '>' . __( 'Always', 'standard' ) . '</option>';
$html .= '<option value="never"'. selected( $options['display_breadcrumbs'], 'never', false ) . '>' . __( 'Never', 'standard' ) . '</option>';
$html .= '</select>';
$html .= ' <span class="description">' . __( 'SEO experts encourage breadcrumb use. <a href="http://docs.8bit.io/standard/admin-panel/presentation/">Learn more</a>.', 'standard' ) . '</span>';
echo $html;
} // end display_breadcrumbs_display
/**
* Renders the option element for Featured Images.
*
* @since 3.0
* @version 3.2
*/
function display_featured_images_display() {
$options = get_option( 'standard_theme_presentation_options' );
$html = '<select id="display_featured_image" name="standard_theme_presentation_options[display_featured_images]">';
$html .= '<option value="always"'. selected( $options['display_featured_images'], 'always', false ) . '>' . __( 'Always', 'standard' ) . '</option>';
$html .= '<option value="never"'. selected( $options['display_featured_images'], 'never', false ) . '>' . __( 'Never', 'standard' ) . '</option>';
$html .= '<option value="index"'. selected( $options['display_featured_images'], 'index', false ) . '>' . __( 'On index only', 'standard' ) . '</option>';
$html .= '<option value="single-post"'. selected( $options['display_featured_images'], 'single-post', false ) . '>' . __( 'On single posts only', 'standard' ) . '</option>';
$html .= '</select>';
echo $html;
} // end display_featured_images_display
/**
* Sanitization callback for the Layout. Since each of the Layout Options are checkboxes,
* this function loops through the incoming options and verifies they are either empty strings
* or contain the value of '1.'
*
* @param array $input The unsanitized collection of options.
* @return array The collection of sanitized values.
* @since 3.0
* @version 3.2
*/
function standard_theme_presentation_options_validate( $input ) {
$output = array();
foreach( $input as $key => $val ) {
if( isset ( $input[$key] ) ) {
$output[$key] = $input[$key];
} // end if
} // end foreach
return apply_filters( 'standard_theme_presentation_options_validate', $output, $input, get_standard_theme_default_presentation_options() );
} // end standard_theme_presentation_options_validate
/* ----------------------------- *
* Social Options
* ----------------------------- */
/**
* Provides the default values for the Social Options.
*
* @since 3.0
* @version 3.2
*/
function get_standard_theme_default_social_options() {
$defaults = array(
'active-social-icons' => '',
'available-social-icons' => ''
);
return apply_filters ( 'standard_theme_social_options', $defaults );
} // end get_standard_theme_default_social_options
/**
* Defines the Social Options. Specifically, the sections and the settings. Will also
* create the option if it does not already exist in the database.
*
* @since 3.0
* @version 3.2
*/
function standard_setup_theme_social_options() {
// If the theme options don't exist, create them.
if( false == get_option( 'standard_theme_social_options' ) ) {
add_option( 'standard_theme_social_options', apply_filters( 'standard_theme_default_social_options', get_standard_theme_default_social_options() ) );
} // end if
// Look to see if any new icons have been added to the library since the last version of the theme
get_standard_theme_default_social_options();
/* ------------------ Social Networks ------------------ */
add_settings_section(
'social',
'',
'standard_theme_social_options_display',
'standard_theme_social_options'
);
add_settings_field(
'available_social_icons',
__( 'Available Icons', 'standard' ),
'standard_available_icons_display',
'standard_theme_social_options',
'social'
);
add_settings_field(
'active_social_icons',
__( 'Active Icons', 'standard' ),
'standard_active_icons_display',
'standard_theme_social_options',
'social'
);
register_setting(
'standard_theme_social_options',
'standard_theme_social_options',
'standard_theme_social_options_validate'
);
} // end standard_setup_theme_social_options
add_action( 'admin_init', 'standard_setup_theme_social_options' );
/**
* Renders the description for the Social Options page.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_social_options_display() {
_e( 'This section controls social network icons in the site header. Drag, drop, and position desired icons from the Icon Library to the Active Icons area. This section controls social network icons in the site header. Drag, drop, and position desired icons from the Icon Library to the Active Icons area. You can also delete all icons and <a href="javascript:;" id="reset-social-icons" class="ad_delete">restore defaults.</a>', 'standard' );
$html = '<div class="social-icons-wrapper">';
$html .= '<div id="social-icons-active" class="left">';
$html .= '<div class="sidebar-name">';
$html .= '<h3>' . __( 'Active Icons', 'standard' ) . '</h3>';
$html .= '</div><!-- /.sidebar-name -->';
$html .= '<div id="active-icons">';
$html .= '<p class="description">' . __( 'Click an icon to set the full URL.', 'standard' ) . '</p>';
$html .= '<ul id="active-icon-list"></ul>';
$html .= '<div id="active-icon-url" class="hidden">';
$html .= '<label>' . __( 'Icon URL:', 'standard' ) . '</label>';
$html .= '<input type="text" id="social-icon-url" value="" class="icon-url" data-via="" data-url="" />';
$html .= ' <span class="description" id="social-rss-icon-controls">';
$html .= '<a href="http://docs.8bit.io/standard/social" target="_blank">' . __( 'Learn More', 'standard' ) . '</a>';
$html .= '</span><!-- /#social-rss-icon-controls -->';
$html .= '<span id="social-icon-controls">';
$html .= '<input type="button" class="button" id="set-social-icon-url" value="' . __( 'Done', 'standard' ). '" />';
$html .= ' ';
$html .= '<a href="javascript:;" id="cancel-social-icon-url">' . __( 'Cancel', 'standard' ) . '</a>';
$html .= '</span><!-- /#social-icon-controls -->';
$html .= '</div><!-- /#active-icon-url -->';
$html .= '<div id="social-icon-max" class="hidden alert alert-info"><i class="icon icon-warning"></i> ' . __( 'Standard looks best with seven icons or fewer.', 'standard' ) . '</div>';
$html .= '</div><!-- /#active-icons -->';
$html .= '</div><!-- /#social-icons-active -->';
$html .= '<div id="social-icons-available" class="right">';
$html .= '<div class="sidebar-name">';
$html .= '<h3>' . __( 'Icon Library', 'standard' ) . '</h3>';
$html .= '</div><!-- /.sidebar-name -->';
$html .= '<div id="available-icons">';
$html .= '<p class="description">' . __( 'Use native social icons or upload your own.', 'standard' ) . '</p>';
$html .= '<ul id="available-icon-list"></ul>';
$html .= '<div id="delete-icons" class="description"><i class="icon icon-trash"></i><br>' . __( 'Drag social icons here to remove them from your library.', 'standard' ) . '</div>';
$html .= '<div id="social-icons-operations">';
$html .= '<input type="button" class="button" id="upload-social-icon" value="' . __( 'Upload New Icon', 'standard') . '" />';
$html .= '</div><!-- /#social-icons-operations -->';
$html .= '</div><!-- /#available-icons -->';
$html .= '</div><!-- /.social-icons-available -->';
$html .= '<span id="standard-save-social-icons-nonce" class="hidden">' . wp_create_nonce( 'standard_save_social_icons_nonce' ) . '</span>';
$html .= '<span id="standard-wordpress-rss-url" class="hidden">' . esc_url( standard_get_rss_feed_url() ) . '</span>';
$html .= '<span id="standard-reset-social-icons" class="hidden">' . wp_create_nonce( 'standard_reset_social_icons_nonce' ) . '</span>';
$html .= '</div><!-- /.social-icons-wrapper -->';
echo $html;
} // end standard_theme_social_options_display
/**
* Callback function used in the Ajax request for generating the Social Icons.
*
* @since 3.0
* @version 3.2
*/
function standard_save_social_icons( ) {
if( wp_verify_nonce( $_REQUEST['nonce'], 'standard_save_social_icons_nonce' ) && isset( $_POST['updateSocialIcons'] ) ) {
// Manually create the input array of options
$input = array(
'available-social-icons' => $_POST['availableSocialIcons'],
'active-social-icons' => $_POST['activeSocialIcons']
);
if( update_option( 'standard_theme_social_options', standard_theme_social_options_validate( $input ) ) ) {
die( '0' );
} else {
die( '1' );
} // end if/else
} else {
die( '-1' );
} // end if/else
} // end standard_save_social_icons
add_action( 'wp_ajax_standard_save_social_icons', 'standard_save_social_icons' );
/**
* Callback function used in the Ajax request for resetting the Social Icons.
*
* @since 3.0
* @version 3.2
*/
function standard_reset_social_icons( ) {
if( wp_verify_nonce( $_REQUEST['nonce'], 'standard_reset_social_icons_nonce' ) ) {
die( delete_option( 'standard_theme_social_options' ) );
} // end if/else
} // end standard_save_social_icons
add_action( 'wp_ajax_standard_reset_social_icons', 'standard_reset_social_icons' );
/**
* Displays the message for users attempting to delete the core set of social icons.
*
* @since 3.0
* @version 3.2
*/
function standard_delete_social_icons() {
if( wp_verify_nonce( $_REQUEST['nonce'], 'standard-delete-social-icon-nonce' ) ) {
die( standard_display_delete_social_icon_message() );
} // end if
} // end standard_delete_social_icons
add_action( 'wp_ajax_standard_delete_social_icons', 'standard_delete_social_icons' );
/**
* Generates a message to be displayed when the user attempts to delete a social icon.
*
* @since 3.0
* @version 3.2
*/
function standard_display_delete_social_icon_message() {
$html = '<div id="standard-delete-social-icons" class="updated">';
$html .= '<p>';
$html .= __( 'You cannot delete the default set of Standard social icons. <a href="javascript:;" id="standard-hide-delete-social-icon-message">Hide this message.</a>', 'standard' );
$html .= '</p>';
$html .= '</div><!-- /#standard-delete-social-icons -->';
echo $html;
} // end standard_display_delete_social_icon_message
/**
* Renders the available social icon input. This field is hidden and is manipulated by the functionality for powering
* the drag and drop ability of the icons.
*
* @since 3.0
* @version 3.2
*/
function standard_available_icons_display() {
$options = get_option( 'standard_theme_social_options' );
$html = '<input type="text" id="available-social-icons" name="standard_theme_social_options[available-social-icons]" value="' . $options['available-social-icons'] . '" />';
$html .= '<span id="standard-delete-social-icon-nonce" class="">' . wp_create_nonce( 'standard-delete-social-icon-nonce' ) . '</span>';
echo $html;
} // end standard_available_icons_display
/**
* Renders the active social icon input. This field is hidden and is manipulated by the functionality for powering
* the drag and drop ability of the icons.
*
* @since 3.0
* @version 3.2
*/
function standard_active_icons_display() {
$options = get_option( 'standard_theme_social_options' );
echo '<input type="text" id="active-social-icons" name="standard_theme_social_options[active-social-icons]" value="' . $options['active-social-icons'] . '" />';
} // end standard_active_icons_display
/**
* Sanitization callback for the Social Options. Since each of the options are text inputs,
* this function loops through the incoming option and strips all tags and slashes from the value
* before serializing it.
*
* @param array $input The unsanitized collection of options.
* @return array The collection of sanitized values.
* @since 3.0
* @version 3.2
*/
function standard_theme_social_options_validate( $input ) {
$output = $defaults = get_standard_theme_default_social_options();
foreach( $input as $key => $val ) {
if( isset ( $input[$key] ) ) {
$output[$key] = esc_url_raw( strip_tags( stripslashes( $input[$key] ) ) );
} // end if
} // end foreach
return apply_filters( 'standard_theme_social_options_validate', $output, $input, $defaults );
} // end standard_theme_options_validate
/**
* When upgrading to newer versions of Standard, this function looks for any new icons that may exist in the social icons directory.
*
* If so, it will add them to the available icons. It excludes icons that are already active.
*
* If users have uploaded their own icons for ones that we have included, such as LinkedIn or
* SoundCloud then they'll need to 'Restore Defaults' and configure their own.
*
* @since 3.1
* @version 3.1
*/
function standard_find_new_social_icons() {
// Be sure to look for any additional social icons
$social_options = get_option( 'standard_theme_social_options' );
if( $handle = opendir( get_template_directory() . '/images/social/small' ) ) {
$available_icons = '';
while( false != ( $filename = readdir( $handle ) ) ) {
// If we're not looking at the current directory, the directory above, or DS_Store...
if( '.' != $filename && '..' != $filename && '.ds_store' != strtolower( $filename) ) {
// Get the icons filename
$new_icon_filename = '/images/social/small/' . $filename . ';';
// Now if this filename is not found in the active icons, we'll add it
if( ! is_numeric ( strpos( $social_options['active-social-icons'], substr($new_icon_filename, 0, strlen( $new_icon_filename ) - 1) ) ) ) {
$available_icons .= get_template_directory_uri() . $new_icon_filename;
} // end if
} // end if
} // end while
// Set the new icons
$social_options['available-social-icons'] = $available_icons;
// Update the option
update_option( 'standard_theme_social_options', $social_options );
} // end if
} // end standard_find_new_social_icons
/* ----------------------------- *
* Global Options
* ----------------------------- */
/**
* Provides the default values for the Global Options.
*
* @since 3.0
* @version 3.2
*/
function get_standard_theme_default_global_options() {
$defaults = array(
'site_mode' => 'online',
'feedburner_url' => '',
'google_analytics' => '',
'offline_display_message' => __( 'Our site is currently offline.', 'standard' )
);
return apply_filters ( 'standard_theme_default_global_options', $defaults );
} // end get_standard_theme_default_global_options
/**
* Defines the Global Options. Specifically, the sections and the settings. Will also
* create the option if it does not already exist in the database.
*
* @since 3.0
* @version 3.2
*/
function standard_setup_theme_global_options() {
// If the theme options don't exist, create them.
if( false == get_option( 'standard_theme_global_options' ) ) {
add_option( 'standard_theme_global_options', apply_filters( 'standard_theme_default_global_options', get_standard_theme_default_global_options() ) );
} // end if
/* ------------------ Page Options ------------------ */
add_settings_section(
'global',
'',
'standard_theme_global_options_display',
'standard_theme_global_options'
);
add_settings_field(
'feedburner_url',
__( 'FeedBurner URL', 'standard' ),
'feedburner_url_display',
'standard_theme_global_options',
'global'
);
add_settings_field(
'google_analytics',
__( 'Google Analytics', 'standard' ),
'google_analytics_display',
'standard_theme_global_options',
'global'
);
add_settings_field(
'site_mode',
__( 'Site Mode', 'standard' ),
'site_mode_display',
'standard_theme_global_options',
'global'
);
add_settings_field(
'offline_message',
__( 'Offline Message', 'standard' ),
'offline_message_display',
'standard_theme_global_options',
'global'
);
register_setting(
'standard_theme_global_options',
'standard_theme_global_options',
'standard_theme_global_options_validate'
);
} // end standard_setup_theme_global_options
add_action( 'admin_init', 'standard_setup_theme_global_options' );
/**
* Renders the description for the Global Options page.
*
* @since 3.0
* @version 3.2
*/
function standard_theme_global_options_display() {
$html = '<h3>' . __( 'Site Configuration ', 'standard' ) . '</h3>';
$html .= '<p>' . __( 'This section controls site wide features.', 'standard' ) . '</p>';
echo $html;
} // end standard_theme_global_options_display
/**
* Renders the option element for FeedBurner.
*
* @since 3.0
* @version 3.2
*/
function feedburner_url_display() {
$option = get_option( 'standard_theme_global_options' );
// Only render this option for administrators
if( current_user_can( 'manage_options' ) ) {
$feedburner_url = '';
if( true == isset ( $option['feedburner_url'] ) ) {
$feedburner_url = $option['feedburner_url'];
} // end if
$html = '<input type="text" id="feedburner_url" name="standard_theme_global_options[feedburner_url]" placeholder="http://feeds.feedburner.com/example" value="' . esc_attr( $feedburner_url ) . '" />';
$html .= ' <span class="description">' . __( 'Use in place of the native RSS feed.', 'standard' ) . '</span>';
echo $html;
} // end if/else
} // end google_analytics_display
/**
* Renders the option element for Google Analytics.
*
* @since 3.0
* @version 3.2
*/
function google_analytics_display() {
$option = get_option( 'standard_theme_global_options' );
// Only render this option for administrators
if( current_user_can( 'manage_options' ) ) {
$analytics_id = '';
if( true == isset ( $option['google_analytics'] ) ) {
$analytics_id = $option['google_analytics'];
} // end if
$html = '<input type="text" id="google_analytics" name="standard_theme_global_options[google_analytics]" placeholder="UA-000000" value="' . esc_attr( $analytics_id ) . '" />';
$html .= ' <span class="description">' . __( 'Enter the ID only.', 'standard' ) . '</span>';
echo $html;
} // end if/else
} // end google_analytics_display
/**
* Renders the option element for activating Offline Mode.