Merge pull request #619 from alex-wright-net/master-pluggable-functions

Apply pluggable function wrappers - Thx @axlright and the rest of you! I merge this and we should test it all together.
This commit is contained in:
Holger 2018-04-03 13:26:05 +02:00 committed by GitHub
commit 664fa834c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 375 additions and 325 deletions

View File

@ -5,6 +5,9 @@
* @package understrap * @package understrap
*/ */
add_action( 'after_setup_theme', 'understrap_custom_header_setup' );
if ( ! function_exists ( 'understrap_custom_header_setup' ) ) {
function understrap_custom_header_setup() { function understrap_custom_header_setup() {
/** /**
@ -39,4 +42,4 @@ function understrap_custom_header_setup() {
), ),
) ); ) );
} }
add_action( 'after_setup_theme', 'understrap_custom_header_setup' ); }

View File

@ -8,22 +8,30 @@
/** /**
* Registers an editor stylesheet for the theme. * Registers an editor stylesheet for the theme.
*/ */
add_action( 'admin_init', 'understrap_wpdocs_theme_add_editor_styles' );
if ( ! function_exists ( 'understrap_wpdocs_theme_add_editor_styles' ) ) {
function understrap_wpdocs_theme_add_editor_styles() { function understrap_wpdocs_theme_add_editor_styles() {
add_editor_style( 'css/custom-editor-style.min.css' ); add_editor_style( 'css/custom-editor-style.min.css' );
} }
add_action( 'admin_init', 'understrap_wpdocs_theme_add_editor_styles' ); }
// Add TinyMCE style formats. // Add TinyMCE style formats.
add_filter( 'mce_buttons_2', 'understrap_tiny_mce_style_formats' ); add_filter( 'mce_buttons_2', 'understrap_tiny_mce_style_formats' );
if ( ! function_exists ( 'understrap_tiny_mce_style_formats' ) ) {
function understrap_tiny_mce_style_formats( $styles ) { function understrap_tiny_mce_style_formats( $styles ) {
array_unshift( $styles, 'styleselect' ); array_unshift( $styles, 'styleselect' );
return $styles; return $styles;
} }
}
add_filter( 'tiny_mce_before_init', 'understrap_tiny_mce_before_init' ); add_filter( 'tiny_mce_before_init', 'understrap_tiny_mce_before_init' );
if ( ! function_exists ( 'understrap_tiny_mce_before_init' ) ) {
function understrap_tiny_mce_before_init( $settings ) { function understrap_tiny_mce_before_init( $settings ) {
$style_formats = array( $style_formats = array(
@ -63,3 +71,4 @@ function understrap_tiny_mce_before_init( $settings ) {
$settings['style_formats'] = json_encode( $style_formats ); $settings['style_formats'] = json_encode( $style_formats );
return $settings; return $settings;
} }
}

View File

@ -7,6 +7,8 @@
* @package understrap * @package understrap
*/ */
add_filter( 'body_class', 'understrap_body_classes' );
if ( ! function_exists( 'understrap_body_classes' ) ) { if ( ! function_exists( 'understrap_body_classes' ) ) {
/** /**
* Adds custom classes to the array of body classes. * Adds custom classes to the array of body classes.
@ -28,7 +30,6 @@ if ( ! function_exists( 'understrap_body_classes' ) ) {
return $classes; return $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', 'understrap_adjust_body_class' ); add_filter( 'body_class', 'understrap_adjust_body_class' );
@ -78,8 +79,8 @@ if ( ! function_exists( 'understrap_change_logo_class' ) ) {
/** /**
* Display navigation to next/previous post when applicable. * Display navigation to next/previous post when applicable.
*/ */
if ( ! function_exists( 'understrap_post_nav' ) ) :
if ( ! function_exists ( 'understrap_post_nav' ) ) {
function understrap_post_nav() { function understrap_post_nav() {
// Don't print empty markup if there's nowhere to navigate. // Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
@ -106,4 +107,4 @@ if ( ! function_exists( 'understrap_post_nav' ) ) :
<?php <?php
} }
endif; }

View File

@ -13,6 +13,10 @@
* See: https://jetpack.me/support/infinite-scroll/ * See: https://jetpack.me/support/infinite-scroll/
* See: https://jetpack.me/support/responsive-videos/ * See: https://jetpack.me/support/responsive-videos/
*/ */
add_action( 'after_setup_theme', 'understrap_components_jetpack_setup' );
if ( ! function_exists ( 'understrap_components_jetpack_setup' ) ) {
function understrap_components_jetpack_setup() { function understrap_components_jetpack_setup() {
// Add theme support for Infinite Scroll. // Add theme support for Infinite Scroll.
add_theme_support( 'infinite-scroll', array( add_theme_support( 'infinite-scroll', array(
@ -28,11 +32,14 @@ function understrap_components_jetpack_setup() {
add_theme_support( 'jetpack-social-menu' ); add_theme_support( 'jetpack-social-menu' );
} }
add_action( 'after_setup_theme', 'understrap_components_jetpack_setup' ); }
/** /**
* Custom render function for Infinite Scroll. * Custom render function for Infinite Scroll.
*/ */
if ( ! function_exists ( 'understrap_components_infinite_scroll_render' ) ) {
function understrap_components_infinite_scroll_render() { function understrap_components_infinite_scroll_render() {
while ( have_posts() ) { while ( have_posts() ) {
the_post(); the_post();
@ -43,7 +50,9 @@ function understrap_components_infinite_scroll_render() {
endif; endif;
} }
} }
}
if ( ! function_exists ( 'understrap_components_social_menu' ) ) {
function understrap_components_social_menu() { function understrap_components_social_menu() {
if ( ! function_exists( 'jetpack_social_menu' ) ) { if ( ! function_exists( 'jetpack_social_menu' ) ) {
return; return;
@ -51,3 +60,4 @@ function understrap_components_social_menu() {
jetpack_social_menu(); jetpack_social_menu();
} }
} }
}

View File

@ -5,7 +5,7 @@
* @package understrap * @package understrap
*/ */
if ( ! function_exists( 'understrap_pagination' ) ) : if ( ! function_exists ( 'understrap_pagination' ) ) {
function understrap_pagination($args = [], $class = 'pagination') { function understrap_pagination($args = [], $class = 'pagination') {
if ($GLOBALS['wp_query']->max_num_pages <= 1) return; if ($GLOBALS['wp_query']->max_num_pages <= 1) return;
@ -38,7 +38,7 @@
<?php <?php
$i = 1; $i = 1;
foreach ( $links as $link ) { ?> foreach ( $links as $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo active; }; ?>"> <li class="page-item <?php if ($i == $args['current']) { echo 'active'; }; ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?> <?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li> </li>
@ -54,5 +54,4 @@
</nav> </nav>
<?php <?php
} }
endif; }
?>

View File

@ -11,7 +11,9 @@ if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */ $content_width = 640; /* pixels */
} }
if ( ! function_exists( 'understrap_setup' ) ) : add_action( 'after_setup_theme', 'understrap_setup' );
if ( ! function_exists ( 'understrap_setup' ) ) {
/** /**
* Sets up theme defaults and registers support for various WordPress features. * Sets up theme defaults and registers support for various WordPress features.
* *
@ -91,8 +93,10 @@ if ( ! function_exists( 'understrap_setup' ) ) :
understrap_setup_theme_default_settings(); understrap_setup_theme_default_settings();
} }
endif; // understrap_setup. }
add_action( 'after_setup_theme', 'understrap_setup' );
add_filter( 'excerpt_more', 'understrap_custom_excerpt_more' );
if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) { if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) {
/** /**
@ -106,7 +110,8 @@ if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) {
return ''; return '';
} }
} }
add_filter( 'excerpt_more', 'understrap_custom_excerpt_more' );
add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' );
if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) { if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) {
/** /**
@ -122,4 +127,3 @@ if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) {
'understrap' ) . '</a></p>'; 'understrap' ) . '</a></p>';
} }
} }
add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' );

View File

@ -7,10 +7,11 @@
* @package understrap * @package understrap
*/ */
if ( ! function_exists( 'understrap_posted_on' ) ) :
/** /**
* Prints HTML with meta information for the current post-date/time and author. * Prints HTML with meta information for the current post-date/time and author.
*/ */
if ( ! function_exists ( 'understrap_posted_on' ) ) {
function understrap_posted_on() { function understrap_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
@ -32,12 +33,13 @@ function understrap_posted_on() {
); );
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK. echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
} }
endif; }
if ( ! function_exists( 'understrap_entry_footer' ) ) :
/** /**
* Prints HTML with meta information for the categories, tags and comments. * Prints HTML with meta information for the categories, tags and comments.
*/ */
if ( ! function_exists ( 'understrap_entry_footer' ) ) {
function understrap_entry_footer() { function understrap_entry_footer() {
// Hide category and tag text for pages. // Hide category and tag text for pages.
if ( 'post' === get_post_type() ) { if ( 'post' === get_post_type() ) {
@ -67,13 +69,15 @@ function understrap_entry_footer() {
'</span>' '</span>'
); );
} }
endif; }
/** /**
* Returns true if a blog has more than 1 category. * Returns true if a blog has more than 1 category.
* *
* @return bool * @return bool
*/ */
if ( ! function_exists ( 'understrap_categorized_blog' ) ) {
function understrap_categorized_blog() { function understrap_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) { if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) {
// Create an array of all the categories that are attached to posts. // Create an array of all the categories that are attached to posts.
@ -95,10 +99,16 @@ function understrap_categorized_blog() {
return false; return false;
} }
} }
}
/** /**
* Flush out the transients used in understrap_categorized_blog. * Flush out the transients used in understrap_categorized_blog.
*/ */
add_action( 'edit_category', 'understrap_category_transient_flusher' );
add_action( 'save_post', 'understrap_category_transient_flusher' );
if ( ! function_exists ( 'understrap_category_transient_flusher' ) ) {
function understrap_category_transient_flusher() { function understrap_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return; return;
@ -106,6 +116,4 @@ function understrap_category_transient_flusher() {
// Like, beat it. Dig? // Like, beat it. Dig?
delete_transient( 'understrap_categories' ); delete_transient( 'understrap_categories' );
} }
add_action( 'edit_category', 'understrap_category_transient_flusher' ); }
add_action( 'save_post', 'understrap_category_transient_flusher' );

View File

@ -6,7 +6,7 @@
* *
*/ */
if ( ! function_exists( 'understrap_setup_theme_default_settings' ) ) : if ( ! function_exists ( 'understrap_setup_theme_default_settings' ) ) {
function understrap_setup_theme_default_settings() { function understrap_setup_theme_default_settings() {
// check if settings are set, if not set defaults. // check if settings are set, if not set defaults.
@ -29,4 +29,4 @@ if ( ! function_exists( 'understrap_setup_theme_default_settings' ) ) :
set_theme_mod( 'understrap_container_type', 'container' ); set_theme_mod( 'understrap_container_type', 'container' );
} }
} }
endif; }

View File

@ -44,6 +44,8 @@ if ( ! function_exists( 'understrap_slbd_count_widgets' ) ) {
} }
} }
add_action( 'widgets_init', 'understrap_widgets_init' );
if ( ! function_exists( 'understrap_widgets_init' ) ) { if ( ! function_exists( 'understrap_widgets_init' ) ) {
/** /**
* Initializes themes widgets. * Initializes themes widgets.
@ -101,5 +103,3 @@ if ( ! function_exists( 'understrap_widgets_init' ) ) {
} }
} // endif function_exists( 'understrap_widgets_init' ). } // endif function_exists( 'understrap_widgets_init' ).
add_action( 'widgets_init', 'understrap_widgets_init' );

View File

@ -4,6 +4,8 @@
* *
* @package understrap * @package understrap
*/ */
add_action( 'after_setup_theme', 'understrap_woocommerce_support' ); add_action( 'after_setup_theme', 'understrap_woocommerce_support' );
if ( ! function_exists( 'understrap_woocommerce_support' ) ) { if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
/** /**
@ -22,6 +24,7 @@ if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
} }
} }
/** /**
* First unhook the WooCommerce wrappers * First unhook the WooCommerce wrappers
*/ */
@ -54,6 +57,7 @@ function understrap_woocommerce_wrapper_end() {
} }
} }
/** /**
* Filter hook function monkey patching form classes * Filter hook function monkey patching form classes
* Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826 * Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
@ -64,6 +68,7 @@ function understrap_woocommerce_wrapper_end() {
* *
* @return mixed * @return mixed
*/ */
if ( ! function_exists ( 'understrap_wc_form_field_args' ) ) {
function understrap_wc_form_field_args( $args, $key, $value = null ) { function understrap_wc_form_field_args( $args, $key, $value = null ) {
// Start field type switch case. // Start field type switch case.
switch ( $args['type'] ) { switch ( $args['type'] ) {
@ -131,13 +136,17 @@ function understrap_wc_form_field_args( $args, $key, $value = null ) {
} // end switch ($args). } // end switch ($args).
return $args; return $args;
} }
}
/** /**
* Change loop add-to-cart button class to Bootstrap * Change loop add-to-cart button class to Bootstrap
*/ */
add_filter( 'woocommerce_loop_add_to_cart_args', 'understrap_woocommerce_add_to_cart_args', 10, 2 ); add_filter( 'woocommerce_loop_add_to_cart_args', 'understrap_woocommerce_add_to_cart_args', 10, 2 );
if ( ! function_exists ( 'understrap_woocommerce_add_to_cart_args' ) ) {
function understrap_woocommerce_add_to_cart_args( $args, $product ) { function understrap_woocommerce_add_to_cart_args( $args, $product ) {
$args['class'] = str_replace('button','btn btn-outline-primary', 'button'); $args['class'] = str_replace('button','btn btn-outline-primary', 'button');
return $args; return $args;
} }
}

View File

@ -12,6 +12,9 @@
* *
* @global array $themecolors * @global array $themecolors
*/ */
add_action( 'after_setup_theme', 'understrap_wpcom_setup' );
if ( ! function_exists ( 'understrap_wpcom_setup' ) ) {
function understrap_wpcom_setup() { function understrap_wpcom_setup() {
global $themecolors; global $themecolors;
@ -29,12 +32,16 @@ function understrap_wpcom_setup() {
/* Add WP.com print styles */ /* Add WP.com print styles */
add_theme_support( 'print-styles' ); add_theme_support( 'print-styles' );
} }
add_action( 'after_setup_theme', 'understrap_wpcom_setup' ); }
/* /*
* WordPress.com-specific styles * WordPress.com-specific styles
*/ */
add_action( 'wp_enqueue_scripts', 'understrap_wpcom_styles' );
if ( ! function_exists ( 'understrap_wpcom_styles' ) ) {
function understrap_wpcom_styles() { function understrap_wpcom_styles() {
wp_enqueue_style( 'understrap-wpcom', get_template_directory_uri() . '/inc/style-wpcom.css', '20160411' ); wp_enqueue_style( 'understrap-wpcom', get_template_directory_uri() . '/inc/style-wpcom.css', '20160411' );
} }
add_action( 'wp_enqueue_scripts', 'understrap_wpcom_styles' ); }