Make WordPress Themes

source: sydney/1.59/functions.php

Last change on this file was 126346, checked in by themedropbox, 6 years ago

New version of Sydney - 1.59

File size: 14.8 KB
Line 
1<?php
2/**
3 * Sydney functions and definitions
4 *
5 * @package Sydney
6 */
7
8if ( ! function_exists( 'sydney_setup' ) ) :
9/**
10 * Sets up theme defaults and registers support for various WordPress features.
11 *
12 * Note that this function is hooked into the after_setup_theme hook, which
13 * runs before the init hook. The init hook is too late for some features, such
14 * as indicating support for post thumbnails.
15 */
16function sydney_setup() {
17
18        /*
19         * Make theme available for translation.
20         * Translations can be filed in the /languages/ directory.
21         * If you're building a theme based on Sydney, use a find and replace
22         * to change 'sydney' to the name of your theme in all the template files
23         */
24        load_theme_textdomain( 'sydney', get_template_directory() . '/languages' );
25
26        // Add default posts and comments RSS feed links to head.
27        add_theme_support( 'automatic-feed-links' );
28
29        // Content width
30        global $content_width;
31        if ( ! isset( $content_width ) ) {
32                $content_width = 1170; /* pixels */
33        }
34
35        /*
36         * Let WordPress manage the document title.
37         * By adding theme support, we declare that this theme does not use a
38         * hard-coded <title> tag in the document head, and expect WordPress to
39         * provide it for us.
40         */
41        add_theme_support( 'title-tag' );
42
43        /*
44         * Enable support for Post Thumbnails on posts and pages.
45         *
46         * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
47         */
48        add_theme_support( 'post-thumbnails' );
49        add_image_size('sydney-large-thumb', 830);
50        add_image_size('sydney-medium-thumb', 550, 400, true);
51        add_image_size('sydney-small-thumb', 230);
52        add_image_size('sydney-service-thumb', 350);
53        add_image_size('sydney-mas-thumb', 480);
54
55        // This theme uses wp_nav_menu() in one location.
56        register_nav_menus( array(
57                'primary' => __( 'Primary Menu', 'sydney' ),
58        ) );
59
60        /*
61         * Switch default core markup for search form, comment form, and comments
62         * to output valid HTML5.
63         */
64        add_theme_support( 'html5', array(
65                'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
66        ) );
67
68        /*
69         * Enable support for Post Formats.
70         * See http://codex.wordpress.org/Post_Formats
71         */
72        add_theme_support( 'post-formats', array(
73                'aside', 'image', 'video', 'quote', 'link',
74        ) );
75
76        // Set up the WordPress core custom background feature.
77        add_theme_support( 'custom-background', apply_filters( 'sydney_custom_background_args', array(
78                'default-color' => 'ffffff',
79                'default-image' => '',
80        ) ) );
81
82        //Gutenberg align-wide support
83        add_theme_support( 'align-wide' );
84}
85endif; // sydney_setup
86add_action( 'after_setup_theme', 'sydney_setup' );
87
88/**
89 * Register widget area.
90 *
91 * @link http://codex.wordpress.org/Function_Reference/register_sidebar
92 */
93function sydney_widgets_init() {
94        register_sidebar( array(
95                'name'          => __( 'Sidebar', 'sydney' ),
96                'id'            => 'sidebar-1',
97                'description'   => '',
98                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
99                'after_widget'  => '</aside>',
100                'before_title'  => '<h3 class="widget-title">',
101                'after_title'   => '</h3>',
102        ) );
103
104        //Footer widget areas
105        $widget_areas = get_theme_mod('footer_widget_areas', '3');
106        for ($i=1; $i<=$widget_areas; $i++) {
107                register_sidebar( array(
108                        'name'          => __( 'Footer ', 'sydney' ) . $i,
109                        'id'            => 'footer-' . $i,
110                        'description'   => '',
111                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
112                        'after_widget'  => '</aside>',
113                        'before_title'  => '<h3 class="widget-title">',
114                        'after_title'   => '</h3>',
115                ) );
116        }
117
118        //Register the front page widgets
119        if ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
120                register_widget( 'Sydney_List' );
121                register_widget( 'Sydney_Services_Type_A' );
122                register_widget( 'Sydney_Services_Type_B' );
123                register_widget( 'Sydney_Facts' );
124                register_widget( 'Sydney_Clients' );
125                register_widget( 'Sydney_Testimonials' );
126                register_widget( 'Sydney_Skills' );
127                register_widget( 'Sydney_Action' );
128                register_widget( 'Sydney_Video_Widget' );
129                register_widget( 'Sydney_Social_Profile' );
130                register_widget( 'Sydney_Employees' );
131                register_widget( 'Sydney_Latest_News' );
132                register_widget( 'Sydney_Portfolio' );
133        }
134        register_widget( 'Sydney_Contact_Info' );
135
136}
137add_action( 'widgets_init', 'sydney_widgets_init' );
138
139/**
140 * Load the front page widgets.
141 */
142if ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
143        require get_template_directory() . "/widgets/fp-list.php";
144        require get_template_directory() . "/widgets/fp-services-type-a.php";
145        require get_template_directory() . "/widgets/fp-services-type-b.php";
146        require get_template_directory() . "/widgets/fp-facts.php";
147        require get_template_directory() . "/widgets/fp-clients.php";
148        require get_template_directory() . "/widgets/fp-testimonials.php";
149        require get_template_directory() . "/widgets/fp-skills.php";
150        require get_template_directory() . "/widgets/fp-call-to-action.php";
151        require get_template_directory() . "/widgets/video-widget.php";
152        require get_template_directory() . "/widgets/fp-social.php";
153        require get_template_directory() . "/widgets/fp-employees.php";
154        require get_template_directory() . "/widgets/fp-latest-news.php";
155        require get_template_directory() . "/widgets/fp-portfolio.php";
156
157        /**
158         * Page builder support
159         */
160        require get_template_directory() . '/inc/page-builder.php';     
161}
162require get_template_directory() . "/widgets/contact-info.php";
163
164/**
165 * Elementor ID
166 */
167if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
168    define( 'ELEMENTOR_PARTNER_ID', 2128 );
169}
170
171/**
172 * Enqueue scripts and styles.
173 */
174function sydney_scripts() {
175
176        wp_enqueue_style( 'sydney-google-fonts', esc_url( sydney_enqueue_google_fonts() ), array(), null );
177
178        if ( is_customize_preview() ) {
179                wp_enqueue_style( 'sydney-preview-google-fonts-body', 'https://fonts.googleapis.com/', array(), null );
180                wp_enqueue_style( 'sydney-preview-google-fonts-headings', 'https://fonts.googleapis.com/', array(), null );
181        }
182
183        wp_enqueue_style( 'sydney-style', get_stylesheet_uri(), '', '20200129' );
184
185        wp_enqueue_style( 'sydney-ie9', get_template_directory_uri() . '/css/ie9.css', array( 'sydney-style' ) );
186        wp_style_add_data( 'sydney-ie9', 'conditional', 'lte IE 9' );
187
188        wp_enqueue_script( 'sydney-scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'', true );
189
190        wp_enqueue_script( 'sydney-main', get_template_directory_uri() . '/js/main.min.js', array('jquery'),'20180716', true );
191
192        if ( defined( 'SITEORIGIN_PANELS_VERSION' )     ) {
193                wp_enqueue_script( 'sydney-so-legacy-scripts', get_template_directory_uri() . '/js/so-legacy.js', array('jquery'),'', true );
194                wp_enqueue_script( 'sydney-so-legacy-main', get_template_directory_uri() . '/js/so-legacy-main.js', array('jquery'),'', true );
195                wp_enqueue_style( 'sydney-font-awesome', get_template_directory_uri() . '/fonts/font-awesome.min.css' );
196        }
197
198        if ( get_theme_mod('blog_layout') == 'masonry-layout' && (is_home() || is_archive()) ) {
199
200                wp_enqueue_script( 'sydney-masonry-init', get_template_directory_uri() . '/js/masonry-init.js', array('masonry'),'', true );
201        }
202
203        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
204                wp_enqueue_script( 'comment-reply' );
205        }
206}
207add_action( 'wp_enqueue_scripts', 'sydney_scripts' );
208
209/**
210 * Disable Elementor globals on theme activation
211 */
212function sydney_disable_elementor_globals () {
213        update_option( 'elementor_disable_color_schemes', 'yes' );
214        update_option( 'elementor_disable_typography_schemes', 'yes' );
215}
216add_action('after_switch_theme', 'sydney_disable_elementor_globals');
217
218/**
219 * Enqueue Bootstrap
220 */
221function sydney_enqueue_bootstrap() {
222        wp_enqueue_style( 'sydney-bootstrap', get_template_directory_uri() . '/css/bootstrap/bootstrap.min.css', array(), true );
223}
224add_action( 'wp_enqueue_scripts', 'sydney_enqueue_bootstrap', 9 );
225
226/**
227 * Elementor editor scripts
228 */
229
230/**
231 * Change the excerpt length
232 */
233function sydney_excerpt_length( $length ) {
234
235  $excerpt = get_theme_mod('exc_lenght', '55');
236  return $excerpt;
237
238}
239add_filter( 'excerpt_length', 'sydney_excerpt_length', 999 );
240
241/**
242 * Blog layout
243 */
244function sydney_blog_layout() {
245        $layout = get_theme_mod('blog_layout','classic-alt');
246        return $layout;
247}
248
249/**
250 * Menu fallback
251 */
252function sydney_menu_fallback() {
253        if ( current_user_can('edit_theme_options') ) {
254                echo '<a class="menu-fallback" href="' . admin_url('nav-menus.php') . '">' . __( 'Create your menu here', 'sydney' ) . '</a>';
255        }
256}
257
258/**
259 * Header image overlay
260 */
261function sydney_header_overlay() {
262        $overlay = get_theme_mod( 'hide_overlay', 0);
263        if ( !$overlay ) {
264                echo '<div class="overlay"></div>';
265        }
266}
267
268/**
269 * Header video
270 */
271function sydney_header_video() {
272
273        if ( !function_exists('the_custom_header_markup') ) {
274                return;
275        }
276
277        $front_header_type      = get_theme_mod( 'front_header_type' );
278        $site_header_type       = get_theme_mod( 'site_header_type' );
279
280        if ( ( get_theme_mod('front_header_type') == 'core-video' && is_front_page() || get_theme_mod('site_header_type') == 'core-video' && !is_front_page() ) ) {
281                the_custom_header_markup();
282        }
283}
284
285/**
286 * Polylang compatibility
287 */
288if ( function_exists('pll_register_string') ) :
289function sydney_polylang() {
290        for ( $i=1; $i<=5; $i++) {
291                pll_register_string('Slide title ' . $i, get_theme_mod('slider_title_' . $i), 'Sydney');
292                pll_register_string('Slide subtitle ' . $i, get_theme_mod('slider_subtitle_' . $i), 'Sydney');
293        }
294        pll_register_string('Slider button text', get_theme_mod('slider_button_text'), 'Sydney');
295        pll_register_string('Slider button URL', get_theme_mod('slider_button_url'), 'Sydney');
296}
297add_action( 'admin_init', 'sydney_polylang' );
298endif;
299
300/**
301 * Preloader
302 */
303function sydney_preloader() {
304        ?>
305        <div class="preloader">
306            <div class="spinner">
307                <div class="pre-bounce1"></div>
308                <div class="pre-bounce2"></div>
309            </div>
310        </div>
311        <?php
312}
313add_action('sydney_before_site', 'sydney_preloader');
314
315/**
316 * Header clone
317 */
318function sydney_header_clone() {
319
320        $front_header_type      = get_theme_mod('front_header_type','nothing');
321        $site_header_type       = get_theme_mod('site_header_type');
322
323        if ( ( $front_header_type == 'nothing' && is_front_page() ) || ( $site_header_type == 'nothing' && !is_front_page() ) ) { ?>
324       
325        <div class="header-clone"></div>
326
327        <?php }
328}
329add_action('sydney_before_header', 'sydney_header_clone');
330
331/**
332 * Get image alt
333 */
334function sydney_get_image_alt( $image ) {
335    global $wpdb;
336
337    if( empty( $image ) ) {
338        return false;
339    }
340
341    $attachment  = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", strtolower( $image ) ) );
342    $id   = ( ! empty( $attachment ) ) ? $attachment[0] : 0;
343
344    $alt = get_post_meta( $id, '_wp_attachment_image_alt', true );
345
346    return $alt;
347}
348
349/**
350 * Fix skip link focus in IE11.
351 *
352 * This does not enqueue the script because it is tiny and because it is only for IE11,
353 * thus it does not warrant having an entire dedicated blocking script being loaded.
354 *
355 * from TwentyTwenty
356 *
357 * @link https://git.io/vWdr2
358 */
359function sydney_skip_link_focus_fix() {
360        ?>
361        <script>
362        /(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);
363        </script>
364        <?php
365}
366add_action( 'wp_print_footer_scripts', 'sydney_skip_link_focus_fix' );
367
368/**
369 * Get SVG code for specific theme icon
370 */
371function sydney_get_svg_icon( $icon, $echo = false ) {
372        $svg_code = wp_kses( //From TwentTwenty. Keeps only allowed tags and attributes
373                Sydney_SVG_Icons::get_svg_icon( $icon ),
374                array(
375                        'svg'     => array(
376                                'class'       => true,
377                                'xmlns'       => true,
378                                'width'       => true,
379                                'height'      => true,
380                                'viewbox'     => true,
381                                'aria-hidden' => true,
382                                'role'        => true,
383                                'focusable'   => true,
384                        ),
385                        'path'    => array(
386                                'fill'      => true,
387                                'fill-rule' => true,
388                                'd'         => true,
389                                'transform' => true,
390                        ),
391                        'polygon' => array(
392                                'fill'      => true,
393                                'fill-rule' => true,
394                                'points'    => true,
395                                'transform' => true,
396                                'focusable' => true,
397                        ),
398                )
399        );     
400
401        if ( $echo != false ) {
402                echo $svg_code; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
403        } else {
404                return $svg_code;
405        }
406}
407
408/**
409 * Implement the Custom Header feature.
410 */
411require get_template_directory() . '/inc/custom-header.php';
412
413/**
414 * Custom template tags for this theme.
415 */
416require get_template_directory() . '/inc/template-tags.php';
417
418/**
419 * Custom functions that act independently of the theme templates.
420 */
421require get_template_directory() . '/inc/extras.php';
422
423/**
424 * Customizer additions.
425 */
426require get_template_directory() . '/inc/customizer.php';
427
428/**
429 * Load Jetpack compatibility file.
430 */
431require get_template_directory() . '/inc/jetpack.php';
432
433/**
434 * Slider
435 */
436require get_template_directory() . '/inc/slider.php';
437
438/**
439 * Styles
440 */
441require get_template_directory() . '/inc/styles.php';
442
443/**
444 * Theme info
445 */
446require get_template_directory() . '/inc/onboarding/theme-info.php';
447
448/**
449 * Woocommerce basic integration
450 */
451require get_template_directory() . '/inc/woocommerce.php';
452
453/**
454 * Upsell
455 */
456require get_template_directory() . '/inc/upsell/class-customize.php';
457
458/**
459 * Gutenberg
460 */
461require get_template_directory() . '/inc/editor.php';
462
463/**
464 * Fonts
465 */
466require get_template_directory() . '/inc/fonts.php';
467
468/**
469 * SVG codes
470 */
471require get_template_directory() . '/inc/classes/class-sydney-svg-icons.php';
472
473/**
474 *TGM Plugin activation.
475 */
476require_once dirname( __FILE__ ) . '/plugins/class-tgm-plugin-activation.php';
477
478add_action( 'tgmpa_register', 'sydney_recommend_plugin' );
479function sydney_recommend_plugin() {
480
481        $plugins = array();
482
483        if ( !defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
484            $plugins[] = array(
485                    'name'               => 'Elementor',
486                    'slug'               => 'elementor',
487                    'required'           => false,
488            );
489        }
490
491        if ( !function_exists('wpcf_init') ) {
492            $plugins[] = array(
493                        'name'               => 'Sydney Toolbox - custom posts and fields for the Sydney theme',
494                        'slug'               => 'sydney-toolbox',
495                        'required'           => false,
496                );
497        }
498
499    tgmpa( $plugins);
500
501}
502
503/**
504 * Admin notice
505 */
506require get_template_directory() . '/inc/notices/persist-admin-notices-dismissal.php';
507
508function sydney_welcome_admin_notice() {
509        if ( ! PAnD::is_admin_notice_active( 'sydney-welcome-forever' ) ) {
510                return;
511        }
512       
513        ?>
514        <div data-dismissible="sydney-welcome-forever" class="sydney-admin-notice updated notice notice-success is-dismissible">
515
516                <p><?php echo sprintf( __( 'Welcome to Sydney. To get started please make sure to visit our <a href="%s">welcome page</a>.', 'sydney' ), admin_url( 'themes.php?page=sydney-info.php' ) ); ?></p>
517                <a class="button" href="<?php echo admin_url( 'themes.php?page=sydney-info.php' ); ?>"><?php esc_html_e( 'Get started with Sydney', 'sydney' ); ?></a>
518
519        </div>
520        <?php
521}
522add_action( 'admin_init', array( 'PAnD', 'init' ) );
523add_action( 'admin_notices', 'sydney_welcome_admin_notice' );
Note: See TracBrowser for help on using the repository browser.