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,38 +5,41 @@
* @package understrap * @package understrap
*/ */
function understrap_custom_header_setup() {
/**
* Filter UnderStrap custom-header support arguments.
*
* @since UnderStrap 0.5.2
*
* @param array $args {
* An array of custom-header support arguments.
*
* @type string $default-image Default image of the header.
* @type string $default_text_color Default color of the header text.
* @type int $width Width in pixels of the custom header image. Default 954.
* @type int $height Height in pixels of the custom header image. Default 1300.
* @type string $wp-head-callback Callback function used to styles the header image and text
* displayed on the blog.
* @type string $flex-height Flex support for height of header.
* }
*/
add_theme_support( 'custom-header', apply_filters( 'understrap_custom_header_args', array(
'default-image' => get_parent_theme_file_uri( '/img/header.jpg' ),
'width' => 2000,
'height' => 1200,
'flex-height' => true,
) ) );
register_default_headers( array(
'default-image' => array(
'url' => '%s/img/header.jpg',
'thumbnail_url' => '%s/img/header.jpg',
'description' => __( 'Default Header Image', 'understrap' ),
),
) );
}
add_action( 'after_setup_theme', 'understrap_custom_header_setup' ); add_action( 'after_setup_theme', 'understrap_custom_header_setup' );
if ( ! function_exists ( 'understrap_custom_header_setup' ) ) {
function understrap_custom_header_setup() {
/**
* Filter UnderStrap custom-header support arguments.
*
* @since UnderStrap 0.5.2
*
* @param array $args {
* An array of custom-header support arguments.
*
* @type string $default-image Default image of the header.
* @type string $default_text_color Default color of the header text.
* @type int $width Width in pixels of the custom header image. Default 954.
* @type int $height Height in pixels of the custom header image. Default 1300.
* @type string $wp-head-callback Callback function used to styles the header image and text
* displayed on the blog.
* @type string $flex-height Flex support for height of header.
* }
*/
add_theme_support( 'custom-header', apply_filters( 'understrap_custom_header_args', array(
'default-image' => get_parent_theme_file_uri( '/img/header.jpg' ),
'width' => 2000,
'height' => 1200,
'flex-height' => true,
) ) );
register_default_headers( array(
'default-image' => array(
'url' => '%s/img/header.jpg',
'thumbnail_url' => '%s/img/header.jpg',
'description' => __( 'Default Header Image', 'understrap' ),
),
) );
}
}

View File

