/
functions.php
1350 lines (1198 loc) · 48.9 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
/**
* Core functions file for the theme. Includes other key files.
*
* @package Suffusion
* @subpackage Functions
*/
if (!defined('SUFFUSION_THEME_VERSION')) {
define('SUFFUSION_THEME_VERSION', '4.6.4');
}
require_once(get_template_directory().'/functions/framework.php');
$suffusion_framework = new Suffusion_Framework();
require_once(get_template_directory().'/admin/theme-definitions.php');
add_action("after_setup_theme", "suffusion_theme_setup");
/**
* Initializing action. If you are creating a child theme and you want to override some of Suffusion's actions/filters etc you
* can add your own action to the hook "after_setup_theme", with a priority > 10 if you want your actions to be executed after
* Suffusion and with priority < 10 if you want your actions executed before.
*
* @return void
*/
function suffusion_theme_setup() {
global $pagenow, $suffusion_unified_options, $suffusion;
suffusion_add_theme_supports();
suffusion_include_files();
suffusion_setup_standard_actions_and_filters();
suffusion_setup_custom_actions_and_filters();
suffusion_setup_skin();
foreach ($suffusion_unified_options as $option => $value) {
global $$option;
$$option = $value;
}
$suffusion = new Suffusion();
$suffusion->init();
if(is_admin() && isset($_GET['activated']) && $pagenow = 'themes.php') {
header('Location: '.admin_url().'themes.php?page=suffusion-options-manager&now-active=true');
}
// Get any translations
// https://developer.wordpress.org/themes/functionality/internationalization/
load_theme_textdomain( 'suffusion', get_template_directory() . '/translation' );
}
/**
* Add support for various theme functions
* @return void
*/
function suffusion_add_theme_supports() {
add_theme_support('post-thumbnails');
add_theme_support('automatic-feed-links');
add_theme_support('title-tag');
// Adding post formats, so that users can assign formats to posts. They will be styled in a later release.
add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));
//Suffusion-specific
add_theme_support('mega-menus');
// Support for page excerpts
add_post_type_support('page', 'excerpt');
// Additional options for Suffusion. This shows the meta box below posts
add_theme_support('suffusion-additional-options');
// Support for native custom headers and backgrounds
global $wp_version;
$header_args = array(
'wp-head-callback' => 'suffusion_header_style',
'admin-head-callback' => 'suffusion_admin_header_style',
'admin-preview-callback' => 'suffusion_admin_header_image',
'random-default' => false,
);
$body_args = array();
$options = get_option('suffusion_options');
$theme_name = suffusion_get_theme_name();
if (!isset($options) || !is_array($options) || $theme_name == 'root') {
$header_args['default-text-color'] = '000';
$header_args['width'] = apply_filters('suffusion_header_image_width', 1000);
$header_args['height'] = apply_filters('suffusion_header_image_height', 55);
$header_args['flex-width'] = false;
$body_args['default-color'] = '444444';
$body_args['default-image'] = '';
}
else {
$defaults = array(
'suf_size_options' => 'custom', // custom || theme
'suf_wrapper_width_type' => 'fixed', // fixed || fluid
'suf_wrapper_width_preset' => '1000', // custom || custom-components
'suf_wrapper_width' => '1000', // if suf_wrapper_width_preset == custom
'suf_main_col_width' => '725', // if suf_wrapper_width_preset == custom-components
'suf_sb_1_width' => '260', // if suf_wrapper_width_preset == custom-components
'suf_sb_2_width' => '260', // if suf_wrapper_width_preset == custom-components
'suf_header_layout_style' => 'theme', // out-hcfull || out-hcalign || out-cfull-halign || in-align
'suf_header_style_setting' => 'theme', // custom
'suf_blog_title_color' => suffusion_evaluate_style('suf_blog_title_color', $theme_name),
'suf_header_height' => '55', // option check: suf_header_style_setting
'suf_body_style_setting' => 'theme', // custom
'suf_body_background_color' => suffusion_evaluate_style('suf_body_background_color', $theme_name),
'suf_body_background_image' => suffusion_evaluate_style('suf_body_background_image', $theme_name, 'empty'),
);
// remove null and empty string values
$options = array_filter($options, fn($value) => (!is_null($value) && $value !== ''));
$options = wp_parse_args((array)$options, $defaults);
if ($options['suf_header_style_setting'] == 'custom') {
$header_args['height'] = $options['suf_header_height'] + 30;
$header_args['default-text-color'] = ltrim($options['suf_blog_title_color'], '#');
}
else {
$header_args['height'] = 55 + 30;
$header_args['default-text-color'] = ltrim(suffusion_evaluate_style("suf_blog_title_color", $theme_name), '#');
}
if ($options['suf_header_layout_style'] == 'theme') {
if ($theme_name == 'minima') {
$options['suf_header_layout_style'] = 'out-cfull-halign';
}
else {
$options['suf_header_layout_style'] = 'in-align';
}
}
if ($options['suf_header_layout_style'] == 'out-cfull-halign') {
$header_args['flex-width'] = true;
}
else {
if ($options['suf_size_options'] == 'theme') {
$header_args['width'] = apply_filters('suffusion_header_image_width', 1000);
$header_args['flex-width'] = false;
}
else {
if ($options['suf_wrapper_width_type'] == 'fixed') {
$header_args['flex-width'] = false;
if ($options['suf_wrapper_width_preset'] != 'custom' && $options['suf_wrapper_width_preset'] != 'custom-components') {
$header_args['width'] = $options['suf_wrapper_width_preset'];
}
else if ($options['suf_wrapper_width_preset'] != 'custom') {
$header_args['width'] = $options['suf_wrapper_width'];
}
else {
$header_args['width'] = $options['suf_main_col_width'] + $options['suf_sb_1_width'] + $options['suf_sb_2_width'];
}
}
else {
$header_args['flex-width'] = true;
}
}
}
if ($options['suf_body_style_setting'] == 'custom') {
$body_args['default-color'] = ltrim($options['suf_body_background_color'], '#');
$body_args['default-image'] = $options['suf_body_background_image'];
}
else {
$body_args['default-color'] = ltrim(suffusion_evaluate_style('suf_body_background_color', $theme_name), '#');
$body_args['default-image'] = suffusion_evaluate_style('suf_body_background_image', $theme_name, 'empty');
}
}
add_theme_support('custom-header', $header_args);
add_theme_support('custom-background', $body_args);
}
/**
* Include other core files. Some files like theme-options.php are included only on demand, because they are too
* heavy for every load.
*
* @return void
*/
function suffusion_include_files() {
global $suffusion_unified_options, $suffusion_interactive_text_fields;
$template_path = get_template_directory();
$suffusion_unified_options = suffusion_get_unified_options();
if (function_exists('icl_t')) {
$suffusion_interactive_text_fields = suffusion_get_interactive_text_fields();
}
include_once ($template_path . '/widgets/suffusion-widgets.php');
$widgets = new Suffusion_Widgets();
$widgets->init();
if (function_exists('icl_t')) {
include_once ($template_path . "/functions/wpml-integration.php");
}
require_once ($template_path . "/suffusion.php");
}
/**
* Adds actions and filters to standard action hooks and filter hooks.
*
* @return void
*/
function suffusion_setup_standard_actions_and_filters() {
add_action('init', 'suffusion_register_jquery');
add_action('init', 'suffusion_register_menus');
// Make sure that the generated CSS is written out to the right option at the end of the load.
add_action('wp_loaded', 'suffusion_update_generated_css', 11);
// Required for WP-MS, 3.0+
add_action('before_signup_form', 'suffusion_pad_signup_form_start');
add_action('after_signup_form', 'suffusion_pad_signup_form_end');
if (!is_admin()) {
add_action('wp_print_styles', 'suffusion_disable_plugin_styles');
}
add_action('custom_header_options', 'suffusion_custom_header_options');
add_action('customize_register', 'suffusion_customize_register');
////// FILTERS - The callbacks are in filters.php
add_filter('extra_theme_headers', 'suffusion_extra_theme_headers');
add_filter('user_contactmethods', 'suffusion_add_user_contact_methods');
add_filter('widget_text', 'do_shortcode');
if (!is_admin()) {
if (current_theme_supports('mega-menus')) {
add_filter('walker_nav_menu_start_el', 'suffusion_mega_menu_walker', 10, 4);
}
add_action('wp_enqueue_scripts', 'suffusion_enqueue_styles');
add_action('wp_enqueue_scripts', 'suffusion_enqueue_scripts');
add_action('wp_head', 'suffusion_add_header_contents');
add_action('wp_head', 'suffusion_print_direct_styles', 11);
add_action('wp_head', 'suffusion_print_direct_scripts', 11);
add_action('wp_head', 'suffusion_create_analytics_contents', 30);
add_action('wp_footer', 'suffusion_add_footer_contents');
add_action('template_redirect', 'suffusion_custom_css_display');
add_filter('get_pages', 'suffusion_replace_page_with_alt_title');
add_filter('wp_list_pages', 'suffusion_js_for_unlinked_pages');
add_filter('wp_list_pages', 'suffusion_remove_a_title_attribute');
add_filter('wp_list_categories', 'suffusion_remove_a_title_attribute');
add_filter('wp_list_bookmarks', 'suffusion_remove_a_title_attribute');
add_filter('query_vars', 'suffusion_new_vars');
add_filter('page_link', 'suffusion_unlink_page', 10, 2);
add_filter('the_content_more_link', 'suffusion_set_more_link');
add_filter('the_content', 'suffusion_pages_link', 8);
add_filter('excerpt_more', 'suffusion_excerpt_more_replace');
add_filter('the_excerpt', 'suffusion_excerpt_more_append');
add_filter('comment_reply_link', 'suffusion_hide_reply_link_for_pings', 10, 4);
add_filter('get_comments_number', 'suffusion_filter_trk_ping_from_count');
add_filter('get_comments_pagenum_link', 'suffusion_append_comment_type');
add_filter('style_loader_tag', 'suffusion_filter_rounded_corners_css', 10, 2);
add_filter('style_loader_tag', 'suffusion_filter_ie_css', 10, 2);
add_filter('post_class', 'suffusion_extra_post_classes');
add_filter('nav_menu_css_class', 'suffusion_mm_nav_css', 10, 3);
add_filter('body_class', 'suffusion_get_body_classes', 10, 2);
add_filter('body_class', 'suffusion_get_width_classes', 10, 2);
add_filter('pre_get_posts', 'suffusion_custom_taxonomy_contents');
add_filter('wp_title', 'suffusion_modify_title', 10, 3);
}
}
/**
* Adds actions and filters to custom action hooks and filter hooks.
*
* @return void
*/
function suffusion_setup_custom_actions_and_filters() {
///// ACTIONS
add_action('suffusion_document_header', 'suffusion_include_responsive_meta');
add_action('suffusion_document_header', 'suffusion_include_favicon');
add_action('suffusion_document_header', 'suffusion_include_default_feed');
add_action('suffusion_before_begin_wrapper', 'suffusion_display_open_header');
add_action('suffusion_after_begin_wrapper', 'suffusion_display_closed_header');
add_action('suffusion_after_begin_wrapper', 'suffusion_print_widget_area_below_header');
add_action('suffusion_page_header', 'suffusion_display_header');
add_action('suffusion_page_header', 'suffusion_display_main_navigation');
add_action('suffusion_before_begin_content', 'suffusion_build_breadcrumb');
add_action('suffusion_before_begin_content', 'suffusion_featured_posts');
add_action('suffusion_after_begin_content', 'suffusion_template_specific_header');
add_action('suffusion_content', 'suffusion_excerpt_or_content');
add_action('suffusion_after_begin_post', 'suffusion_print_post_page_title');
add_action('suffusion_after_begin_post', 'suffusion_print_post_format_icon');
add_action('suffusion_after_begin_post', 'suffusion_print_post_updated_information');
add_action('suffusion_after_begin_post', 'suffusion_print_line_byline_top');
add_action('suffusion_after_content', 'suffusion_meta_pullout');
add_action('suffusion_before_end_post', 'suffusion_author_information');
add_action('suffusion_before_end_post', 'suffusion_post_footer');
add_action('suffusion_before_end_post', 'suffusion_print_line_byline_bottom');
add_action('suffusion_before_post', 'suffusion_start_outer_pullout_div', 8, 3);
add_action('suffusion_after_post', 'suffusion_print_outer_pullout', 12, 3);
add_action('suffusion_after_post', 'suffusion_close_outer_pullout_div', 15, 3);
add_action('suffusion_before_end_content', 'suffusion_pagination');
// Print sidebars
add_action('suffusion_before_end_container', 'suffusion_print_left_sidebars');
add_action('suffusion_before_end_container', 'suffusion_print_right_sidebars');
add_action('suffusion_after_end_container', 'suffusion_print_widget_area_above_footer');
add_action('suffusion_page_footer', 'suffusion_display_footer');
add_action('suffusion_document_footer', 'suffusion_include_custom_js');
add_action('suffusion_skin_setup_photonique', 'suffusion_skin_setup_specific');
add_action('suffusion_skin_setup_scribbles', 'suffusion_skin_setup_specific');
///// FILTERS
add_filter('suffusion_can_display_attachment', 'suffusion_filter_attachment_display', 10, 4);
add_filter('suffusion_left_sidebar_count', 'suffusion_get_sidebar_count_for_view', 10, 3);
add_filter('suffusion_right_sidebar_count', 'suffusion_get_sidebar_count_for_view', 10, 3);
add_filter('suffusion_after_comment_form', 'suffusion_allowed_html_tags');
}
function suffusion_setup_skin() {
global $suffusion_theme_name;
if (isset($suffusion_theme_name)) {
do_action("suffusion_skin_setup_{$suffusion_theme_name}");
}
}
function suffusion_skin_setup_specific() {
add_action('wp_enqueue_scripts', 'suffusion_enqueue_skin_scripts');
}
function suffusion_enqueue_skin_scripts() {
global $suffusion_theme_name;
if (isset($suffusion_theme_name) && $suffusion_theme_name == 'photonique') {
wp_enqueue_style('suffusion-skin-fonts', "https://fonts.googleapis.com/css?family=Quattrocento", array(), null);
}
else if (isset($suffusion_theme_name) && $suffusion_theme_name == 'scribbles') {
wp_enqueue_style('suffusion-skin-fonts', "https://fonts.googleapis.com/css?family=Coming+Soon", array(), null);
}
}
function suffusion_admin_check_integer($val) {
if (substr($val, 0, 1) == '-') {
$val = substr($val, 1);
}
return (preg_match('/^\d*$/', $val) == 1);
}
function suffusion_admin_get_size_from_field($val, $default, $allow_blank = true, $offset = 0) {
$ret = $default;
if (substr(trim($val), -2) == "px") {
$test_str = trim(substr(trim($val), 0, strlen(trim($val)) - 2));
if (suffusion_admin_check_integer($test_str)) {
$test_str = (int)$test_str;
$test_str = $test_str + $offset;
$ret = $test_str."px";
}
}
else if (suffusion_admin_check_integer(trim($val))) {
if (!$allow_blank) {
if (trim($val) != '') {
$test_str = (int)trim($val);
$test_str = $test_str + $offset;
$ret = $test_str."px";
}
}
else {
$test_str = (int)trim($val);
$test_str = $test_str + $offset;
$ret = $test_str."px";
}
}
return $ret;
}
function suffusion_get_numeric_size_from_field($val, $default) {
$ret = $default;
if (substr(trim($val), -2) == "px") {
$test_str = trim(substr(trim($val), 0, strlen(trim($val)) - 2));
if (suffusion_admin_check_integer($test_str)) {
$ret = (int)$test_str;
}
}
else if (suffusion_admin_check_integer(trim($val))) {
$ret = (int)(trim($val));
}
return $ret;
}
function suffusion_tab_array_prepositions() {
global $suffusion_sidebar_tabs;
$ret = array();
foreach ($suffusion_sidebar_tabs as $key => $value) {
$ret[$key] = $value['title'];
}
return $ret;
}
function suffusion_entity_prepositions($entity_type = 'nav') {
if ($entity_type == 'nav') {
$ret = array('pages' => 'Pages', 'categories' => 'Categories', 'links' => 'Links');
$menus = wp_get_nav_menus();
if ($menus == null) {
$menus = array();
}
foreach ($menus as $menu) {
$ret["menu-".$menu->term_id] = $menu->name;
}
}
else if ($entity_type == 'nr') {
$ret = array('current' => 'Currently Reading', 'unread' => 'Not Yet Read', 'completed' => 'Completed');
}
else if ($entity_type == 'mag-layout') {
$ret = array('headlines' => 'Headlines', 'excerpts' => 'Excerpts', 'categories' => 'Categories');
}
else if ($entity_type == 'thumb-mag-excerpt' || $entity_type == 'thumb-excerpt' || $entity_type == 'thumb-mag-headline' || $entity_type == 'thumb-tiles') {
$ret = array('native' => 'Native WP 3.0 featured image', 'custom-thumb' => 'Image specified through custom thumbnail field',
'attachment' => 'Image attached to the post', 'embedded' => 'Embedded URL in post', 'custom-featured' => 'Image specified through custom Featured Image field');
}
else if ($entity_type == 'thumb-featured') {
$ret = array('custom-featured' => 'Image specified through custom Featured Image field', 'native' => 'Native WP 3.0 featured image', 'custom-thumb' => 'Image specified through custom thumbnail field',
'attachment' => 'Image attached to the post', 'embedded' => 'Embedded URL in post');
}
else if ($entity_type == 'sitemap') {
global $suffusion_sitemap_entities;
$ret = array();
foreach ($suffusion_sitemap_entities as $entity => $entity_options) {
$ret[$entity] = $entity_options['title'];
}
}
return $ret;
}
function suffusion_get_unified_options() {
global $suffusion_unified_options, $suffusion_default_theme_name;
$suffusion_unified_options = get_option('suffusion_options');
if (!isset($suffusion_unified_options) || !is_array($suffusion_unified_options)) {
// Regenerate the options
$suffusion_unified_options = suffusion_default_options();
$suffusion_unified_options['theme-version'] = SUFFUSION_THEME_VERSION;
$suffusion_unified_options['option-date'] = date(get_option('date_format').' '.get_option('time_format'));
$save = true;
}
else if (!isset($suffusion_unified_options['theme-version']) ||
(isset($suffusion_unified_options['theme-version']) && $suffusion_unified_options['theme-version'] != SUFFUSION_THEME_VERSION) ||
!isset($suffusion_unified_options['option-date'])) {
$default_options = suffusion_default_options();
$suffusion_unified_options = array_merge($default_options, $suffusion_unified_options);
$suffusion_unified_options['theme-version'] = SUFFUSION_THEME_VERSION;
$suffusion_unified_options['option-date'] = date(get_option('date_format').' '.get_option('time_format'));
$save = true;
}
$template_path = get_template_directory();
$stylesheet_path = get_stylesheet_directory();
$suffusion_theme_name = suffusion_get_theme_name();
if ($suffusion_theme_name == 'root') {
$skin = $suffusion_default_theme_name;
}
else {
$skin = $suffusion_theme_name;
}
if (file_exists($stylesheet_path . "/skins/$skin/settings.php")) {
include_once($stylesheet_path . "/skins/$skin/settings.php");
}
else if (file_exists($template_path . "/skins/$skin/settings.php")) {
include_once($template_path . "/skins/$skin/settings.php");
}
if (isset($skin_settings) && is_array($skin_settings)) {
foreach ($skin_settings as $key => $value) {
if (!isset($suffusion_unified_options[$key]) || (isset($suffusion_unified_options[$key]) && $suffusion_unified_options[$key] == 'theme')) {
$suffusion_unified_options[$key] = $skin_settings[$key];
}
}
}
// if (isset($save)) {
// update_option('suffusion_options', $suffusion_unified_options);
// }
return $suffusion_unified_options;
}
if (!function_exists('suffusion_get_memory_usage')) {
/**
* Returns the total memory usage for the script at any point.
*
* @param bool $echo Echoes the value if set to true
* @return string
*/
function suffusion_get_memory_usage($echo = true) {
$ret = "";
if (function_exists('memory_get_usage')) {
$mem = memory_get_usage();
$unit = "B";
if ($mem > 1024) {
$mem = round($mem / 1024);
$unit = "KB";
if ($mem > 1024) {
$mem = round($mem / 1024);
$unit = "MB";
}
}
$ret = $mem . $unit;
if ($echo) {
echo $ret;
}
}
return $ret;
}
}
/**
* Returns the name of the skin being used.
*
* @return string
*/
function suffusion_get_theme_name() {
$suffusion_options = get_option('suffusion_options');
if (!isset($suffusion_options['suf_color_scheme']) || $suffusion_options['suf_color_scheme'] === FALSE || $suffusion_options['suf_color_scheme'] == null || !isset($suffusion_options['suf_color_scheme'])) {
$theme_name = 'root';
}
else {
$theme_name = $suffusion_options['suf_color_scheme'];
}
return $theme_name;
}
function suffusion_get_template_prefixes() {
$template_prefixes = array('1l-sidebar.php' => '_1l', '1r-sidebar.php' => '_1r', '1l1r-sidebar.php' => '_1l1r', '2l-sidebars.php' => '_2l', '2r-sidebars.php' => '_2r');
$template_prefixes = apply_filters('suffusion_filter_template_prefixes', $template_prefixes);
return $template_prefixes;
}
function suffusion_get_template_sidebars() {
$template_sb = array('1l-sidebar.php' => 1, '1r-sidebar.php' => 1, '1l1r-sidebar.php' => 2, '2l-sidebars.php' => 2, '2r-sidebars.php' => 2);
$template_sb = apply_filters('suffusion_filter_template_sidebars', $template_sb);
return $template_sb;
}
function suffusion_new_vars($public_query_vars) {
$public_query_vars[] = 'suffusion-css';
return $public_query_vars;
}
/**
* Core function to generate the custom CSS. This is used by custom-styles.php to print out the stylesheet, if CSS auto-generation
* is switched off.
*
* @param bool $echo
* @return string
* @since 3.7.4
*/
function suffusion_generate_all_custom_styles($echo = false) {
global $suf_enable_responsive;
$template_path = get_template_directory();
include_once ($template_path . '/suffusion-css-helper.php');
include_once ($template_path . '/suffusion-css-generator.php');
if (isset($suf_enable_responsive) && $suf_enable_responsive == 'on') {
include_once($template_path.'/responsive-css.php');
}
$suffusion_css_generator = new Suffusion_CSS_Generator(date(get_option('date_format').' '.get_option('time_format')));
$suffusion_custom_css_string = $suffusion_css_generator->generate_all_css();
if ($echo) {
echo $suffusion_custom_css_string;
}
return $suffusion_custom_css_string;
}
function suffusion_get_interactive_text_fields() {
global $suffusion_inbuilt_options;
$field_titles = get_option('suffusion_options_field_titles');
if (isset($field_titles) && is_array($field_titles)) {
$theme_version = $field_titles['theme-version'];
}
if ((isset($theme_version) && $theme_version != SUFFUSION_THEME_VERSION) || (!isset($theme_version))) {
$field_titles = array();
include_once (get_template_directory() . "/admin/theme-options.php");
foreach ($suffusion_inbuilt_options as $option) {
if (isset($option['id'])) {
$field_titles[$option['id']] = isset($option['name']) ? $option['name'] : '';
}
}
$field_titles['theme-version'] = SUFFUSION_THEME_VERSION;
if (current_user_can('edit_theme_options')) {
update_option('suffusion_options_field_titles', $field_titles);
}
}
return $field_titles;
}
/**
* Updates the generated CSS upon saving.
*
* @return mixed|string|void
*/
function suffusion_update_generated_css() {
global $suffusion_unified_options;
if (!isset($suffusion_unified_options['option-date'])) {
$suffusion_unified_options = suffusion_get_unified_options();
}
foreach ($suffusion_unified_options as $option => $value) {
global $$option;
$$option = $value;
}
$custom_css = get_option('suffusion_generated_css');
$db_options = get_option('suffusion_options');
if ((!isset($custom_css) || (isset($custom_css) && !is_array($custom_css)) ||
(is_array($custom_css) && !isset($custom_css['theme-version'])) ||
(is_array($custom_css) && isset($custom_css['theme-version']) && $custom_css['theme-version'] != SUFFUSION_THEME_VERSION) ||
(is_array($custom_css) && !isset($custom_css['option-date'])) ||
(is_array($custom_css) && isset($custom_css['option-date']) && $custom_css['option-date'] != $suffusion_unified_options['option-date']))
&& isset($db_options) && is_array($db_options) && count($db_options) > 10) {
$custom_css = array();
$custom_css['css'] = suffusion_generate_all_custom_styles();
$custom_css['option-date'] = $suffusion_unified_options['option-date'];
$custom_css['theme-version'] = SUFFUSION_THEME_VERSION;
update_option('suffusion_generated_css', $custom_css);
}
return $custom_css;
}
function suffusion_is_sidebar_empty($index) {
$sidebars = wp_get_sidebars_widgets();
if ((!isset($sidebars['sidebar-'.$index]) || (isset($sidebars['sidebar-'.$index]) && $sidebars['sidebar-'.$index] == null) || (isset($sidebars['sidebar-'.$index]) && is_array($sidebars['sidebar-'.$index]) && count($sidebars['sidebar-'.$index]) == 0)) &&
(!isset($sidebars[$index]) || (isset($sidebars[$index]) && $sidebars[$index] == null) || (isset($sidebars[$index]) && is_array($sidebars[$index]) && count($sidebars[$index]) == 0))) {
return true;
}
return false;
}
function suffusion_sidebar_widget_count($index) {
$sidebars = wp_get_sidebars_widgets();
if (!isset($sidebars['sidebar-'.$index]) || $sidebars['sidebar-'.$index] == null || (is_array($sidebars['sidebar-'.$index]) && count($sidebars['sidebar-'.$index]) == 0)) {
return 0;
}
else if (is_array($sidebars['sidebar-'.$index])){
return count($sidebars['sidebar-'.$index]);
}
if (!isset($sidebars[$index]) || $sidebars[$index] == null || (is_array($sidebars[$index]) && count($sidebars[$index]) == 0)) {
return 0;
}
else {
return count($sidebars[$index]);
}
}
function suffusion_register_jquery() {
global $suf_featured_use_lite;
if ($suf_featured_use_lite == 'lite') {
wp_register_script('suffusion-jquery-cycle', get_template_directory_uri() . '/scripts/jquery.cycle.lite.min.js', array('jquery'), null);
}
else {
wp_register_script('suffusion-jquery-cycle', get_template_directory_uri() . '/scripts/jquery.cycle.all.min.js', array('jquery'), null);
}
// wp_register_script('suffusion-jquery-cycle', get_template_directory_uri() . '/scripts/jquery.cycle.min.js', array('jquery'), null);
}
/**
* Function to support meus from the Menu dashboard.
* Strictly speaking this is not required. You could select these same menus from the Main Navigation Bar Setup or Top Navigation Bar Setup.
*
* @return void
*/
function suffusion_register_menus() {
register_nav_menus(array(
'top' => __( 'Navigation Bar Above Header', 'suffusion' ),
'main' => __( 'Navigation Bar Below Header', 'suffusion' ),
));
}
function suffusion_add_user_contact_methods($contact_methods) {
global $suf_uprof_networks, $suffusion_social_networks;
if (trim($suf_uprof_networks) != '') {
$networks = explode(',', $suf_uprof_networks);
foreach ($networks as $network) {
$display = $suffusion_social_networks[$network];
$contact_methods[$network] = $display;
}
}
return $contact_methods;
}
/**
* Support for a custom tag in the style.css header.
*
* @param $headers
* @return array
*/
function suffusion_extra_theme_headers($headers) {
if (!in_array('Announcements Feed', $headers)) {
$headers[] = 'Announcements Feed';
}
return $headers;
}
function suffusion_pad_signup_form_start() {
?>
<div id="main-col">
<?php
}
function suffusion_pad_signup_form_end() {
?>
</div><!-- #main-col -->
<?php
}
/**
* Parses all the options, then picks out the default values for them. This is a heavy operation, hence it is executed only while saving.
*
* @return array
*/
function suffusion_default_options() {
global $suffusion_inbuilt_options;
if (!isset($suffusion_inbuilt_options) || !is_array($suffusion_inbuilt_options)) {
require_once(get_template_directory().'/admin/theme-options.php');
}
$default_options = array();
foreach ($suffusion_inbuilt_options as $value) {
if (isset($value['id']) && isset($value['type']) && $value['type'] != 'button' && isset($value['std'])) {
$default_options[$value['id']] = suffusion_flatten_option($value);
}
}
return $default_options;
}
/**
* Converts an option's default value to a string. This is useful for options where the default is stored as an array.
*
* @param $option
* @return string
*/
function suffusion_flatten_option($option) {
if (!is_array($option) || !isset($option['type']) || !isset($option['id']) || !isset($option['std'])) {
return '';
}
switch ($option['type']) {
case 'sortable-list':
if (is_array($option['std'])) {
return implode(',', array_keys($option['std']));
}
return $option['std'];
case 'multi-select':
if (is_array($option['std'])) {
return implode(',', $option['std']);
}
return $option['std'];
case 'border':
if (is_array($option['std'])) {
$default_txt = "";
foreach ($option['std'] as $edge => $edge_val) {
$default_txt .= $edge.'::';
foreach ($edge_val as $opt => $opt_val) {
$default_txt .= $opt . "=" . $opt_val . ";";
}
$default_txt .= "||";
}
return $default_txt;
}
return $option['std'];
case 'background':
if (is_array($option['std'])) {
$default_txt = "";
foreach ($option['std'] as $opt => $opt_val) {
$default_txt .= $opt."=".$opt_val.";";
}
return $default_txt;
}
return $option['std'];
case 'font':
if (is_array($option['std'])) {
$default_txt = "";
foreach ($option['std'] as $opt => $opt_val) {
$default_txt .= $opt."=".stripslashes($opt_val).";";
}
return $default_txt;
}
return $option['std'];
default:
return $option['std'];
}
}
/**
* Returns an indented array of pages, based on parent and child pages. This is used in the admin menus.
*
* @return array|null
*/
function suffusion_get_formatted_page_array() {
global $suffusion_pages_array;
if (isset($suffusion_pages_array) && $suffusion_pages_array != null) {
return $suffusion_pages_array;
}
$ret = array();
$pages = get_pages('sort_column=menu_order');
if ($pages != null) {
foreach ($pages as $page) {
if (is_null($suffusion_pages_array)) {
$ret[$page->ID] = array ("title" => $page->post_title, "depth" => count(get_ancestors($page->ID, 'page')));
}
}
}
if ($suffusion_pages_array == null) {
$suffusion_pages_array = $ret;
return $ret;
}
else {
return $suffusion_pages_array;
}
}
function suffusion_get_formatted_category_array() {
global $suffusion_categories_array;
$ret = array();
$args = array("type" => "post",
"orderby" => "name",
"hide_empty" => false,
);
$categories = get_categories($args);
if ($categories == null) { $categories = array(); }
foreach ($categories as $category) {
if ($suffusion_categories_array == null) {
$ret[$category->cat_ID] = array("title" => $category->cat_name);
}
}
if ($suffusion_categories_array == null) {
$suffusion_categories_array = $ret;
return $suffusion_categories_array;
}
else {
return $suffusion_categories_array;
}
}
function suffusion_get_formatted_link_array() {
global $link_array;
$ret = array();
$args = array(
"order" => "ASC",
"orderby" => 'name',
);
$links = get_bookmarks($args);
if ($links == null) {
$links = array();
}
foreach ($links as $link) {
if ($link_array == null) {
$ret[$link->link_id] = array("title" => $link->link_name);
}
}
if ($link_array == null) {
$link_array = $ret;
return $link_array;
}
else {
return $link_array;
}
}
function suffusion_get_formatted_wp_menu_array() {
global $suffusion_menu_array;
$ret = array();
$menus = wp_get_nav_menus();
if ($menus == null) {
$menus = array();
}
if ($suffusion_menu_array == null) {
foreach ($menus as $menu) {
$ret[$menu->term_id] = array("title" => $menu->name);
}
$suffusion_menu_array = $ret;
}
return $suffusion_menu_array;
}
function suffusion_get_formatted_options_array($options_array) {
$ret = array();
foreach ($options_array as $option_key => $option_value) {
$ret[$option_key] = array('title' => $option_value, 'depth' => 1);
}
return $ret;
}
function suffusion_get_associative_array($stored_value) {
if (!is_array($stored_value)) {
$converted = explode('||', $stored_value ?? '');
$stored_value = array();
foreach ($converted as $converted_string) {
$converted_pairs = explode('::', $converted_string);
$index = '';
$inner_ctr = 0;
$pair_array = array();
foreach ($converted_pairs as $pairs_string) {
$inner_ctr++;
if ($inner_ctr == 1) {
$index = $pairs_string;
continue 1;
}
if (trim($pairs_string) != '') {
$pairs = explode(';', $pairs_string);
foreach ($pairs as $pair) {
$name_value = explode('=', $pair);
if (count($name_value) <= 1) {
continue 1;
}
$pair_array[$name_value[0]] = $name_value[1];
}
}
}
$stored_value[$index] = $pair_array;
}
}
return $stored_value;
}
/**
* Based on the Image Rotator script by Matt Mullenweg > https://ma.tt/scripts/randomimage/
* Inspired by Dan Benjamin > https://alistapart.com/article/randomizer/
*
* Make the folder the relative path to the images, like "../img" or "random/images/".
*
* Modifications by Sayontan Sinha, to dynamically pass the folder for images.
* This cannot exist as a standalone file, because it loads outside the context of WP, so variables such as folder names cannot be fetched by the file automatically.
*
* @param $folder
* @return string
*/
function suffusion_get_rotating_image($folder) {
// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1; // Initialize some variables
// if ('' == $folder) $folder = './';
$content_folder = trailingslashit(WP_CONTENT_DIR).$folder;
$handle = opendir($content_folder);
if ($handle) {
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along
return trailingslashit(WP_CONTENT_URL).trailingslashit($folder).$files[$rand];
}
return '';
}