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
|
<?php
/* CONTENT */
/* - Extra body classes /* - Filter for next/previous image links /* - Custom metaboxes for Product Categories /* - Extra editor styles /* - Shorter Exerpt /* - Shortcode fixer /* - Hex 2 Rgb /* - Set default WooCommerce images /* - WooCommerc extra tabs /* - Enable SVG upload
/** * Adds custom classes to the array of body classes. */
function flatsome_body_classes( $classes ) { global $flatsome_opt; // add antialias to all texts $classes[] = 'antialiased';
// Adds a class of group-blog to blogs with more than 1 published author if ( is_multi_author() ) { $classes[] = 'group-blog'; }
// adds dark header class if($flatsome_opt['header_color'] == 'dark'){ $classes[] = 'dark-header'; $classes[] = 'org-dark-header'; } // add stikcy header class if($flatsome_opt['header_sticky'] && !isset($_GET["shortcode"])){ $classes[] = 'sticky_header'; }
if($flatsome_opt['breadcrumb_size']){ $classes[] = $flatsome_opt['breadcrumb_size']; } // add logo-center class if($flatsome_opt['logo_position'] == 'center'){ $classes[] = 'logo-center'; }
if($flatsome_opt['catalog_mode_prices']){ $classes[] = 'no-prices'; }
// add boxed layout class if selected if($flatsome_opt['body_layout']){ $classes[] = $flatsome_opt['body_layout']; }
if($flatsome_opt['body_layout'] == "framed-layout"){ $classes[] = "boxed"; }
// add background settings if($flatsome_opt['body_bg_image']){ $classes[] = $flatsome_opt['body_bg_type']; }
if ( is_page_template( 'page-transparent-header-light.php' ) || is_page_template( 'page-transparent-header.php' ) || is_page_template( 'page-boxed-header.php' )) { $classes[] = 'transparent-header'; }
if ( is_page_template( 'page-transparent-header-light.php' )) { $classes[] = 'has-dark-header'; $classes[] = 'dark-header'; }
if ( is_page_template( 'page-blank-header.php' )) { $classes[] = 'hide-header'; }
if ( is_page_template( 'page-boxed-header.php' )) { $classes[] = 'boxed-header'; }
return $classes; } add_filter( 'body_class', 'flatsome_body_classes' );
/** * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages */ function flatsome_enhanced_image_navigation( $url, $id ) { if ( ! is_attachment() && ! wp_attachment_is_image( $id ) ) return $url;
$image = get_post( $id ); if ( ! empty( $image->post_parent ) && $image->post_parent != $id ) $url .= '#main';
return $url; } add_filter( 'attachment_link', 'flatsome_enhanced_image_navigation', 10, 2 );
/** * Filters wp_title to print a neat <title> tag based on what is being viewed. */ function flatsome_wp_title( $title, $sep ) { global $page, $paged;
if ( is_feed() ) return $title;
// Add the blog name $title .= get_bloginfo( 'name' );
// Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) $title .= " $sep $site_description";
// Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) $title .= " $sep " . sprintf( __( 'Page %s', 'flatsome' ), max( $paged, $page ) );
return $title; } add_filter( 'wp_title', 'flatsome_wp_title', 10, 2 );
/* ADD CUSTOM META BOX TO CATEGORY PAGES */ if(function_exists('get_term_meta')){ function top_text_taxonomy_edit_meta_field($term) { // put the term ID into a variable $t_id = $term->term_id; // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_term_meta($t_id,'cat_meta'); if(!$term_meta){$term_meta = add_term_meta($t_id, 'cat_meta', '');} ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[cat_header]"><?php _e( 'Top Content', 'flatsome' ); ?></label></th> <td> <?php
$content = esc_attr( $term_meta[0]['cat_header'] ) ? esc_attr( $term_meta[0]['cat_header'] ) : ''; echo '<textarea id="term_meta[cat_header]" name="term_meta[cat_header]">'.$content.'</textarea>'; ?> <p class="description"><?php _e( 'Enter a value for this field. Shortcodes are allowed. This will be displayed at top of the category.','flatsome' ); ?></p> </td> </tr> <?php } add_action( 'product_cat_edit_form_fields', 'top_text_taxonomy_edit_meta_field', 10, 2 );
/* ADD CUSTOM META BOX TO CATEGORY PAGES */ function bottom_text_taxonomy_edit_meta_field($term) { // put the term ID into a variable $t_id = $term->term_id; // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_term_meta($t_id,'cat_meta'); if(!$term_meta){$term_meta = add_term_meta($t_id, 'cat_meta', '');} ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[cat_footer]"><?php _e( 'Bottom Content', 'flatsome' ); ?></label></th> <td> <?php
$content = esc_attr( $term_meta[0]['cat_footer'] ) ? esc_attr( $term_meta[0]['cat_footer'] ) : ''; echo '<textarea id="term_meta[cat_footer]" name="term_meta[cat_footer]">'.$content.'</textarea>'; ?> <p class="description"><?php _e( 'Enter a value for this field. Shortcodes are allowed. This will be displayed at bottom of the category.','flatsome' ); ?></p> </td> </tr> <?php } add_action( 'product_cat_edit_form_fields', 'bottom_text_taxonomy_edit_meta_field', 10, 2 );
/* SAVE CUSTOM META*/ function save_taxonomy_custom_meta( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_term_meta($t_id,'cat_meta'); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_term_meta($term_id, 'cat_meta', $term_meta);
} } add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 ); }
/* EXTRA EDITOR STYLES (add extra styles to the content editor box) */ add_filter( 'mce_buttons_2', 'my_mce_buttons_2' ); function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; }
add_filter( 'tiny_mce_before_init', 'ux_formats_before_init' ); function ux_formats_before_init( $settings ) {
$style_formats = array(
array( 'title' => 'Link styles', 'items' => array( array( 'title' => 'Button Primary', 'selector' => 'a', 'classes' => 'button primary', ), array( 'title' => 'Button White', 'selector' => 'a', 'classes' => 'button white', ), array( 'title' => 'Button Secondary', 'selector' => 'a', 'classes' => 'button secondary', ), array( 'title' => 'Button Alert', 'selector' => 'a', 'classes' => 'button alert', ), array( 'title' => 'Button Success', 'selector' => 'a', 'classes' => 'button success', ), array( 'title' => 'Button Alternative Primary', 'selector' => 'a', 'classes' => 'button alt-button', ), array( 'title' => 'Button Alternative White', 'selector' => 'a', 'classes' => 'button alt-button white', ), array( 'title' => 'Large - Button Primary', 'selector' => 'a', 'classes' => 'button large primary', ), array( 'title' => 'Large Button Secondary', 'selector' => 'a', 'classes' => 'button large secondary', ), array( 'title' => 'Large Button Alert', 'selector' => 'a', 'classes' => 'button large alert', ), array( 'title' => 'Large Button Success', 'selector' => 'a', 'classes' => 'button large success', ), array( 'title' => 'Large Button Alternative Primary', 'selector' => 'a', 'classes' => 'button large alt-button success', ), array( 'title' => 'Large Button Alternative Secondary', 'selector' => 'a', 'classes' => 'button large alt-button secondary', ), array( 'title' => 'Large Button Alternative White', 'selector' => 'a', 'classes' => 'button large alt-button white', ) ) ),
array( 'title' => 'Pull text inn', 'selector' => 'p', 'classes' => 'text-pull-inn', 'exact' => 'true', ), array( 'title' => 'Paragraph - Lead', 'selector' => 'p', 'classes' => 'lead', 'exact' => 'true', ),
array( 'title' => 'Paragraph - Lead, Centered', 'selector' => 'p', 'classes' => 'lead text-center', 'exact' => 'true', ),
array( 'title' => 'Uppercase', 'selector' => '*', 'classes' => 'uppercase', ), array( 'title' => 'Thin Font', 'selector' => '*', 'classes' => 'thin-font', ),
array( 'title' => 'Hide on Mobile screens', 'selector' => '*', 'classes' => 'hide-for-small', ),
array( 'title' => 'Alternative Font', 'selector' => '*', 'classes' => 'alt-font', ),
array( 'title' => 'Title - Large', 'selector' => '*', 'classes' => 'h-large', ),
array( 'title' => 'Title - X-Large', 'selector' => '*', 'classes' => 'h-xlarge', ),
array( 'title' => 'Backgroud - Black', 'selector' => '*', 'classes' => 'text-box-dark', ),
array( 'title' => 'Background - White', 'selector' => '*', 'classes' => 'text-box-light', ),
array( 'title' => 'Background - Primary Color', 'selector' => '*', 'classes' => 'text-box-primary', ),
array( 'title' => 'Text Border White', 'selector' => '*', 'classes' => 'text-bordered-white', ), array( 'title' => 'Text Border Primary', 'selector' => '*', 'classes' => 'text-bordered-primary', ), array( 'title' => 'Text Border Dark', 'selector' => '*', 'classes' => 'text-bordered-dark', ) , array( 'title' => 'Text Border Top and Bottom White', 'selector' => '*', 'classes' => 'text-boarder-top-bottom-white', ) , array( 'title' => 'Text Border Top and Bottom Dark', 'selector' => '*', 'classes' => 'text-boarder-top-bottom-dark', ), array( 'title' => 'Tilt Left', 'selector' => '*', 'classes' => 'tilt-left', ), array( 'title' => 'Text Border Top and Bottom Dark', 'selector' => '*', 'classes' => 'tilt-right', ) , array( 'title' => 'Bullets List - Check mark', 'selector' => 'li', 'classes' => 'bullet-checkmark', ), array( 'title' => 'Bullets List - Arrow', 'selector' => 'li', 'classes' => 'bullet-arrow', ), array( 'title' => 'Bullets List - Star', 'selector' => 'li', 'classes' => 'bullet-star', ),
array( 'title' => 'Text shadow', 'selector' => '*', 'classes' => 'drop-shadow', ),
array( 'title' => 'Animate -Fade In', 'selector' => '*', 'classes' => 'animated fadeIn', ),
array( 'title' => 'Animate - Fade In Left', 'selector' => '*', 'classes' => 'animated fadeInLeft', ), array( 'title' => 'Animate - Fade In Right', 'selector' => '*', 'classes' => 'animated fadeInRight', ),
);
$settings['style_formats'] = json_encode( $style_formats );
return $settings;
}
/* Add HTML after Short description */ if($flatsome_opt['html_before_add_to_cart']){ function before_add_to_cart_html(){ global $flatsome_opt; echo do_shortcode($flatsome_opt['html_before_add_to_cart']); } add_action( 'woocommerce_single_product_summary', 'before_add_to_cart_html', 20);
}
if($flatsome_opt['html_after_add_to_cart']){ function after_add_to_cart_html(){ global $flatsome_opt; echo do_shortcode($flatsome_opt['html_after_add_to_cart']); } add_action( 'woocommerce_single_product_summary', 'after_add_to_cart_html', 30); }
/* HTML AFTER CART */ if($flatsome_opt['html_cart_footer']){ function html_cart_footer(){ global $flatsome_opt; echo do_shortcode($flatsome_opt['html_cart_footer']); } add_action( 'woocommerce_after_cart', 'html_cart_footer', 0); }
/* SHORTCODE FIX */ function fixShortcode($content){ $fix = array ( '_____' => '<div class="tx-div large"></div>', '____' => '<div class="tx-div medium"></div>', '___' => '<div class="tx-div small"></div>', ']<br />' => ']', '<br />[' => '[', '<br>' => '', ); $content = strtr($content, $fix); $content = wpautop( preg_replace( '/<\/?p\>/', "\n", $content ) . "\n" );
return do_shortcode( shortcode_unautop( $content) ); }
/* EDITOR COLORS */ function ux_mce4_options( $init ) { global $flatsome_opt; $default_colours = ' "000000", "Black", "993300", "Burnt orange", "333300", "Dark olive", "003300", "Dark green", "003366", "Dark azure", "000080", "Navy Blue", "333399", "Indigo", "333333", "Very dark gray", "800000", "Maroon", "FF6600", "Orange", "808000", "Olive", "008000", "Green", "008080", "Teal", "0000FF", "Blue", "666699", "Grayish blue", "808080", "Gray", "FF0000", "Red", "FF9900", "Amber", "99CC00", "Yellow green", "339966", "Sea green", "33CCCC", "Turquoise", "3366FF", "Royal blue", "800080", "Purple", "999999", "Medium gray", "FF00FF", "Magenta", "FFCC00", "Gold", "FFFF00", "Yellow", "00FF00", "Lime", "00FFFF", "Aqua", "00CCFF", "Sky blue", "993366", "Brown", "C0C0C0", "Silver", "FF99CC", "Pink", "FFCC99", "Peach", "FFFF99", "Light yellow", "CCFFCC", "Pale green", "CCFFFF", "Pale cyan", "99CCFF", "Light sky blue", "CC99FF", "Plum", "FFFFFF", "White" '; $custom_colours = ' "e14d43", "Primary Color", "d83131", "Color 2 Name", "ed1c24", "Color 3 Name", "f99b1c", "Color 4 Name", "50b848", "Color 5 Name", "00a859", "Color 6 Name", "00aae7", "Color 7 Name", "282828", "Color 8 Name" '; $init['textcolor_map'] = '['.$custom_colours.','.$default_colours.']'; return $init; } add_filter('tiny_mce_before_init', 'ux_mce4_options');
/* Shorter exerpt */ function short_excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); return $excerpt; }
function content($limit) { $content = explode(' ', get_the_content(), $limit); if (count($content)>=$limit) { array_pop($content); $content = implode(" ",$content).'...'; } else { $content = implode(" ",$content); } $content = preg_replace('/\[.+\]/','', $content); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); return $content; }
/* HEX TO RGB */ function ux_hex2rgba($color, $opacity = false) { $default = 'rgb(0,0,0)'; //Return default if no color provided if(empty($color)) return $default;
//Sanitize $color if "#" is provided if ($color[0] == '#' ) { $color = substr( $color, 1 ); }
//Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; }
//Convert hexadec to rgb $rgb = array_map('hexdec', $hex);
//Check if opacity is set(rgba or rgb) if($opacity){ if(abs($opacity) > 1) $opacity = 1.0; $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; } else { $output = 'rgb('.implode(",",$rgb).')'; } //Return rgb(a) color string return $output; }
/* SETUP DEFAULT WOOCOMMERCE IMAGE SIZES */ global $pagenow; if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) add_action( 'init', 'flatsome_woocommerce_image_dimensions', 1 );
function flatsome_woocommerce_image_dimensions() { $catalog = array( 'width' => '247', // px 'height' => '300', // px 'crop' => 1 // true );
$single = array( 'width' => '510', // px 'height' => '600', // px 'crop' => 1 // true );
$thumbnail = array( 'width' => '114', // px 'height' => '130', // px 'crop' => 1 // false );
// Catalog Image sizes update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs update_option( 'shop_single_image_size', $single ); // Single product image update_option( 'shop_thumbnail_image_size', $thumbnail ); // Image gallery thumbs }
/* ajax navigation fix */ add_filter('_ajax_layered_nav_containers', 'ux_add_custom_container'); function ux_add_custom_container($containers){ $containers[] = '.woocommerce-pagination'; $containers[] = '.woocommerce-result-count'; return $containers; }
add_filter('sod_ajax_layered_nav_product_container', 'aln_product_container'); function aln_product_container($product_container){ //Enter either the class or id of the container that holds your products return '.products'; }
/* WooCommerce extra tabs */ add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' ); function woo_new_product_tab( $tabs ) { global $wc_cpdf, $flatsome_opt; // Adds the new tab if($wc_cpdf->get_value(get_the_ID(), '_custom_tab_title')){ $tabs['ux_custom_tab'] = array( 'title' => __( $wc_cpdf->get_value(get_the_ID(), '_custom_tab_title'), 'flatsome' ), 'priority' => 40, 'callback' => 'ux_custom_tab_content' ); }
if($flatsome_opt['tab_title']){ $tabs['ux_global_tab'] = array( 'title' => __($flatsome_opt['tab_title'], 'flatsome' ), 'priority' => 50, 'callback' => 'ux_global_tab_content' ); } return $tabs; } function ux_custom_tab_content() { // The new tab content global $wc_cpdf; echo do_shortcode($wc_cpdf->get_value(get_the_ID(), '_custom_tab')); }
function ux_global_tab_content() { // The new tab content global $flatsome_opt; echo do_shortcode($flatsome_opt['tab_content']); }
/* Enable SVG upload */ function ux_enable_svg( $mimes ){ $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter( 'upload_mimes', 'ux_enable_svg' );
|