@ -8,58 +8,67 @@
/** /**
* Registers an editor stylesheet for the theme. * Registers an editor stylesheet for the theme.
*/ */
function understrap_wpdocs_theme_add_editor_styles() {
add_editor_style( 'css/custom-editor-style.min.css' );
}
add_action( 'admin_init', 'understrap_wpdocs_theme_add_editor_styles' ); 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() {
add_editor_style( 'css/custom-editor-style.min.css' );
}
}
// 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' );
function understrap_tiny_mce_style_formats( $styles ) { if ( ! function_exists ( 'understrap_tiny_mce_style_formats' ) ) {
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' );
function understrap_tiny_mce_before_init( $settings ) { if ( ! function_exists ( 'understrap_tiny_mce_before_init' ) ) {
function understrap_tiny_mce_before_init( $settings ) {
$style_formats = array( $style_formats = array(
array( array(
'title' => 'Lead Paragraph', 'title' => 'Lead Paragraph',
'selector' => 'p', 'selector' => 'p',
'classes' => 'lead', 'classes' => 'lead',
'wrapper' => true 'wrapper' => true
), ),
array( array(
'title' => 'Small', 'title' => 'Small',
'inline' => 'small' 'inline' => 'small'
), ),
array( array(
'title' => 'Blockquote', 'title' => 'Blockquote',
'block' => 'blockquote', 'block' => 'blockquote',
'classes' => 'blockquote', 'classes' => 'blockquote',
'wrapper' => true 'wrapper' => true
), ),
array( array(
'title' => 'Blockquote Footer', 'title' => 'Blockquote Footer',
'block' => 'footer', 'block' => 'footer',
'classes' => 'blockquote-footer', 'classes' => 'blockquote-footer',
'wrapper' => true 'wrapper' => true
), ),
array( array(
'title' => 'Cite', 'title' => 'Cite',
'inline' => 'cite' 'inline' => 'cite'
) )
); );
if ( isset( $settings['style_formats'] ) ) { if ( isset( $settings['style_formats'] ) ) {
$orig_style_formats = json_decode($settings['style_formats'],true); $orig_style_formats = json_decode($settings['style_formats'],true);
$style_formats = array_merge($orig_style_formats,$style_formats); $style_formats = array_merge($orig_style_formats,$style_formats);
} }
$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,41 +13,51 @@
* 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/
*/ */
function understrap_components_jetpack_setup() {
// Add theme support for Infinite Scroll.
add_theme_support( 'infinite-scroll', array(
'container' => 'main',
'render' => 'components_infinite_scroll_render',
'footer' => 'page',
) );
// Add theme support for Responsive Videos.
add_theme_support( 'jetpack-responsive-videos' );
// Add theme support for Social Menus
add_theme_support( 'jetpack-social-menu' );
}
add_action( 'after_setup_theme', 'understrap_components_jetpack_setup' ); add_action( 'after_setup_theme', 'understrap_components_jetpack_setup' );
if ( ! function_exists ( 'understrap_components_jetpack_setup' ) ) {
function understrap_components_jetpack_setup() {
// Add theme support for Infinite Scroll.
add_theme_support( 'infinite-scroll', array(
'container' => 'main',
'render' => 'components_infinite_scroll_render',
'footer' => 'page',
) );
// Add theme support for Responsive Videos.
add_theme_support( 'jetpack-responsive-videos' );
// Add theme support for Social Menus
add_theme_support( 'jetpack-social-menu' );
}
}
/** /**
* Custom render function for Infinite Scroll. * Custom render function for Infinite Scroll.
*/ */
function understrap_components_infinite_scroll_render() {
while ( have_posts() ) { if ( ! function_exists ( 'understrap_components_infinite_scroll_render' ) ) {
the_post(); function understrap_components_infinite_scroll_render() {
if ( is_search() ) : while ( have_posts() ) {
get_template_part( 'loop-templates/content', 'search' ); the_post();
else : if ( is_search() ) :
get_template_part( 'loop-templates/content', get_post_format() ); get_template_part( 'loop-templates/content', 'search' );
endif; else :
get_template_part( 'loop-templates/content', get_post_format() );
endif;
}
} }
} }
function understrap_components_social_menu() { if ( ! function_exists ( 'understrap_components_social_menu' ) ) {
if ( ! function_exists( 'jetpack_social_menu' ) ) { function understrap_components_social_menu() {
return; if ( ! function_exists( 'jetpack_social_menu' ) ) {
} else { return;
jetpack_social_menu(); } else {
jetpack_social_menu();
}
} }
} }

View File

@ -5,54 +5,53 @@
* @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;
$args = wp_parse_args( $args, [ $args = wp_parse_args( $args, [
'mid_size' => 2, 'mid_size' => 2,
'prev_next' => false, 'prev_next' => false,
'prev_text' => __('&laquo;', 'understrap'), 'prev_text' => __('&laquo;', 'understrap'),
'next_text' => __('&raquo;', 'understrap'), 'next_text' => __('&raquo;', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'), 'screen_reader_text' => __('Posts navigation', 'understrap'),
'type' => 'array', 'type' => 'array',
'current' => max( 1, get_query_var('paged') ), 'current' => max( 1, get_query_var('paged') ),
]); ]);
$links = paginate_links($args); $links = paginate_links($args);
$next_link = get_next_posts_page_link(); $next_link = get_next_posts_page_link();
$prev_link = get_previous_posts_page_link(); $prev_link = get_previous_posts_page_link();
?> ?>
<nav aria-label="<?php echo $args['screen_reader_text']; ?>"> <nav aria-label="<?php echo $args['screen_reader_text']; ?>">
<ul class="pagination"> <ul class="pagination">
<li class="page-item"> <li class="page-item">
<a class="page-link" href="<?php echo esc_attr($prev_link); ?>" aria-label="<?php echo __('Previous', 'understrap'); ?>"> <a class="page-link" href="<?php echo esc_attr($prev_link); ?>" aria-label="<?php echo __('Previous', 'understrap'); ?>">
<span aria-hidden="true"><?php echo esc_attr($args['prev_text']); ?></span> <span aria-hidden="true"><?php echo esc_attr($args['prev_text']); ?></span>
<span class="sr-only"><?php echo __('Previous', 'understrap'); ?></span> <span class="sr-only"><?php echo __('Previous', 'understrap'); ?></span>
</a> </a>
</li> </li>
<?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>
<?php $i++;} ?> <?php $i++;} ?>
<li class="page-item"> <li class="page-item">
<a class="page-link" href="<?php echo esc_attr($next_link); ?>" aria-label="<?php echo __('Next', 'understrap'); ?>"> <a class="page-link" href="<?php echo esc_attr($next_link); ?>" aria-label="<?php echo __('Next', 'understrap'); ?>">
<span aria-hidden="true"><?php echo esc_attr($args['next_text']); ?></span> <span aria-hidden="true"><?php echo esc_attr($args['next_text']); ?></span>
<span class="sr-only"><?php echo __('Next', 'understrap'); ?></span> <span class="sr-only"><?php echo __('Next', 'understrap'); ?></span>
</a> </a>
</li> </li>
</ul> </ul>
</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' ) ) {
/** /**
@ -121,5 +126,4 @@ if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) {
return $post_excerpt . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="' . esc_url( get_permalink( get_the_ID() )) . '">' . __( 'Read More...', return $post_excerpt . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="' . esc_url( get_permalink( get_the_ID() )) . '">' . __( 'Read More...',
'understrap' ) . '</a></p>'; 'understrap' ) . '</a></p>';
} }
} }
add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' );

View File

@ -7,105 +7,113 @@
* @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.
*/ */
function understrap_posted_on() { if ( ! function_exists ( 'understrap_posted_on' ) ) {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; function understrap_posted_on() {
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s"> (%4$s) </time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s"> (%4$s) </time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'understrap' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'understrap' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
} }
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'understrap' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'understrap' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
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.
*/ */
function understrap_entry_footer() { if ( ! function_exists ( 'understrap_entry_footer' ) ) {
// Hide category and tag text for pages. function understrap_entry_footer() {
if ( 'post' === get_post_type() ) { // Hide category and tag text for pages.
/* translators: used between list items, there is a space after the comma */ if ( 'post' === get_post_type() ) {
$categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) ); /* translators: used between list items, there is a space after the comma */
if ( $categories_list && understrap_categorized_blog() ) { $categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) );
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'understrap' ) . '</span>', $categories_list ); // WPCS: XSS OK. if ( $categories_list && understrap_categorized_blog() ) {
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'understrap' ) . '</span>', $categories_list ); // WPCS: XSS OK.
}
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'understrap' ) );
if ( $tags_list ) {
printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'understrap' ) . '</span>', $tags_list ); // WPCS: XSS OK.
}
} }
/* translators: used between list items, there is a space after the comma */ if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'understrap' ) ); echo '<span class="comments-link">';
if ( $tags_list ) { comments_popup_link( esc_html__( 'Leave a comment', 'understrap' ), esc_html__( '1 Comment', 'understrap' ), esc_html__( '% Comments', 'understrap' ) );
printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'understrap' ) . '</span>', $tags_list ); // WPCS: XSS OK. echo '</span>';
} }
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'understrap' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
),
'<span class="edit-link">',
'</span>'
);
} }
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( esc_html__( 'Leave a comment', 'understrap' ), esc_html__( '1 Comment', 'understrap' ), esc_html__( '% Comments', 'understrap' ) );
echo '</span>';
}
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'understrap' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
),
'<span class="edit-link">',
'</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
*/ */
function understrap_categorized_blog() { if ( ! function_exists ( 'understrap_categorized_blog' ) ) {
if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) { function understrap_categorized_blog() {
// Create an array of all the categories that are attached to posts. if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) {
$all_the_cool_cats = get_categories( array( // Create an array of all the categories that are attached to posts.
'fields' => 'ids', $all_the_cool_cats = get_categories( array(
'hide_empty' => 1, 'fields' => 'ids',
// We only need to know if there is more than one category. 'hide_empty' => 1,
'number' => 2, // We only need to know if there is more than one category.
) ); 'number' => 2,
// Count the number of categories that are attached to the posts. ) );
$all_the_cool_cats = count( $all_the_cool_cats ); // Count the number of categories that are attached to the posts.
set_transient( 'understrap_categories', $all_the_cool_cats ); $all_the_cool_cats = count( $all_the_cool_cats );
} set_transient( 'understrap_categories', $all_the_cool_cats );
if ( $all_the_cool_cats > 1 ) { }
// This blog has more than 1 category so components_categorized_blog should return true. if ( $all_the_cool_cats > 1 ) {
return true; // This blog has more than 1 category so components_categorized_blog should return true.
} else { return true;
// This blog has only 1 category so components_categorized_blog should return false. } else {
return false; // This blog has only 1 category so components_categorized_blog should return false.
return false;
}
} }
} }
/** /**
* Flush out the transients used in understrap_categorized_blog. * Flush out the transients used in understrap_categorized_blog.
*/ */
function understrap_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Like, beat it. Dig?
delete_transient( 'understrap_categories' );
}
add_action( 'edit_category', 'understrap_category_transient_flusher' ); add_action( 'edit_category', 'understrap_category_transient_flusher' );
add_action( 'save_post', 'understrap_category_transient_flusher' ); add_action( 'save_post', 'understrap_category_transient_flusher' );
if ( ! function_exists ( 'understrap_category_transient_flusher' ) ) {
function understrap_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Like, beat it. Dig?
delete_transient( 'understrap_categories' );
}
}

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.
@ -100,6 +102,4 @@ 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,72 +68,74 @@ function understrap_woocommerce_wrapper_end() {
* *
* @return mixed * @return mixed
*/ */
function understrap_wc_form_field_args( $args, $key, $value = null ) { if ( ! function_exists ( 'understrap_wc_form_field_args' ) ) {
// Start field type switch case. function understrap_wc_form_field_args( $args, $key, $value = null ) {
switch ( $args['type'] ) { // Start field type switch case.
/* Targets all select input type elements, except the country and state select input types */ switch ( $args['type'] ) {
case 'select' : /* Targets all select input type elements, except the country and state select input types */
// Add a class to the field's html element wrapper - woocommerce case 'select' :
// input types (fields) are often wrapped within a <p></p> tag. // Add a class to the field's html element wrapper - woocommerce
$args['class'][] = 'form-group'; // input types (fields) are often wrapped within a <p></p> tag.
// Add a class to the form input itself. $args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' ); // Add a class to the form input itself.
$args['label_class'] = array( 'control-label' ); $args['input_class'] = array( 'form-control', 'input-lg' );
$args['custom_attributes'] = array( $args['label_class'] = array( 'control-label' );
'data-plugin' => 'select2', $args['custom_attributes'] = array(
'data-allow-clear' => 'true', 'data-plugin' => 'select2',
'aria-hidden' => 'true', 'data-allow-clear' => 'true',
// Add custom data attributes to the form input itself. 'aria-hidden' => 'true',
); // Add custom data attributes to the form input itself.
break; );
// By default WooCommerce will populate a select with the country names - $args break;
// defined for this specific input type targets only the country select element. // By default WooCommerce will populate a select with the country names - $args
case 'country' : // defined for this specific input type targets only the country select element.
$args['class'][] = 'form-group single-country'; case 'country' :
$args['label_class'] = array( 'control-label' ); $args['class'][] = 'form-group single-country';
break; $args['label_class'] = array( 'control-label' );
// By default WooCommerce will populate a select with state names - $args defined break;
// for this specific input type targets only the country select element. // By default WooCommerce will populate a select with state names - $args defined
case 'state' : // for this specific input type targets only the country select element.
// Add class to the field's html element wrapper. case 'state' :
$args['class'][] = 'form-group'; // Add class to the field's html element wrapper.
// add class to the form input itself. $args['class'][] = 'form-group';
$args['input_class'] = array( '', 'input-lg' ); // add class to the form input itself.
$args['label_class'] = array( 'control-label' ); $args['input_class'] = array( '', 'input-lg' );
$args['custom_attributes'] = array( $args['label_class'] = array( 'control-label' );
'data-plugin' => 'select2', $args['custom_attributes'] = array(
'data-allow-clear' => 'true', 'data-plugin' => 'select2',
'aria-hidden' => 'true', 'data-allow-clear' => 'true',
); 'aria-hidden' => 'true',
break; );
case 'password' : break;
case 'text' : case 'password' :
case 'email' : case 'text' :
case 'tel' : case 'email' :
case 'number' : case 'tel' :
$args['class'][] = 'form-group'; case 'number' :
$args['input_class'] = array( 'form-control', 'input-lg' ); $args['class'][] = 'form-group';
$args['label_class'] = array( 'control-label' ); $args['input_class'] = array( 'form-control', 'input-lg' );
break; $args['label_class'] = array( 'control-label' );
case 'textarea' : break;
$args['input_class'] = array( 'form-control', 'input-lg' ); case 'textarea' :
$args['label_class'] = array( 'control-label' ); $args['input_class'] = array( 'form-control', 'input-lg' );
break; $args['label_class'] = array( 'control-label' );
case 'checkbox' : break;
$args['label_class'] = array( 'custom-control custom-checkbox' ); case 'checkbox' :
$args['input_class'] = array( 'custom-control-input', 'input-lg' ); $args['label_class'] = array( 'custom-control custom-checkbox' );
break; $args['input_class'] = array( 'custom-control-input', 'input-lg' );
case 'radio' : break;
$args['label_class'] = array( 'custom-control custom-radio' ); case 'radio' :
$args['input_class'] = array( 'custom-control-input', 'input-lg' ); $args['label_class'] = array( 'custom-control custom-radio' );
break; $args['input_class'] = array( 'custom-control-input', 'input-lg' );
default : break;
$args['class'][] = 'form-group'; default :
$args['input_class'] = array( 'form-control', 'input-lg' ); $args['class'][] = 'form-group';
$args['label_class'] = array( 'control-label' ); $args['input_class'] = array( 'form-control', 'input-lg' );
break; $args['label_class'] = array( 'control-label' );
} // end switch ($args). break;
return $args; } // end switch ($args).
return $args;
}
} }
@ -137,7 +143,10 @@ function understrap_wc_form_field_args( $args, $key, $value = null ) {
* 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 );
function understrap_woocommerce_add_to_cart_args( $args, $product ) {
$args['class'] = str_replace('button','btn btn-outline-primary', 'button'); if ( ! function_exists ( 'understrap_woocommerce_add_to_cart_args' ) ) {
return $args; function understrap_woocommerce_add_to_cart_args( $args, $product ) {
} $args['class'] = str_replace('button','btn btn-outline-primary', 'button');
return $args;
}
}

