From ad03eb383a1d7deb8bf9554bf8f826a99d6cd1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Ko=CC=88nemann?= Date: Tue, 1 Nov 2016 20:36:43 +0100 Subject: [PATCH] Making all function pluggable --- inc/customizer.php | 94 ++++++++++++++++++++++++--------------------- inc/enqueue.php | 60 +++++++++++++++-------------- inc/extras.php | 49 +++++++++++++---------- inc/jetpack.php | 38 ++++++++++-------- inc/setup.php | 13 ++++--- inc/widgets.php | 78 +++++++++++++++++++------------------ inc/woocommerce.php | 6 ++- inc/wpcom.php | 24 ++++++------ 8 files changed, 197 insertions(+), 165 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index a44c2abb..290ab0c7 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -10,60 +10,64 @@ * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ -function understrap_customize_register( $wp_customize ) { - $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; - $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; - $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; +if ( ! function_exists ( 'understrap_customize_register' ) ) { + function understrap_customize_register( $wp_customize ) { + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; + } } add_action( 'customize_register', 'understrap_customize_register' ); -function understrap_theme_customize_register( $wp_customize ) { +if ( ! function_exists ( 'understrap_theme_customize_register' ) ) { + function understrap_theme_customize_register( $wp_customize ) { - $wp_customize->add_section( 'understrap_theme_slider_options', array( - 'title' => __( 'Slider Settings', 'understrap' ) - ) ); + $wp_customize->add_section( 'understrap_theme_slider_options', array( + 'title' => __( 'Slider Settings', 'understrap' ) + ) ); - $wp_customize->add_setting( 'understrap_theme_slider_count_setting', array( - 'default' => '1', - 'sanitize_callback' => 'absint' - ) ); + $wp_customize->add_setting( 'understrap_theme_slider_count_setting', array( + 'default' => '1', + 'sanitize_callback' => 'absint' + ) ); - $wp_customize->add_control( 'understrap_theme_slider_count', array( - 'label' => __( 'Number of slides displaying at once', 'understrap' ), - 'section' => 'understrap_theme_slider_options', - 'type' => 'text', - 'settings' => 'understrap_theme_slider_count_setting' - ) ); + $wp_customize->add_control( 'understrap_theme_slider_count', array( + 'label' => __( 'Number of slides displaying at once', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_count_setting' + ) ); - $wp_customize->add_setting( 'understrap_theme_slider_time_setting', array( - 'default' => '5000', - 'sanitize_callback' => 'absint' - ) ); + $wp_customize->add_setting( 'understrap_theme_slider_time_setting', array( + 'default' => '5000', + 'sanitize_callback' => 'absint' + ) ); - $wp_customize->add_control( 'understrap_theme_slider_time', array( - 'label' => __( 'Slider Time (in ms)', 'understrap' ), - 'section' => 'understrap_theme_slider_options', - 'type' => 'text', - 'settings' => 'understrap_theme_slider_time_setting' - ) ); + $wp_customize->add_control( 'understrap_theme_slider_time', array( + 'label' => __( 'Slider Time (in ms)', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_time_setting' + ) ); - $wp_customize->add_setting( 'understrap_theme_slider_loop_setting', array( - 'default' => 'true', - 'sanitize_callback' => 'esc_textarea' - ) ); + $wp_customize->add_setting( 'understrap_theme_slider_loop_setting', array( + 'default' => 'true', + 'sanitize_callback' => 'esc_textarea' + ) ); - $wp_customize->add_control( 'understrap_theme_loop', array( - 'label' => __( 'Loop Slider Content', 'understrap' ), - 'section' => 'understrap_theme_slider_options', - 'type' => 'radio', - 'choices' => array( - 'true' => 'yes', - 'false' => 'no', - ), - 'settings' => 'understrap_theme_slider_loop_setting' - ) ); + $wp_customize->add_control( 'understrap_theme_loop', array( + 'label' => __( 'Loop Slider Content', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'radio', + 'choices' => array( + 'true' => 'yes', + 'false' => 'no', + ), + 'settings' => 'understrap_theme_slider_loop_setting' + ) ); + } } add_action( 'customize_register', 'understrap_theme_customize_register' ); @@ -72,7 +76,9 @@ add_action( 'customize_register', 'understrap_theme_customize_register' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ -function understrap_customize_preview_js() { - wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); +if ( ! function_exists ( 'understrap_customize_preview_js' ) ) { + function understrap_customize_preview_js() { + wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); + } } add_action( 'customize_preview_init', 'understrap_customize_preview_js' ); diff --git a/inc/enqueue.php b/inc/enqueue.php index cee17646..c9cc8b48 100644 --- a/inc/enqueue.php +++ b/inc/enqueue.php @@ -5,29 +5,31 @@ * @package understrap */ -function understrap_scripts() { - wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), '0.4.9' ); - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), '0.4.9', true ); +if ( ! function_exists ( 'understrap_scripts' ) ) { + function understrap_scripts() { + wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), '0.4.9' ); + wp_enqueue_script( 'jquery' ); + wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), '0.4.9', true ); - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { - wp_enqueue_script( 'comment-reply' ); - } + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); + } - // menu - vertical page association - if ( is_page_template( 'page-templates/vertical-one-page.php' ) || is_home() || is_single() ) { - wp_enqueue_script( 'vertical-one-page', get_template_directory_uri() . '/js/vertical-one-page.js', array( 'jquery' ), '0.4.9', true ); - $page_for_posts = strtolower( get_the_title( get_option( 'page_for_posts' ) ) ); - $home_url = home_url(); - $is_single = is_single(); - $vars = array( - 'pageForPosts' => $page_for_posts, - 'homeUrl' => $home_url, - 'isSingle' => $is_single - ); - wp_localize_script( 'vertical-one-page', 'vars', $vars ); + // menu - vertical page association + if ( is_page_template( 'page-templates/vertical-one-page.php' ) || is_home() || is_single() ) { + wp_enqueue_script( 'vertical-one-page', get_template_directory_uri() . '/js/vertical-one-page.js', array( 'jquery' ), '0.4.9', true ); + $page_for_posts = strtolower( get_the_title( get_option( 'page_for_posts' ) ) ); + $home_url = home_url(); + $is_single = is_single(); + $vars = array( + 'pageForPosts' => $page_for_posts, + 'homeUrl' => $home_url, + 'isSingle' => $is_single + ); + wp_localize_script( 'vertical-one-page', 'vars', $vars ); + } + // menu - vertical page association end } - // menu - vertical page association end } add_action( 'wp_enqueue_scripts', 'understrap_scripts' ); @@ -39,15 +41,17 @@ add_action( 'wp_enqueue_scripts', 'understrap_scripts' ); if ( is_active_sidebar( 'hero' ) ): add_action( "wp_enqueue_scripts", "understrap_slider" ); - function understrap_slider() { - if ( is_front_page() ) { - $data = array( - "timeout" => intval( get_theme_mod( 'understrap_theme_slider_time_setting', 5000 ) ), - "items" => intval( get_theme_mod( 'understrap_theme_slider_count_setting', 1 ) ) - ); + if ( ! function_exists ( 'understrap_slider' ) ) { + function understrap_slider() { + if ( is_front_page() ) { + $data = array( + "timeout" => intval( get_theme_mod( 'understrap_theme_slider_time_setting', 5000 ) ), + "items" => intval( get_theme_mod( 'understrap_theme_slider_count_setting', 1 ) ) + ); - wp_enqueue_script( "understrap-slider-script", get_stylesheet_directory_uri() . '/js/slider_settings.js', array(), '0.4.9' ); - wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data ); + wp_enqueue_script( "understrap-slider-script", get_stylesheet_directory_uri() . '/js/slider_settings.js', array(), '0.4.9' ); + wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data ); + } } } endif; diff --git a/inc/extras.php b/inc/extras.php index 01a489d0..965926ff 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -12,37 +12,46 @@ * @param array $classes Classes for the body element. * @return array */ -function understrap_body_classes( $classes ) { - // Adds a class of group-blog to blogs with more than 1 published author. - if ( is_multi_author() ) { - $classes[] = 'group-blog'; + +if ( ! function_exists ( 'understrap_body_classes' ) ) { + function understrap_body_classes( $classes ) { + // Adds a class of group-blog to blogs with more than 1 published author. + if ( is_multi_author() ) { + $classes[] = 'group-blog'; + } + // Adds a class of hfeed to non-singular pages. + if ( ! is_singular() ) { + $classes[] = 'hfeed'; + } + return $classes; } - // Adds a class of hfeed to non-singular pages. - if ( ! is_singular() ) { - $classes[] = 'hfeed'; - } - return $classes; } add_filter( 'body_class', 'understrap_body_classes' ); // Removes tag class from the body_class array to avoid Bootstrap markup styling issues. add_filter( 'body_class', 'adjust_body_class' ); -function adjust_body_class( $classes ) { - foreach ( $classes as $key => $value ) { - if ( $value == 'tag' ) unset( $classes[ $key ] ); - } +if ( ! function_exists ( 'adjust_body_class' ) ) { + function adjust_body_class( $classes ) { - return $classes; + foreach ( $classes as $key => $value ) { + if ( $value == 'tag' ) unset( $classes[ $key ] ); + } + return $classes; + + } } // Filter custom logo with correct classes add_filter('get_custom_logo','change_logo_class'); -function change_logo_class($html) -{ - $html = str_replace('class="custom-logo"', 'class="img-responsive"', $html); - $html = str_replace('class="custom-logo-link"', 'class="navbar-brand custom-logo-link"', $html); - return $html; -} + +if ( ! function_exists ( 'change_logo_class' ) ) { + function change_logo_class($html) + { + $html = str_replace('class="custom-logo"', 'class="img-responsive"', $html); + $html = str_replace('class="custom-logo-link"', 'class="navbar-brand custom-logo-link"', $html); + return $html; + } +} \ No newline at end of file diff --git a/inc/jetpack.php b/inc/jetpack.php index 0e1ba705..2586adec 100644 --- a/inc/jetpack.php +++ b/inc/jetpack.php @@ -12,28 +12,32 @@ * See: https://jetpack.com/support/infinite-scroll/ * See: https://jetpack.com/support/responsive-videos/ */ -function understrap_jetpack_setup() { - // Add theme support for Infinite Scroll. - add_theme_support( 'infinite-scroll', array( - 'container' => 'main', - 'render' => 'understrap_infinite_scroll_render', - 'footer' => 'wrapper-footer', - ) ); - // Add theme support for Responsive Videos. - add_theme_support( 'jetpack-responsive-videos' ); +if ( ! function_exists ( 'understrap_jetpack_setup' ) ) { + function understrap_jetpack_setup() { + // Add theme support for Infinite Scroll. + add_theme_support( 'infinite-scroll', array( + 'container' => 'main', + 'render' => 'understrap_infinite_scroll_render', + 'footer' => 'wrapper-footer', + ) ); + // Add theme support for Responsive Videos. + add_theme_support( 'jetpack-responsive-videos' ); + } } add_action( 'after_setup_theme', 'understrap_jetpack_setup' ); /** * Custom render function for Infinite Scroll. */ -function understrap_infinite_scroll_render() { - while ( have_posts() ) { - the_post(); - if ( is_search() ) : - get_template_part( 'loop-templates/content', 'search' ); - else : - get_template_part( 'loop-templates/content', get_post_format() ); - endif; +if ( ! function_exists ( 'understrap_infinite_scroll_render' ) ) { + function understrap_infinite_scroll_render() { + while ( have_posts() ) { + the_post(); + if ( is_search() ) : + get_template_part( 'loop-templates/content', 'search' ); + else : + get_template_part( 'loop-templates/content', get_post_format() ); + endif; + } } } diff --git a/inc/setup.php b/inc/setup.php index d4d8edc3..6c1c1d80 100644 --- a/inc/setup.php +++ b/inc/setup.php @@ -89,15 +89,18 @@ add_action( 'after_setup_theme', 'understrap_setup' ); } add_filter( 'excerpt_more', 'new_excerpt_more' );*/ /* Removes the ... from the excerpt read more link */ -function custom_excerpt_more( $more ) { - return ''; +if ( ! function_exists ( 'custom_excerpt_more' ) ) { + function custom_excerpt_more( $more ) { + return ''; + } } add_filter( 'excerpt_more', 'custom_excerpt_more' ); /* Adds a custom read more link to all excerpts, manually or automatically generated */ +if ( ! function_exists ( 'all_excerpts_get_more_link' ) ) { + function all_excerpts_get_more_link($post_excerpt) { -function all_excerpts_get_more_link($post_excerpt) { - - return $post_excerpt . ' [...]

