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,14 +10,17 @@
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
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' );
if ( ! function_exists ( 'understrap_theme_customize_register' ) ) {
function understrap_theme_customize_register( $wp_customize ) {
$wp_customize->add_section( 'understrap_theme_slider_options', array(
@ -65,6 +68,7 @@ function understrap_theme_customize_register( $wp_customize ) {
) );
}
}
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.
*/
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' );

View File

@ -5,6 +5,7 @@
* @package understrap
*/
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' );
@ -29,6 +30,7 @@ function understrap_scripts() {
}
// menu - vertical page association end
}
}
add_action( 'wp_enqueue_scripts', 'understrap_scripts' );
@ -39,6 +41,7 @@ add_action( 'wp_enqueue_scripts', 'understrap_scripts' );
if ( is_active_sidebar( 'hero' ) ):
add_action( "wp_enqueue_scripts", "understrap_slider" );
if ( ! function_exists ( 'understrap_slider' ) ) {
function understrap_slider() {
if ( is_front_page() ) {
$data = array(
@ -50,5 +53,6 @@ if ( is_active_sidebar( 'hero' ) ):
wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data );
}
}
}
endif;

View File

@ -12,6 +12,8 @@
* @param array $classes Classes for the body element.
* @return array
*/
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() ) {
@ -23,11 +25,14 @@ function understrap_body_classes( $classes ) {
}
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' );
if ( ! function_exists ( 'adjust_body_class' ) ) {
function adjust_body_class( $classes ) {
foreach ( $classes as $key => $value ) {
@ -37,12 +42,16 @@ function adjust_body_class( $classes ) {
return $classes;
}
}
// Filter custom logo with correct classes
add_filter('get_custom_logo','change_logo_class');
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;
}
}

View File

@ -12,6 +12,7 @@
* See: https://jetpack.com/support/infinite-scroll/
* See: https://jetpack.com/support/responsive-videos/
*/
if ( ! function_exists ( 'understrap_jetpack_setup' ) ) {
function understrap_jetpack_setup() {
// Add theme support for Infinite Scroll.
add_theme_support( 'infinite-scroll', array(
@ -22,10 +23,12 @@ function understrap_jetpack_setup() {
// 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.
*/
if ( ! function_exists ( 'understrap_infinite_scroll_render' ) ) {
function understrap_infinite_scroll_render() {
while ( have_posts() ) {
the_post();
@ -36,4 +39,5 @@ function understrap_infinite_scroll_render() {
endif;
}
}
}

View File

@ -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 */
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) {
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');

View File

@ -5,6 +5,7 @@
*
* @package understrap
*/
if ( ! function_exists ( 'understrap_widgets_init' ) ) {
function understrap_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'understrap' ),
@ -47,4 +48,5 @@ function understrap_widgets_init() {
) );
}
}
add_action( 'widgets_init', 'understrap_widgets_init' );

View File

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

View File

@ -12,6 +12,7 @@
*
* @global array $themecolors
*/
if ( ! function_exists ( 'understrap_wpcom_setup' ) ) {
function understrap_wpcom_setup() {
global $themecolors;
@ -26,4 +27,5 @@ function understrap_wpcom_setup() {
);
}
}
}
add_action( 'after_setup_theme', 'understrap_wpcom_setup' );