Make WordPress Themes

source: multisport/1.6.0/functions.php

Last change on this file was 218390, checked in by themedropbox, 21 months ago

New version of MultiSport - 1.5.8

File size: 14.2 KB
Line 
1<?php
2/**
3 * MultiSport functions and definitions
4 *
5 * Set up the theme and provides some helper functions, which are used in the
6 * theme as custom template tags. Others are attached to action and filter
7 * hooks in WordPress to change core functionality.
8 *
9 * When using a child theme you can override certain functions (those wrapped
10 * in a function_exists() call) by defining them first in your child theme's
11 * functions.php file. The child theme's functions.php file is included before
12 * the parent theme's file, so the child theme functions would be used.
13 *
14 */
15
16/**
17 * Set a constant that holds the theme's minimum supported PHP version.
18 */
19define( 'MULTISPORT_MIN_PHP_VERSION', '7.0' );
20
21/**
22 * Immediately after theme switch is fired we we want to check php version and
23 * revert to previously active theme if version is below our minimum.
24 */
25add_action( 'after_switch_theme', 'multisport_test_for_min_php' );
26
27/**
28 * Switches back to the previous theme if the minimum PHP version is not met.
29 */
30function multisport_test_for_min_php() {
31
32        // Compare versions.
33        if ( version_compare( PHP_VERSION, MULTISPORT_MIN_PHP_VERSION, '<' ) ) {
34                // Site doesn't meet themes min php requirements, add notice...
35                add_action( 'admin_notices', 'multisport_min_php_not_met_notice' );
36                // ... and switch back to previous theme.
37                switch_theme( get_option( 'theme_switched' ) );
38                return false;
39
40        };
41}
42
43if ( ! function_exists( 'wp_body_open' ) ) {
44        function wp_body_open() {
45                do_action( 'wp_body_open' );
46        }
47}
48
49/**
50 * An error notice that can be displayed if the Minimum PHP version is not met.
51 */
52function multisport_min_php_not_met_notice() {
53        ?>
54        <div class="notice notice-error is_dismissable">
55                <p>
56                        <?php esc_html_e( 'You need to update your PHP version to run this theme.', 'multisport' ); ?> <br />
57                        <?php
58                        printf(
59                                /* translators: 1 is the current PHP version string, 2 is the minmum supported php version string of the theme */
60                                esc_html__( 'Actual version is: %1$s, required version is: %2$s.', 'multisport' ),
61                                PHP_VERSION,
62                                MULTISPORT_MIN_PHP_VERSION
63                        ); // phpcs: XSS ok.
64                        ?>
65                </p>
66        </div>
67        <?php
68}
69
70
71require_once( trailingslashit( get_template_directory() ) . 'inc/customize-pro/class-customize.php' );
72
73if ( ! function_exists( 'multisport_setup' ) ) :
74        /**
75         * MultiSport setup.
76         *
77         * Set up theme defaults and registers support for various WordPress features.
78         *
79         * Note that this function is hooked into the after_setup_theme hook, which
80         * runs before the init hook. The init hook is too late for some features, such
81         * as indicating support post thumbnails.
82         *
83         */
84        function multisport_setup() {
85
86                /*
87                 * Make theme available for translation.
88                 *
89                 * Translations can be filed in the /languages/ directory
90                 *
91                 * If you're building a theme based on MultiSport, use a find and replace
92                 * to change 'multisport' to the name of your theme in all the template files.
93                 */
94                load_theme_textdomain( 'multisport', get_template_directory() . '/languages' );
95
96                // Add default posts and comments RSS feed links to head.
97                add_theme_support( 'automatic-feed-links' );
98
99                /*
100                 * Let WordPress manage the document title.
101                 * By adding theme support, we declare that this theme does not use a
102                 * hard-coded <title> tag in the document head, and expect WordPress to
103                 * provide it for us.
104                 */
105                add_theme_support( 'title-tag' );
106
107                /*
108                 * Enable support for Post Thumbnails on posts and pages.
109                 */
110                add_theme_support( 'post-thumbnails' );
111
112
113
114                /*
115                 * Switch default core markup for search form, comment form, and comments
116                 * to output valid HTML5.
117                 */
118                add_theme_support( 'html5', array(
119                        'comment-form',
120                        'comment-list',
121                        'gallery',
122                        'caption',
123                ) );
124
125                // Add support for Block Styles.
126                add_theme_support( 'wp-block-styles' );
127
128                add_theme_support( 'editor-styles' );
129
130                /*
131                 * This theme styles the visual editor to resemble the theme style,
132                 * specifically font, colors, and column width.
133                 */
134                add_editor_style( array( 'assets/css/editor-style.css', 
135                                                                 get_template_directory_uri() . '/assets/css/font-awesome.css',
136                                                                 
137                                                  ) );
138
139                /*
140                 * Set Custom Background
141                 */                             
142                add_theme_support( 'custom-background', array ('default-color'  => '#ffffff') );
143
144                // Set the default content width.
145                $GLOBALS['content_width'] = 900;
146
147                // This theme uses wp_nav_menu() in header menu
148                register_nav_menus( array(
149                        'primary'   => __( 'Primary Menu', 'multisport' ),
150                        'footer'    => __( 'Footer Menu', 'multisport' ),
151                ) );
152
153                $defaults = array(
154                'flex-height' => false,
155                'flex-width'  => false,
156                'header-text' => array( 'site-title', 'site-description' ),
157            );
158            add_theme_support( 'custom-logo', $defaults );
159
160            // Define and register starter content to showcase the theme on new sites.
161                $starter_content = array(
162
163                        'widgets' => array(
164                                'sidebar-widget-area' => array(
165                                        'search',
166                                        'recent-posts',
167                                        'categories',
168                                        'archives',
169                                ),
170
171
172
173                                'footer-column-1-widget-area' => array(
174                                        'recent-comments'
175                                ),
176
177                                'footer-column-2-widget-area' => array(
178                                        'recent-posts'
179                                ),
180
181                                'footer-column-3-widget-area' => array(
182                                        'calendar'
183                                ),
184                        ),
185
186                        'posts' => array(
187                                'home',
188                                'blog',
189                                'about',
190                                'contact'
191                        ),
192
193                        // Default to a static front page and assign the front and posts pages.
194                        'options' => array(
195                                'show_on_front' => 'page',
196                                'page_on_front' => '{{home}}',
197                                'page_for_posts' => '{{blog}}',
198                        ),
199
200                        // Set the front page section theme mods to the IDs of the core-registered pages.
201                        'theme_mods' => array(
202                                'multisport_slider_display' => 1,
203                                'multisport_slide1_image' => esc_url( get_template_directory_uri() . '/images/slider/1.jpg' ),
204                                'multisport_slide2_image' => esc_url( get_template_directory_uri() . '/images/slider/2.jpg' ),
205                                'multisport_slide3_image' => esc_url( get_template_directory_uri() . '/images/slider/3.jpg' ),
206                        ),
207
208                        'nav_menus' => array(
209
210                                // Assign a menu to the "primary" location.
211                                'primary' => array(
212                                        'name' => __( 'Primary Menu', 'multisport' ),
213                                        'items' => array(
214                                                'link_home',
215                                                'page_blog',
216                                                'page_contact',
217                                                'page_about',
218                                        ),
219                                ),
220
221                                // Assign a menu to the "footer" location.
222                                'footer' => array(
223                                        'name' => __( 'Footer Menu', 'multisport' ),
224                                        'items' => array(
225                                                'link_home',
226                                                'page_about',
227                                                'page_blog',
228                                                'page_contact',
229                                        ),
230                                ),
231                        ),
232                );
233
234                $starter_content = apply_filters( 'multisport_starter_content', $starter_content );
235                add_theme_support( 'starter-content', $starter_content );
236        }
237endif; // multisport_setup
238add_action( 'after_setup_theme', 'multisport_setup' );
239
240
241if ( ! function_exists( 'multisport_load_scripts' ) ) :
242        /**
243         * the main function to load scripts in the MultiSport theme
244         * if you add a new load of script, style, etc. you can use that function
245         * instead of adding a new wp_enqueue_scripts action for it.
246         */
247        function multisport_load_scripts() {
248
249                // load main stylesheet.
250                wp_enqueue_style( 'font-awesome',
251                        get_template_directory_uri() . '/assets/css/font-awesome.css', array( ) );
252
253                wp_enqueue_style( 'animate-css',
254                        get_template_directory_uri() . '/assets/css/animate.css', array( ) );
255
256                wp_enqueue_style( 'multisport-style', get_stylesheet_uri(), array() );
257               
258               
259               
260                if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
261                        wp_enqueue_script( 'comment-reply' );
262                }
263
264                wp_enqueue_script( 'viewportchecker',
265                        get_template_directory_uri() . '/assets/js/viewportchecker.js',
266            array( 'jquery' ) );
267               
268                // Load Utilities JS Script
269                wp_enqueue_script( 'multisport-utilities',
270                        get_template_directory_uri() . '/assets/js/utilities.js',
271                        array( 'jquery', 'viewportchecker' ) );
272
273                $data = array(
274                'loading_effect' => ( get_theme_mod('multisport_animations_display', 1) == 1 ),
275            );
276            wp_localize_script('multisport-utilities', 'multisport_options', $data);
277
278            // Load Slider JS Scripts
279                wp_enqueue_script( 'jquery-easing-1-3',
280                        get_template_directory_uri() . '/assets/js/jquery.easing.js',
281                        array( 'jquery' ) );
282
283                wp_enqueue_script( 'jquery-eislideshow',
284                        get_template_directory_uri() . '/assets/js/jquery.eislideshow.js',
285                        array( 'jquery', 'jquery-easing-1-3' ) );
286        }
287endif; // multisport_load_scripts
288add_action( 'wp_enqueue_scripts', 'multisport_load_scripts' );
289
290if ( ! function_exists( 'multisport_widgets_init' ) ) :
291        /**
292         *      widgets-init action handler. Used to register widgets and register widget areas
293         */
294        function multisport_widgets_init() {
295               
296                // Register Sidebar Widget.
297                register_sidebar( array (
298                                                        'name'                   =>      __( 'Sidebar Widget Area', 'multisport'),
299                                                        'id'                     =>      'sidebar-widget-area',
300                                                        'description'    =>  __( 'The sidebar widget area', 'multisport'),
301                                                        'before_widget'  =>  '',
302                                                        'after_widget'   =>  '',
303                                                        'before_title'   =>  '<div class="sidebar-before-title"></div><h3 class="sidebar-title">',
304                                                        'after_title'    =>  '</h3><div class="sidebar-after-title"></div>',
305                                                ) );
306
307                // Register Footer Column #1
308                register_sidebar( array (
309                                                                'name'                   =>  __( 'Footer Column #1', 'multisport' ),
310                                                                'id'                     =>  'footer-column-1-widget-area',
311                                                                'description'    =>  __( 'The Footer Column #1 widget area', 'multisport' ),
312                                                                'before_widget'  =>  '',
313                                                                'after_widget'   =>  '',
314                                                                'before_title'   =>  '<h2 class="footer-title">',
315                                                                'after_title'    =>  '</h2><div class="footer-after-title"></div>',
316                                                        ) );
317               
318                // Register Footer Column #2
319                register_sidebar( array (
320                                                                'name'                   =>  __( 'Footer Column #2', 'multisport' ),
321                                                                'id'                     =>  'footer-column-2-widget-area',
322                                                                'description'    =>  __( 'The Footer Column #2 widget area', 'multisport' ),
323                                                                'before_widget'  =>  '',
324                                                                'after_widget'   =>  '',
325                                                                'before_title'   =>  '<h2 class="footer-title">',
326                                                                'after_title'    =>  '</h2><div class="footer-after-title"></div>',
327                                                        ) );
328               
329                // Register Footer Column #3
330                register_sidebar( array (
331                                                                'name'                   =>  __( 'Footer Column #3', 'multisport' ),
332                                                                'id'                     =>  'footer-column-3-widget-area',
333                                                                'description'    =>  __( 'The Footer Column #3 widget area', 'multisport' ),
334                                                                'before_widget'  =>  '',
335                                                                'after_widget'   =>  '',
336                                                                'before_title'   =>  '<h2 class="footer-title">',
337                                                                'after_title'    =>  '</h2><div class="footer-after-title"></div>',
338                                                        ) );
339        }
340endif; // multisport_widgets_init
341add_action( 'widgets_init', 'multisport_widgets_init' );
342
343if ( ! function_exists( 'multisport_show_copyright_text' ) ) :
344        /**
345         *      Displays the copyright text.
346         */
347        function multisport_show_copyright_text() {
348
349                $footerText = esc_html( get_theme_mod('multisport_footer_copyright', null) );
350
351                if ( !empty( $footerText ) ) {
352
353                        echo esc_html( $footerText ) . ' | ';           
354                }
355        }
356endif; // multisport_show_copyright_text
357
358if ( ! function_exists( 'multisport_display_slider' ) ) :
359/**
360 * Displays Slider
361 */
362function multisport_display_slider() {
363        ?>
364                <div class="slider-wrapper">
365                <div id="ei-slider" class="ei-slider">
366                                <ul class="ei-slider-large">
367        <?php
368                                for ( $i = 1; $i <= 3; ++$i ) {
369       
370                                        $defaultSlideImage = get_template_directory_uri().'/images/slider/' . $i .'.jpg';
371
372                                        $slideImage = get_theme_mod( 'multisport_slide'.$i.'_image', $defaultSlideImage );
373        ?>
374                                        <li>
375                                                <img src="<?php echo esc_attr($slideImage); ?>" class="sldr-img" />
376                                        </li>
377        <?php
378                                }
379        ?>
380                          </ul><!-- .ei-slider-large -->
381
382                          <ul class="ei-slider-thumbs">
383                                        <li class="ei-slider-element"></li>
384        <?php
385                                        /**
386                                         * Display slider thumbnail images
387                                         *
388                                         */
389                                        for ( $i = 1; $i <= 3; ++$i ) {
390
391                                                $defaultSlideImage = get_template_directory_uri().'/images/slider/' . $i .'.jpg';
392
393                                                $slideImage = get_theme_mod( 'multisport_slide'.$i.'_image', $defaultSlideImage );
394        ?>
395                                                <li>
396                                                        <a href="#"></a>
397                                                        <img src="<?php echo esc_attr($slideImage); ?>" class="sldr-img" />
398                                                </li>
399        <?php
400                                        } // end of slider thumbnail images for
401?>
402                          </ul><!-- .ei-slider-thumbs -->
403                        </div><!-- .ei-slider -->
404                </div><!-- .slider-wrapper -->
405        <?php
406        }
407endif; // multisport_display_slider
408
409/**
410 * Implement the Custom Header feature.
411 */
412require get_template_directory() . '/inc/custom-header.php';
413
414/**
415 * Customizer additions.
416 */
417require get_template_directory() . '/inc/customizer.php';
418
419/**
420 * Fix skip link focus in IE11.
421 *
422 * This does not enqueue the script because it is tiny and because it is only for IE11,
423 * thus it does not warrant having an entire dedicated blocking script being loaded.
424 *
425 * @link https://git.io/vWdr2
426 */
427function multisport_skip_link_focus_fix() {
428        // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
429        ?>
430        <script>
431        /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
432        </script>
433        <?php
434}
435add_action( 'wp_print_footer_scripts', 'multisport_skip_link_focus_fix' );
436
437function multisport_register_block_styles() {
438
439        register_block_style(
440                'core/button',
441                array(
442                        'name'  => 'btn',
443                        'label' => __( 'Hover Effect', 'multisport' ),
444                )
445        );
446
447        register_block_style(
448                'core/group',
449                array(
450                        'name'  => 'tgroup',
451                        'label' => __( 'Margin Bottom Space', 'multisport' ),
452                )
453        );
454
455        register_block_style(
456                'core/site-title',
457                array(
458                        'name'  => 'tsitetitle',
459                        'label' => __( 'Bold', 'multisport' ),
460                )
461        );
462
463        register_block_style(
464                'core/post-title',
465                array(
466                        'name'  => 'tposttitle',
467                        'label' => __( 'Bold', 'multisport' ),
468                )
469        );
470
471        register_block_style(
472                'core/social-link',
473                array(
474                        'name'  => 'tsociallinks',
475                        'label' => __( 'Square', 'multisport' ),
476                )
477        );
478}
479add_action( 'init', 'multisport_register_block_styles' );
Note: See TracBrowser for help on using the repository browser.