' . __('Read More...', 'understrap') . '

'; + return $post_excerpt . ' [...]

' . __('Read More...', 'understrap') . '

'; + } } add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); diff --git a/inc/widgets.php b/inc/widgets.php index 1e2e1307..1088ceda 100644 --- a/inc/widgets.php +++ b/inc/widgets.php @@ -5,46 +5,48 @@ * * @package understrap */ -function understrap_widgets_init() { - register_sidebar( array( - 'name' => __( 'Sidebar', 'understrap' ), - 'id' => 'sidebar-1', - 'description' => 'Sidebar widget area', - 'before_widget' => '', - 'before_title' => '

', - 'after_title' => '

', - ) ); - - register_sidebar( array( - 'name' => __( 'Hero Slider', 'understrap' ), - 'id' => 'hero', - 'description' => 'Hero slider area. Place two or more widgets here and they will slide!', - 'before_widget' => '
', - 'after_widget' => '
', - 'before_title' => '', - 'after_title' => '', - ) ); - - register_sidebar( array( - 'name' => __( 'Hero Static', 'understrap' ), - 'id' => 'statichero', - 'description' => 'Static Hero widget. no slider functionallity', - 'before_widget' => '', - 'after_widget' => '', - 'before_title' => '', - 'after_title' => '', - ) ); +if ( ! function_exists ( 'understrap_widgets_init' ) ) { + function understrap_widgets_init() { + register_sidebar( array( + 'name' => __( 'Sidebar', 'understrap' ), + 'id' => 'sidebar-1', + 'description' => 'Sidebar widget area', + 'before_widget' => '', + 'before_title' => '

