Make WordPress Themes

source: thbusiness/2.0.7/inc/customizer/customizer.php

Last change on this file was 105728, checked in by themedropbox, 3 years ago

New version of THBusiness - 2.0.7

File size: 26.4 KB
Line 
1<?php
2/**
3 * Thbusiness Theme Customizer
4 *
5 * @package thbusiness
6 */
7
8/**
9 * Add postMessage support for site title and description for the Theme Customizer.
10 *
11 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
12 */
13function thbusiness_customize_register( $wp_customize ) {
14
15        require( get_template_directory() . '/inc/customizer/custom-controls/control-custom-content.php' );
16
17        $wp_customize->remove_section( 'themes' );
18        $wp_customize->remove_control( 'display_header_text' );
19        $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
20        $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
21        $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
22    $wp_customize->get_section( 'static_front_page' )->panel    = 'thbusiness_home_settings';
23    $wp_customize->get_section( 'background_image' )->panel     = 'thbusiness_styling';
24    $wp_customize->get_section( 'header_image' )->panel                 = 'thbusiness_styling';
25    $wp_customize->get_section( 'colors' )->panel                               = 'thbusiness_styling';
26   
27
28
29        /**
30         * Header Settings Panel
31         */
32        $wp_customize->add_panel( 
33                'thbusiness_header_settings', 
34                array(
35                        'title' => __( 'Header Settings', 'thbusiness' ),
36                        'description' => __( 'Use this panel to set your header settings', 'thbusiness' ),
37                        'priority' => 25, 
38                ) 
39        );
40
41
42        // Logo image
43    $wp_customize->add_setting(
44        'site_logo',
45        array(
46            'sanitize_callback' => 'thbusiness_sanitize_image'
47        ) 
48    ); 
49    $wp_customize->add_control(
50        new WP_Customize_Image_Control(
51            $wp_customize,
52            'site_logo',
53            array(
54                'label'         => __( 'Site Logo', 'thbusiness' ),
55                'section'       => 'title_tagline',
56                'settings'      => 'site_logo',
57                'description'   => __( 'Upload a logo for your website. Recommended height for your logo is 135px.', 'thbusiness' ),
58            )
59        )
60    );
61
62    // Logo, title and description chooser
63    $wp_customize->add_setting(
64        'site_title_option',
65        array (
66            'default'           => 'text_only',
67            'sanitize_callback' => 'thbusiness_sanitize_logo_title_select',
68            'transport'         => 'refresh'
69        )
70    );
71    $wp_customize->add_control(
72        'site_title_option',
73        array(
74            'label'             => __( 'Display site title / logo.', 'thbusiness' ),
75            'section'           => 'title_tagline',
76            'type'              => 'radio',
77            'description'       => __( 'Choose your preferred option.', 'thbusiness' ),
78            'choices'   => array (
79                'text_only'     => __( 'Display site title and description only.', 'thbusiness' ),
80                'logo_only'     => __( 'Display site logo image only.', 'thbusiness' ),
81                'display_none'  => __( 'Display none', 'thbusiness' )
82            )
83        )
84    );
85
86    // Site favicon
87        $wp_customize->add_setting(
88        'site_favicon',
89        array(
90            'sanitize_callback' => 'thbusiness_sanitize_image'
91        ) 
92    ); 
93    $wp_customize->add_control(
94        new WP_Customize_Image_Control(
95            $wp_customize,
96            'site_favicon',
97            array(
98                'label'         => __( 'Upload a favicon', 'thbusiness' ),
99                'section'       => 'title_tagline',
100                'settings'      => 'site_favicon',
101                'description'   => __( 'Upload a favicon for your website.', 'thbusiness' ),
102            )
103        )
104    );
105
106    // Display site favicon?
107    $wp_customize->add_setting(
108                'display_site_favicon',
109                array(
110                        'default'                       => false,
111                        'sanitize_callback'     => 'thbusiness_sanitize_checkbox'
112                )
113        );
114    $wp_customize->add_control(
115                'display_site_favicon',
116                array(
117                        'settings'              => 'display_site_favicon',
118                        'section'               => 'title_tagline',
119                        'type'                  => 'checkbox',
120                        'label'                 => __( 'Display site favicon?', 'thbusiness' ),
121                )
122        );
123
124
125    /**
126     * General settings section.
127     */
128    $wp_customize->add_section( 
129        'thbusiness_general_settings', 
130        array(
131                        'title' => __( 'General Settings', 'thbusiness' ),
132                        'description' => __( 'Use this section to set general settings of the site.', 'thbusiness' ),
133                        'priority' => 30,
134                ) 
135        );
136
137        // Footer copyright text.
138        $wp_customize->add_setting(
139                'footer_copyright_text',
140                array(
141                        'default'                       => sprintf( __( 'Copyright %s. All rights reserved.', 'thbusiness' ), esc_html( get_bloginfo( 'name' ) ) ),
142                        'sanitize_callback'     => 'thbusiness_sanitize_html'
143                )
144        );
145        $wp_customize->add_control(
146                'footer_copyright_text',
147                array(
148                        'settings'              => 'footer_copyright_text',
149                        'section'               => 'thbusiness_general_settings',
150                        'type'                  => 'textarea',
151                        'label'                 => __( 'Footer copyright text', 'thbusiness' ),
152                        'description'   => __( 'Copyright or other text to be displayed in the site footer. HTML allowed.', 'thbusiness' )
153                )
154        );
155
156    /**
157     * Top bar section.
158     */
159    $wp_customize->add_section( 
160        'thbusiness_topbar_settings', 
161        array(
162                        'title' => __( 'Top Bar Settings', 'thbusiness' ),
163                        'priority' => 31,
164                ) 
165        );
166
167    // Display topbar?
168    $wp_customize->add_setting(
169                'display_topbar',
170                array(
171                        'default'                       => true,
172                        'sanitize_callback'     => 'thbusiness_sanitize_checkbox'
173                )
174        );
175    $wp_customize->add_control(
176                'display_topbar',
177                array(
178                        'settings'              => 'display_topbar',
179                        'section'               => 'thbusiness_topbar_settings',
180                        'type'                  => 'checkbox',
181                        'label'                 => __( 'Display top bar?', 'thbusiness' )
182                )
183        );
184
185        $wp_customize->add_setting(
186                'telephone_text',
187                array(
188                        'default'                       => '',
189                        'sanitize_callback'     => 'thbusiness_sanitize_html'
190                )
191        );
192
193        $wp_customize->add_control(
194                'telephone_text',
195                array(
196                        'settings'              => 'telephone_text',
197                        'section'               => 'thbusiness_topbar_settings',
198                        'type'                  => 'text',
199                        'label'                 => __( 'Call Us Text', 'thbusiness' ),
200                )
201        );     
202
203        $wp_customize->add_setting(
204                'telephone_number',
205                array(
206                        'default'                       => '',
207                        'sanitize_callback'     => 'thbusiness_sanitize_nohtml'
208                )
209        );
210
211        $wp_customize->add_control(
212                'telephone_number',
213                array(
214                        'settings'              => 'telephone_number',
215                        'section'               => 'thbusiness_topbar_settings',
216                        'type'                  => 'text',
217                        'label'                 => __( 'Telephone Number', 'thbusiness' ),
218                )
219        );     
220
221        $wp_customize->add_setting(
222                'email_text',
223                array(
224                        'default'                       => '',
225                        'sanitize_callback'     => 'thbusiness_sanitize_nohtml'
226                )
227        );
228
229        $wp_customize->add_control(
230                'email_text',
231                array(
232                        'settings'              => 'email_text',
233                        'section'               => 'thbusiness_topbar_settings',
234                        'type'                  => 'text',
235                        'label'                 => __( 'Email Text', 'thbusiness' ),
236                )
237        );     
238
239        $wp_customize->add_setting(
240                'email_address',
241                array(
242                        'default'                       => '',
243                        'sanitize_callback'     => 'thbusiness_sanitize_email'
244                )
245        );
246
247        $wp_customize->add_control(
248                'email_address',
249                array(
250                        'settings'              => 'email_address',
251                        'section'               => 'thbusiness_topbar_settings',
252                        'type'                  => 'email',
253                        'label'                 => __( 'Email Address', 'thbusiness' ),
254                )
255        );
256
257        // Topbar custom text.
258        $wp_customize->add_setting(
259                'topbar_custom_text',
260                array(
261                        'default'                       => '',
262                        'sanitize_callback'     => 'thbusiness_sanitize_nohtml'
263                )
264        );
265        $wp_customize->add_control(
266                'topbar_custom_text',
267                array(
268                        'settings'              => 'topbar_custom_text',
269                        'section'               => 'thbusiness_topbar_settings',
270                        'type'                  => 'textarea',
271                        'label'                 => __( 'Custom Text', 'thbusiness' ),
272                        'description'   => __( 'Add your custom text here.', 'thbusiness' )
273                )
274        );     
275
276    /**
277     * Home Settings section.
278     */
279    $wp_customize->add_panel( 
280                'thbusiness_home_settings', 
281                array(
282                        'title' => __( 'Homepage Settings', 'thbusiness' ),
283                        'description' => __( 'Use this panel to set your home page settings', 'thbusiness' ),
284                        'priority' => 32, 
285                ) 
286        );
287
288        /**
289     * Slider Section.
290     */
291    $wp_customize->add_section( 
292        'thbusiness_slider', 
293        array(
294                        'title' => __( 'Homepage Slider', 'thbusiness' ),
295                        'panel' => 'thbusiness_home_settings'
296                ) 
297        );
298
299    // Display slider?
300    $wp_customize->add_setting(
301                'display_slider',
302                array(
303                        'default'                       => true,
304                        'sanitize_callback'     => 'thbusiness_sanitize_checkbox'
305                )
306        );
307    $wp_customize->add_control(
308                'display_slider',
309                array(
310                        'settings'              => 'display_slider',
311                        'section'               => 'thbusiness_slider',
312                        'type'                  => 'checkbox',
313                        'label'                 => __( 'Display slider on homepage ?', 'thbusiness' )
314                )
315        );
316
317        for ( $i=1; $i <= 5; $i++ ) { 
318                $wp_customize->add_setting(
319                'custom_slide_img_' . $i . '',
320                array(
321                    'sanitize_callback' => 'thbusiness_sanitize_image'
322                ) 
323            ); 
324            $wp_customize->add_control(
325                new WP_Customize_Image_Control(
326                    $wp_customize,
327                    'custom_slide_img_' . $i . '',
328                    array(
329                        'label'         => sprintf( __( 'Slide %d image', 'thbusiness' ), $i ),
330                        'section'       => 'thbusiness_slider',
331                        'settings'      => 'custom_slide_img_' . $i . '',
332                    )
333                )
334            );
335
336            $wp_customize->add_setting(
337                        'custom_slide_title_' . $i . '',
338                        array(
339                                'default'                       => '',
340                                'sanitize_callback'     => 'thbusiness_sanitize_html'
341                        )
342                );
343
344                $wp_customize->add_control(
345                        'custom_slide_title_' . $i . '',
346                        array(
347                                'settings'              => 'custom_slide_title_' . $i . '',
348                                'section'               => 'thbusiness_slider',
349                                'type'                  => 'text',
350                                'label'                 => sprintf( __( 'Slide %d title', 'thbusiness' ), $i )
351                        )
352                );
353
354            $wp_customize->add_setting(
355                        'custom_slide_description_' . $i . '',
356                        array(
357                                'default'                       => '',
358                                'sanitize_callback'     => 'thbusiness_sanitize_html'
359                        )
360                );
361
362                $wp_customize->add_control(
363                        'custom_slide_description_' . $i . '',
364                        array(
365                                'settings'              => 'custom_slide_description_' . $i . '',
366                                'section'               => 'thbusiness_slider',
367                                'type'                  => 'textarea',
368                                'label'                 => sprintf( __( 'Slide %d description', 'thbusiness' ), $i )
369                        )
370                );             
371
372            $wp_customize->add_setting(
373                        'custom_slide_url_' . $i . '',
374                        array(
375                                'default'                       => '',
376                                'sanitize_callback'     => 'thbusiness_sanitize_url'
377                        )
378                );
379
380                $wp_customize->add_control(
381                        'custom_slide_url_' . $i . '',
382                        array(
383                                'settings'              => 'custom_slide_url_' . $i . '',
384                                'section'               => 'thbusiness_slider',
385                                'type'                  => 'text',
386                                'label'                 => sprintf( __( 'Slide %d redirect url', 'thbusiness' ), $i )
387                        )
388                );
389
390                $wp_customize->add_setting(
391                        'custom_slide_button_text_' . $i . '',
392                        array(
393                                'default'                       => '',
394                                'sanitize_callback'     => 'thbusiness_sanitize_html'
395                        )
396                );
397
398                $wp_customize->add_control(
399                        'custom_slide_button_text_' . $i . '',
400                        array(
401                                'settings'              => 'custom_slide_button_text_' . $i . '',
402                                'section'               => 'thbusiness_slider',
403                                'type'                  => 'text',
404                                'label'                 => sprintf( __( 'Slide %d button text', 'thbusiness' ), $i )
405                        )
406                );
407    }           
408
409
410        /**
411     * Styling Options.
412     */
413        $wp_customize->add_panel( 
414                'thbusiness_styling', 
415                array(
416                        'title'                 => __( 'Site Styling', 'thbusiness' ),
417                        'description'   => __( 'Use this section to setup the homepage slider and featured posts.', 'thbusiness' ),
418                        'priority'              => 33, 
419                ) 
420        );
421
422        $wp_customize->add_setting(
423                'site_main_color',
424                array(
425                        'default'                       => '#eb5937',
426                        'sanitize_callback'     => 'thbusiness_sanitize_hex_color'
427                )
428        );
429
430        $wp_customize->add_control(
431                new WP_Customize_Color_Control(
432                        $wp_customize,
433                        'site_main_color',
434                        array(
435                                'settings'              => 'site_main_color',
436                                'section'               => 'colors',
437                                'label'                 => __( 'Site Main Color', 'thbusiness' ),
438                        )
439                )
440        );
441
442        /**
443     * Custom CSS section
444     */
445    $wp_customize->add_section( 
446        'thbusiness_custom_css', 
447        array(
448                        'title'                 => __( 'Custom CSS', 'thbusiness' ),
449                        'panel'                 => 'thbusiness_styling',
450                        'priority'              => 50
451                ) 
452        );
453
454        $wp_customize->add_setting(
455                'custom_css',
456                array(
457                        'default'                       => '',
458                        'type'                          => 'theme_mod',
459                        'capability'            => 'edit_theme_options',
460                        'sanitize_callback'     => 'thbusiness_sanitize_css'
461                )
462        );
463        $wp_customize->add_control(
464                'custom_css',
465                array(
466                        'settings'              => 'custom_css',
467                        'section'               => 'thbusiness_custom_css',
468                        'type'                  => 'textarea',
469                        'label'                 => __( 'Custom CSS', 'thbusiness' ),
470                        'description'   => __( 'Define custom CSS be used for your site. Do not enclose in script tags.', 'thbusiness' ),
471                )
472        );
473
474        /**
475     * Social Media
476     */
477    $wp_customize->add_section( 
478        'thbusiness_social_media', 
479        array(
480                        'title'                 => __( 'Social Media', 'thbusiness' ),
481                        'priority'              => 34
482                ) 
483        );
484
485        $wp_customize->add_setting(
486                'display_social_icons',
487                array(
488                        'default'                       => false,
489                        'sanitize_callback'     => 'thbusiness_sanitize_checkbox'
490                )
491        );
492
493        $wp_customize->add_control(
494                'display_social_icons',
495                array(
496                        'settings'              => 'display_social_icons',
497                        'section'               => 'thbusiness_social_media',
498                        'type'                  => 'checkbox',
499                        'label'                 => __( 'Display social icons?', 'thbusiness' ),
500                )
501        );
502
503        $wp_customize->add_setting(
504                'social_media_text',
505                array(
506                        'default'                       => '',
507                        'sanitize_callback'     => 'thbusiness_sanitize_nohtml'
508                )
509        );
510
511        $wp_customize->add_control(
512                'social_media_text',
513                array(
514                        'settings'              => 'social_media_text',
515                        'section'               => 'thbusiness_social_media',
516                        'type'                  => 'text',
517                        'label'                 => __( 'Follow Us Text', 'thbusiness' ),
518                )
519        );     
520
521
522        $wp_customize->add_setting(
523                'facebook_url',
524                array(
525                        'default'                       => '',
526                        'sanitize_callback'     => 'thbusiness_sanitize_url'
527                )
528        );
529
530        $wp_customize->add_control(
531                'facebook_url',
532                array(
533                        'settings'              => 'facebook_url',
534                        'section'               => 'thbusiness_social_media',
535                        'type'                  => 'url',
536                        'label'                 => __( 'Facebook URL', 'thbusiness' ),
537                )
538        );
539
540        $wp_customize->add_setting(
541                'twitter_url',
542                array(
543                        'default'                       => '',
544                        'sanitize_callback'     => 'thbusiness_sanitize_url'
545                )
546        );
547
548        $wp_customize->add_control(
549                'twitter_url',
550                array(
551                        'settings'              => 'twitter_url',
552                        'section'               => 'thbusiness_social_media',
553                        'type'                  => 'url',
554                        'label'                 => __( 'Twitter URL', 'thbusiness' ),
555                )
556        );
557
558        $wp_customize->add_setting(
559                'googleplus_url',
560                array(
561                        'default'                       => '',
562                        'sanitize_callback'     => 'thbusiness_sanitize_url'
563                )
564        );
565
566        $wp_customize->add_control(
567                'googleplus_url',
568                array(
569                        'settings'              => 'googleplus_url',
570                        'section'               => 'thbusiness_social_media',
571                        'type'                  => 'url',
572                        'label'                 => __( 'Google Plus URL', 'thbusiness' ),
573                )
574        );
575
576        $wp_customize->add_setting(
577                'instagram_url',
578                array(
579                        'default'                       => '',
580                        'sanitize_callback'     => 'thbusiness_sanitize_url'
581                )
582        );
583
584        $wp_customize->add_control(
585                'instagram_url',
586                array(
587                        'settings'              => 'instagram_url',
588                        'section'               => 'thbusiness_social_media',
589                        'type'                  => 'url',
590                        'label'                 => __( 'Instagram Url', 'thbusiness' ),
591                )
592        );
593
594        $wp_customize->add_setting(
595                'linkedin_url',
596                array(
597                        'default'                       => '',
598                        'sanitize_callback'     => 'thbusiness_sanitize_url'
599                )
600        );
601
602        $wp_customize->add_control(
603                'linkedin_url',
604                array(
605                        'settings'              => 'linkedin_url',
606                        'section'               => 'thbusiness_social_media',
607                        'type'                  => 'url',
608                        'label'                 => __( 'Linkedin URL', 'thbusiness' ),
609                )
610        );
611
612        $wp_customize->add_setting(
613                'youtube_url',
614                array(
615                        'default'                       => '',
616                        'sanitize_callback'     => 'thbusiness_sanitize_url'
617                )
618        );
619
620        $wp_customize->add_control(
621                'youtube_url',
622                array(
623                        'settings'              => 'youtube_url',
624                        'section'               => 'thbusiness_social_media',
625                        'type'                  => 'url',
626                        'label'                 => __( 'Youtube URL', 'thbusiness' ),
627                )
628        );             
629
630        $wp_customize->add_setting(
631                'dribbble_url',
632                array(
633                        'default'                       => '',
634                        'sanitize_callback'     => 'thbusiness_sanitize_url'
635                )
636        );
637
638        $wp_customize->add_control(
639                'dribbble_url',
640                array(
641                        'settings'              => 'dribbble_url',
642                        'section'               => 'thbusiness_social_media',
643                        'type'                  => 'url',
644                        'label'                 => __( 'Dribbble URL', 'thbusiness' ),
645                )
646        );
647
648        $wp_customize->add_setting(
649                'github_url',
650                array(
651                        'default'                       => '',
652                        'sanitize_callback'     => 'thbusiness_sanitize_url'
653                )
654        );
655
656        $wp_customize->add_control(
657                'github_url',
658                array(
659                        'settings'              => 'github_url',
660                        'section'               => 'thbusiness_social_media',
661                        'type'                  => 'url',
662                        'label'                 => __( 'Github URL', 'thbusiness' ),
663                )
664        );     
665
666        $wp_customize->add_setting(
667                'flickr_url',
668                array(
669                        'default'                       => '',
670                        'sanitize_callback'     => 'thbusiness_sanitize_url'
671                )
672        );
673
674        $wp_customize->add_control(
675                'flickr_url',
676                array(
677                        'settings'              => 'flickr_url',
678                        'section'               => 'thbusiness_social_media',
679                        'type'                  => 'url',
680                        'label'                 => __( 'Flickr URL', 'thbusiness' ),
681                )
682        );     
683
684    $wp_customize->add_section( 
685        'thbusiness_pro_details', 
686        array(
687                        'title'                 => __( 'THBusiness Pro', 'thbusiness' ),
688                        'priority'              => 120
689                ) 
690        );
691
692        $wp_customize->add_setting( 
693                'thbusiness_pro_desc', 
694                array(
695                        'sanitize_callback'     => 'thbusiness_sanitize_html'
696                ) 
697        );
698
699        $wp_customize->add_control( 
700                new Thbusiness_Custom_Content( 
701                        $wp_customize, 
702                        'thbusiness_pro_desc', 
703                        array(
704                                'section'               => 'thbusiness_pro_details',
705                                'priority'              => 20,
706                                'label'                 => __( 'Do you want more features?', 'thbusiness' ),
707                                'content'               => __( 'Then consider buying <a href="http://themezhut.com/themes/thbusiness-pro/" target="_blank">Thbusiness Pro.</a><h4>Thbusiness Pro Features.</h4><ol><li>More Layouts.</li><li>Google Fonts.</li><li>Unlimited Colors.</li><li>More Page Templates.</li><li>More Widgets</li><li>More Customizer Options.</li><li>Released under GPL.</li></ol>And more..<p><a class="button" href="http://themezhut.com/demo/thbusiness-pro/" target="_blank">Thbusiness Pro Demo</a><a class="button button-primary" href="http://themezhut.com/themes/thbusiness-pro/" target="_blank">Thbusiness Pro Details</a></p>', 'thbusiness' ) . '</p>',
708                                //'description'         => __( 'Optional: Example Description.', 'thbusiness' ),
709                        ) 
710                ) 
711        );
712
713}
714add_action( 'customize_register', 'thbusiness_customize_register' );
715
716/**
717 * Image sanitization.
718 *
719 * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/
720 *
721 * @param string               $image   Image filename.
722 * @param WP_Customize_Setting $setting Setting instance.
723 * @return string The image filename if the extension is allowed; otherwise, the setting default.
724 */
725
726function thbusiness_sanitize_image( $image, $setting ) {
727        /*
728         * Array of valid image file types.
729         *
730         * The array includes image mime types that are included in wp_get_mime_types()
731         */
732    $mimes = array(
733        'jpg|jpeg|jpe' => 'image/jpeg',
734        'gif'          => 'image/gif',
735        'png'          => 'image/png',
736        'bmp'          => 'image/bmp',
737        'tif|tiff'     => 'image/tiff',
738        'ico'          => 'image/x-icon'
739    );
740        // Return an array with file extension and mime_type.
741    $file = wp_check_filetype( $image, $mimes );
742        // If $image has a valid mime_type, return it; otherwise, return the default.
743    return ( $file['ext'] ? $image : $setting->default );
744}
745
746/**
747 * Sanitize the logo title select option.
748 *
749 * @param string $logo_option.
750 * @return string (text_only|logo_only|display_none).
751 */
752function thbusiness_sanitize_logo_title_select( $logo_option ) {
753        if ( ! in_array( $logo_option, array( 'text_only', 'logo_only', 'display_none' ) ) ) {
754        $logo_option = 'text_only';
755    } 
756
757    return $logo_option;
758}
759
760/**
761 * Checkbox sanitization.
762 *
763 * Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked`
764 * as a boolean value, either TRUE or FALSE.
765 *
766 * @param bool $checked Whether the checkbox is checked.
767 * @return bool Whether the checkbox is checked.
768 */
769function thbusiness_sanitize_checkbox( $checked ) {
770        // Boolean check.
771        return ( ( isset( $checked ) && true == $checked ) ? true : false );
772}
773
774/**
775 * HTML sanitization
776 *
777 * @see wp_filter_post_kses() https://developer.wordpress.org/reference/functions/wp_filter_post_kses/
778 *
779 * @param string $html HTML to sanitize.
780 * @return string Sanitized HTML.
781 */
782function thbusiness_sanitize_html( $html ) {
783        return wp_filter_post_kses( $html );
784}
785
786/**
787 * CSS sanitization.
788 *
789 * @see wp_strip_all_tags() https://developer.wordpress.org/reference/functions/wp_strip_all_tags/
790 *
791 * @param string $css CSS to sanitize.
792 * @return string Sanitized CSS.
793 */
794function thbusiness_sanitize_css( $css ) {
795        return wp_strip_all_tags( $css );
796}
797
798/**
799 * Email sanitization callback.
800 *
801 * - Sanitization: email
802 * - Control: text
803 *
804 * Sanitization callback for 'email' type text controls. This callback sanitizes `$email`
805 * as a valid email address.
806 *
807 * @see sanitize_email() https://developer.wordpress.org/reference/functions/sanitize_key/
808 * @link sanitize_email() https://codex.wordpress.org/Function_Reference/sanitize_email
809 *
810 * @param string               $email   Email address to sanitize.
811 * @param WP_Customize_Setting $setting Setting instance.
812 * @return string The sanitized email if not null; otherwise, the setting default.
813 */
814function thbusiness_sanitize_email( $email, $setting ) {
815        // Sanitize $input as a hex value without the hash prefix.
816        $email = sanitize_email( $email );
817       
818        // return sanitized $email
819        return $email;
820}
821
822/**
823 * HEX Color sanitization
824 *
825 * @see sanitize_hex_color() https://developer.wordpress.org/reference/functions/sanitize_hex_color/
826 * @link sanitize_hex_color_no_hash() https://developer.wordpress.org/reference/functions/sanitize_hex_color_no_hash/
827 *
828 * @param string               $hex_color HEX color to sanitize.
829 * @param WP_Customize_Setting $setting   Setting instance.
830 * @return string The sanitized hex color if not empty; otherwise, the setting default.
831 */
832function thbusiness_sanitize_hex_color( $hex_color, $setting ) {
833        // Sanitize $input as a hex value without the hash prefix.
834        $hex_color = sanitize_hex_color( $hex_color );
835       
836        // If $input is a valid hex value, return it; otherwise, return the default.
837        return ( ! empty( $hex_color ) ? $hex_color : $setting->default );
838}
839
840/**
841 * Number sanitization callback example.
842 *
843 * - Sanitization: number_absint
844 * - Control: number
845 *
846 * Sanitization callback for 'number' type text inputs. This callback sanitizes `$number`
847 * as an absolute integer (whole number, zero or greater).
848 *
849 * NOTE: absint() can be passed directly as `$wp_customize->add_setting()` 'sanitize_callback'.
850 * It is wrapped in a callback here merely for example purposes.
851 *
852 * @see absint() https://developer.wordpress.org/reference/functions/absint/
853 *
854 * @param int                  $number  Number to sanitize.
855 * @param WP_Customize_Setting $setting Setting instance.
856 * @return int Sanitized number; otherwise, the setting default.
857 */
858function thbusiness_sanitize_number_absint( $number, $setting ) {
859        // Ensure $number is an absolute integer (whole number, zero or greater).
860        $number = absint( $number );
861       
862        // If the input is an absolute integer, return it; otherwise, return the default
863        return ( $number ? $number : $setting->default );
864}
865
866/**
867 * No-HTML sanitization callback example.
868 *
869 * - Sanitization: nohtml
870 * - Control: text, textarea, password
871 *
872 * Sanitization callback for 'nohtml' type text inputs. This callback sanitizes `$nohtml`
873 * to remove all HTML.
874 *
875 * NOTE: wp_filter_nohtml_kses() can be passed directly as `$wp_customize->add_setting()`
876 * 'sanitize_callback'. It is wrapped in a callback here merely for example purposes.
877 *
878 * @see wp_filter_nohtml_kses() https://developer.wordpress.org/reference/functions/wp_filter_nohtml_kses/
879 *
880 * @param string $nohtml The no-HTML content to sanitize.
881 * @return string Sanitized no-HTML content.
882 */
883function thbusiness_sanitize_nohtml( $nohtml ) {
884        return wp_filter_nohtml_kses( $nohtml );
885}
886
887/**
888 * URL sanitization.
889 *
890 * @see esc_url_raw() https://developer.wordpress.org/reference/functions/esc_url_raw/
891 *
892 * @param string $url URL to sanitize.
893 * @return string Sanitized URL.
894 */
895function thbusiness_sanitize_url( $url ) {
896        return esc_url_raw( $url );
897}
898
899/**
900 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
901 */
902function thbusiness_customize_preview_js() {
903        wp_enqueue_script( 'thbusiness_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
904}
905add_action( 'customize_preview_init', 'thbusiness_customize_preview_js' );
906
907
908
909/**
910 * Enqueue the customizer stylesheet.
911 */
912function thbusiness_enqueue_customizer_stylesheets() {
913
914    wp_register_style( 'thbusiness-customizer-css', get_template_directory_uri() . '/inc/customizer/assets/customizer.css', NULL, NULL, 'all' );
915    wp_enqueue_style( 'thbusiness-customizer-css' );
916    wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), '4.7.0' );
917
918}
919add_action( 'customize_controls_print_styles', 'thbusiness_enqueue_customizer_stylesheets' );
920
921
922
923/**
924 * Writes out the CSS as defined by the values in the Theme Customizer
925 * to the `head` element of the header template.
926 *
927 * @package thbusiness
928 */
929function thbusiness_customize_css() {
930       
931        $color = get_theme_mod( 'site_main_color', '#eb5937' );
932       
933        if ( $color != '#eb5937' ) : 
934
935?>
936
937        <style type="text/css">
938        <?php
939                echo 
940                'a:hover,
941                a:focus,
942                a:active {
943                        color: '.$color.';
944                }
945                blockquote {
946                        border-left: 3px solid '.$color.';
947                }
948                .main-navigation ul ul {
949                        border-top: 3px solid '.$color.';
950                }
951                .main-navigation li:hover > a {
952                        border-bottom: 3px solid '.$color.';
953                }
954                .main-navigation a:hover,
955                .main-navigation ul li.current-menu-item a,
956                .main-navigation ul li.current_page_ancestor a,
957                .main-navigation ul li.current-menu-ancestor a,
958                .main-navigation ul li.current_page_item a,
959                .main-navigation ul li:hover > a {
960                        color: '.$color.';
961                }
962                .widget-title {
963                        border-bottom: 3px solid '.$color.';
964                }
965                .th-services-box:hover .th-services-icon {
966                        border: 1px solid '.$color.';
967                        color: '.$color.';
968                }
969                .th-services-box:hover .th-morelink {
970                        background: '.$color.';
971                }
972                .th-morelink {
973                        color: '.$color.';
974                }
975                .th-morelink:visited {
976                        color: '.$color.';
977                }
978                .call-to-action-button {
979                        background: '.$color.';
980                }
981                .singlepage-widget-moretag {
982                        background: '.$color.';
983                }               
984                .moretag {
985                        background: '.$color.';
986                }
987                .comment-author .fn,
988                .comment-author .url,
989                .comment-reply-link,
990                .comment-reply-login {
991                        color: '.$color.';
992                }
993                a:hover.page-numbers {
994                        background-color: '.$color.';
995                }
996                .paging-navigation .current {
997                        background-color: '.$color.';
998                }
999                .page-links span a{
1000                        background: '.$color.';
1001                }
1002                .page-links a:hover {
1003                        background: '.$color.';
1004                }
1005                .th-slider-readmore-button a {
1006                        background: '.$color.';
1007                }
1008                .site-footer a:hover {
1009                        color: '.$color.';
1010                }
1011                .th-search-box-container {
1012                        border-top: 3px solid '.$color.';
1013                }
1014                .topbar-icon {
1015                        background: '.$color.';
1016                }
1017                #th-search-form input[type="submit"] {
1018                        background-color: '.$color.';
1019                }
1020                .wp-block-quote {
1021                        border-left: 3px solid '.$color.';
1022                }
1023                .wp-block-quote:not(.is-large):not(.is-style-large) {
1024                        border-left: 3px solid '.$color.';
1025                }';
1026        ?>
1027        </style>
1028<?php
1029        endif;
1030}
1031add_action( 'wp_head', 'thbusiness_customize_css' );
Note: See TracBrowser for help on using the repository browser.