Making all function pluggable

This commit is contained in:
Holger Könemann 2016-11-01 20:36:43 +01:00
parent b8a5f0cc5a
commit ad03eb383a
8 changed files with 197 additions and 165 deletions

View File

@ -10,60 +10,64 @@
* *
* @param WP_Customize_Manager $wp_customize Theme Customizer object. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/ */
function understrap_customize_register( $wp_customize ) { if ( ! function_exists ( 'understrap_customize_register' ) ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; function understrap_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
}
} }
add_action( 'customize_register', 'understrap_customize_register' ); 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( $wp_customize->add_section( 'understrap_theme_slider_options', array(
'title' => __( 'Slider Settings', 'understrap' ) 'title' => __( 'Slider Settings', 'understrap' )
) ); ) );
$wp_customize->add_setting( 'understrap_theme_slider_count_setting', array( $wp_customize->add_setting( 'understrap_theme_slider_count_setting', array(
'default' => '1', 'default' => '1',
'sanitize_callback' => 'absint' 'sanitize_callback' => 'absint'
) ); ) );
$wp_customize->add_control( 'understrap_theme_slider_count', array( $wp_customize->add_control( 'understrap_theme_slider_count', array(
'label' => __( 'Number of slides displaying at once', 'understrap' ), 'label' => __( 'Number of slides displaying at once', 'understrap' ),
'section' => 'understrap_theme_slider_options', 'section' => 'understrap_theme_slider_options',
'type' => 'text', 'type' => 'text',
'settings' => 'understrap_theme_slider_count_setting' 'settings' => 'understrap_theme_slider_count_setting'
) ); ) );
$wp_customize->add_setting( 'understrap_theme_slider_time_setting', array( $wp_customize->add_setting( 'understrap_theme_slider_time_setting', array(
'default' => '5000', 'default' => '5000',
'sanitize_callback' => 'absint' 'sanitize_callback' => 'absint'
) ); ) );
$wp_customize->add_control( 'understrap_theme_slider_time', array( $wp_customize->add_control( 'understrap_theme_slider_time', array(
'label' => __( 'Slider Time (in ms)', 'understrap' ), 'label' => __( 'Slider Time (in ms)', 'understrap' ),
'section' => 'understrap_theme_slider_options', 'section' => 'understrap_theme_slider_options',
'type' => 'text', 'type' => 'text',
'settings' => 'understrap_theme_slider_time_setting' 'settings' => 'understrap_theme_slider_time_setting'
) ); ) );
$wp_customize->add_setting( 'understrap_theme_slider_loop_setting', array( $wp_customize->add_setting( 'understrap_theme_slider_loop_setting', array(
'default' => 'true', 'default' => 'true',
'sanitize_callback' => 'esc_textarea' 'sanitize_callback' => 'esc_textarea'
) ); ) );
$wp_customize->add_control( 'understrap_theme_loop', array( $wp_customize->add_control( 'understrap_theme_loop', array(
'label' => __( 'Loop Slider Content', 'understrap' ), 'label' => __( 'Loop Slider Content', 'understrap' ),
'section' => 'understrap_theme_slider_options', 'section' => 'understrap_theme_slider_options',
'type' => 'radio', 'type' => 'radio',
'choices' => array( 'choices' => array(
'true' => 'yes', 'true' => 'yes',
'false' => 'no', 'false' => 'no',
), ),
'settings' => 'understrap_theme_slider_loop_setting' 'settings' => 'understrap_theme_slider_loop_setting'
) ); ) );
}
} }
add_action( 'customize_register', 'understrap_theme_customize_register' ); 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. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
*/ */
function understrap_customize_preview_js() { if ( ! function_exists ( 'understrap_customize_preview_js' ) ) {
wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); 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' ); add_action( 'customize_preview_init', 'understrap_customize_preview_js' );

View File

@ -5,29 +5,31 @@
* @package understrap * @package understrap
*/ */
function understrap_scripts() { if ( ! function_exists ( 'understrap_scripts' ) ) {
wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), '0.4.9' ); function understrap_scripts() {
wp_enqueue_script( 'jquery' ); wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), '0.4.9' );
wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), '0.4.9', true ); 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' ) ) { if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' ); wp_enqueue_script( 'comment-reply' );
} }
// menu - vertical page association // menu - vertical page association
if ( is_page_template( 'page-templates/vertical-one-page.php' ) || is_home() || is_single() ) { 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 ); 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' ) ) ); $page_for_posts = strtolower( get_the_title( get_option( 'page_for_posts' ) ) );
$home_url = home_url(); $home_url = home_url();
$is_single = is_single(); $is_single = is_single();
$vars = array( $vars = array(
'pageForPosts' => $page_for_posts, 'pageForPosts' => $page_for_posts,
'homeUrl' => $home_url, 'homeUrl' => $home_url,
'isSingle' => $is_single 'isSingle' => $is_single
); );
wp_localize_script( 'vertical-one-page', 'vars', $vars ); 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' ); add_action( 'wp_enqueue_scripts', 'understrap_scripts' );
@ -39,15 +41,17 @@ add_action( 'wp_enqueue_scripts', 'understrap_scripts' );
if ( is_active_sidebar( 'hero' ) ): if ( is_active_sidebar( 'hero' ) ):
add_action( "wp_enqueue_scripts", "understrap_slider" ); add_action( "wp_enqueue_scripts", "understrap_slider" );
function understrap_slider() { if ( ! function_exists ( 'understrap_slider' ) ) {
if ( is_front_page() ) { function understrap_slider() {
$data = array( if ( is_front_page() ) {
"timeout" => intval( get_theme_mod( 'understrap_theme_slider_time_setting', 5000 ) ), $data = array(
"items" => intval( get_theme_mod( 'understrap_theme_slider_count_setting', 1 ) ) "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_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_localize_script( "understrap-slider-script", "understrap_slider_variables", $data );
}
} }
} }
endif; endif;

View File

@ -12,37 +12,46 @@
* @param array $classes Classes for the body element. * @param array $classes Classes for the body element.
* @return array * @return array
*/ */
function understrap_body_classes( $classes ) {
// Adds a class of group-blog to blogs with more than 1 published author. if ( ! function_exists ( 'understrap_body_classes' ) ) {
if ( is_multi_author() ) { function understrap_body_classes( $classes ) {
$classes[] = 'group-blog'; // 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' ); add_filter( 'body_class', 'understrap_body_classes' );
// Removes tag class from the body_class array to avoid Bootstrap markup styling issues. // Removes tag class from the body_class array to avoid Bootstrap markup styling issues.
add_filter( 'body_class', 'adjust_body_class' ); add_filter( 'body_class', 'adjust_body_class' );
function adjust_body_class( $classes ) {
foreach ( $classes as $key => $value ) { if ( ! function_exists ( 'adjust_body_class' ) ) {
if ( $value == 'tag' ) unset( $classes[ $key ] ); 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 // Filter custom logo with correct classes
add_filter('get_custom_logo','change_logo_class'); add_filter('get_custom_logo','change_logo_class');
function change_logo_class($html)
{ if ( ! function_exists ( 'change_logo_class' ) ) {
$html = str_replace('class="custom-logo"', 'class="img-responsive"', $html); function change_logo_class($html)
$html = str_replace('class="custom-logo-link"', 'class="navbar-brand custom-logo-link"', $html); {
return $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;
}
} }

View File

@ -12,28 +12,32 @@
* See: https://jetpack.com/support/infinite-scroll/ * See: https://jetpack.com/support/infinite-scroll/
* See: https://jetpack.com/support/responsive-videos/ * See: https://jetpack.com/support/responsive-videos/
*/ */
function understrap_jetpack_setup() { if ( ! function_exists ( 'understrap_jetpack_setup' ) ) {
// Add theme support for Infinite Scroll. function understrap_jetpack_setup() {
add_theme_support( 'infinite-scroll', array( // Add theme support for Infinite Scroll.
'container' => 'main', add_theme_support( 'infinite-scroll', array(
'render' => 'understrap_infinite_scroll_render', 'container' => 'main',
'footer' => 'wrapper-footer', 'render' => 'understrap_infinite_scroll_render',
) ); 'footer' => 'wrapper-footer',
// Add theme support for Responsive Videos. ) );
add_theme_support( 'jetpack-responsive-videos' ); // Add theme support for Responsive Videos.
add_theme_support( 'jetpack-responsive-videos' );
}
} }
add_action( 'after_setup_theme', 'understrap_jetpack_setup' ); add_action( 'after_setup_theme', 'understrap_jetpack_setup' );
/** /**
* Custom render function for Infinite Scroll. * Custom render function for Infinite Scroll.
*/ */
function understrap_infinite_scroll_render() { if ( ! function_exists ( 'understrap_infinite_scroll_render' ) ) {
while ( have_posts() ) { function understrap_infinite_scroll_render() {
the_post(); while ( have_posts() ) {
if ( is_search() ) : the_post();
get_template_part( 'loop-templates/content', 'search' ); if ( is_search() ) :
else : get_template_part( 'loop-templates/content', 'search' );
get_template_part( 'loop-templates/content', get_post_format() ); else :
endif; get_template_part( 'loop-templates/content', get_post_format() );
endif;
}
} }
} }

View File

@ -89,15 +89,18 @@ add_action( 'after_setup_theme', 'understrap_setup' );
} }
add_filter( 'excerpt_more', 'new_excerpt_more' );*/ add_filter( 'excerpt_more', 'new_excerpt_more' );*/
/* Removes the ... from the excerpt read more link */ /* Removes the ... from the excerpt read more link */
function custom_excerpt_more( $more ) { if ( ! function_exists ( 'custom_excerpt_more' ) ) {
return ''; function custom_excerpt_more( $more ) {
return '';
}
} }
add_filter( 'excerpt_more', 'custom_excerpt_more' ); add_filter( 'excerpt_more', 'custom_excerpt_more' );
/* Adds a custom read more link to all excerpts, manually or automatically generated */ /* 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 . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More...', 'understrap') . '</a></p>';
}
return $post_excerpt . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More...', 'understrap') . '</a></p>';
} }
add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

View File

@ -5,46 +5,48 @@
* *
* @package understrap * @package understrap
*/ */
function understrap_widgets_init() { if ( ! function_exists ( 'understrap_widgets_init' ) ) {
register_sidebar( array( function understrap_widgets_init() {
'name' => __( 'Sidebar', 'understrap' ), register_sidebar( array(
'id' => 'sidebar-1', 'name' => __( 'Sidebar', 'understrap' ),
'description' => 'Sidebar widget area', 'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'description' => 'Sidebar widget area',
'after_widget' => '</aside>', 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'before_title' => '<h3 class="widget-title">', 'after_widget' => '</aside>',
'after_title' => '</h3>', 'before_title' => '<h3 class="widget-title">',
) ); 'after_title' => '</h3>',
) );
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' => '<div class="item">',
'after_widget' => '</div>',
'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( register_sidebar( array(
'name' => __( 'Footer Full', 'understrap' ), 'name' => __( 'Hero Slider', 'understrap' ),
'id' => 'footerfull', 'id' => 'hero',
'description' => 'Widget area below main content and above footer', 'description' => 'Hero slider area. Place two or more widgets here and they will slide!',
'before_widget' => '', 'before_widget' => '<div class="item">',
'after_widget' => '', 'after_widget' => '</div>',
'before_title' => '', 'before_title' => '',
'after_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' ); add_action( 'widgets_init', 'understrap_widgets_init' );

View File

@ -7,6 +7,8 @@
*/ */
add_action( 'after_setup_theme', 'woocommerce_support' ); add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() { if ( ! function_exists ( 'woocommerce_support' ) ) {
add_theme_support( 'woocommerce' ); function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
} }

View File

@ -12,18 +12,20 @@
* *
* @global array $themecolors * @global array $themecolors
*/ */
function understrap_wpcom_setup() { if ( ! function_exists ( 'understrap_wpcom_setup' ) ) {
global $themecolors; function understrap_wpcom_setup() {
global $themecolors;
// Set theme colors for third party services. // Set theme colors for third party services.
if ( ! isset( $themecolors ) ) { if ( ! isset( $themecolors ) ) {
$themecolors = array( $themecolors = array(
'bg' => '', 'bg' => '',
'border' => '', 'border' => '',
'text' => '', 'text' => '',
'link' => '', 'link' => '',
'url' => '', 'url' => '',
); );
}
} }
} }
add_action( 'after_setup_theme', 'understrap_wpcom_setup' ); add_action( 'after_setup_theme', 'understrap_wpcom_setup' );