', + 'after_title' => '

', + ) ); register_sidebar( array( - 'name' => __( 'Footer Full', 'understrap' ), - 'id' => 'footerfull', - 'description' => 'Widget area below main content and above footer', - 'before_widget' => '', - 'after_widget' => '', - 'before_title' => '', - 'after_title' => '', - ) ); + 'name' => __( 'Hero Slider', 'understrap' ), + 'id' => 'hero', + 'description' => 'Hero slider area. Place two or more widgets here and they will slide!', + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '', + 'after_title' => '', + ) ); + register_sidebar( array( + 'name' => __( 'Hero Static', 'understrap' ), + 'id' => 'statichero', + 'description' => 'Static Hero widget. no slider functionallity', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Footer Full', 'understrap' ), + 'id' => 'footerfull', + 'description' => 'Widget area below main content and above footer', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + } } add_action( 'widgets_init', 'understrap_widgets_init' ); \ No newline at end of file diff --git a/inc/woocommerce.php b/inc/woocommerce.php index c789bbae..51ab159d 100644 --- a/inc/woocommerce.php +++ b/inc/woocommerce.php @@ -7,6 +7,8 @@ */ add_action( 'after_setup_theme', 'woocommerce_support' ); -function woocommerce_support() { - add_theme_support( 'woocommerce' ); +if ( ! function_exists ( 'woocommerce_support' ) ) { + function woocommerce_support() { + add_theme_support( 'woocommerce' ); + } } \ No newline at end of file diff --git a/inc/wpcom.php b/inc/wpcom.php index 8400caae..82abdf3a 100644 --- a/inc/wpcom.php +++ b/inc/wpcom.php @@ -12,18 +12,20 @@ * * @global array $themecolors */ -function understrap_wpcom_setup() { - global $themecolors; +if ( ! function_exists ( 'understrap_wpcom_setup' ) ) { + function understrap_wpcom_setup() { + global $themecolors; - // Set theme colors for third party services. - if ( ! isset( $themecolors ) ) { - $themecolors = array( - 'bg' => '', - 'border' => '', - 'text' => '', - 'link' => '', - 'url' => '', - ); + // Set theme colors for third party services. + if ( ! isset( $themecolors ) ) { + $themecolors = array( + 'bg' => '', + 'border' => '', + 'text' => '', + 'link' => '', + 'url' => '', + ); + } } } add_action( 'after_setup_theme', 'understrap_wpcom_setup' );