View File

@ -12,29 +12,36 @@
* *
* @global array $themecolors * @global array $themecolors
*/ */
function understrap_wpcom_setup() {
global $themecolors;
// Set theme colors for third party services.
if ( ! isset( $themecolors ) ) {
$themecolors = array(
'bg' => '',
'border' => '',
'text' => '',
'link' => '',
'url' => '',
);
}
/* Add WP.com print styles */
add_theme_support( 'print-styles' );
}
add_action( 'after_setup_theme', 'understrap_wpcom_setup' ); add_action( 'after_setup_theme', 'understrap_wpcom_setup' );
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' => '',
);
}
/* Add WP.com print styles */
add_theme_support( 'print-styles' );
}
}
/* /*
* WordPress.com-specific styles * WordPress.com-specific styles
*/ */
function understrap_wpcom_styles() {
wp_enqueue_style( 'understrap-wpcom', get_template_directory_uri() . '/inc/style-wpcom.css', '20160411' );
}
add_action( 'wp_enqueue_scripts', 'understrap_wpcom_styles' ); add_action( 'wp_enqueue_scripts', 'understrap_wpcom_styles' );
if ( ! function_exists ( 'understrap_wpcom_styles' ) ) {
function understrap_wpcom_styles() {
wp_enqueue_style( 'understrap-wpcom', get_template_directory_uri() . '/inc/style-wpcom.css', '20160411' );
}
}