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
*/
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' );
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.
*/
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' );
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_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' );
return $styles;
array_unshift( $styles, 'styleselect' );
return $styles;
}
}
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(
array(
'title' => 'Lead Paragraph',
'selector' => 'p',
'classes' => 'lead',
'wrapper' => true
),
array(
'title' => 'Small',
'inline' => 'small'
),
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'classes' => 'blockquote',
'wrapper' => true
),
array(
'title' => 'Blockquote Footer',
'block' => 'footer',
'classes' => 'blockquote-footer',
'wrapper' => true
),
array(
'title' => 'Cite',
'inline' => 'cite'
)
);
if ( isset( $settings['style_formats'] ) ) {
$orig_style_formats = json_decode($settings['style_formats'],true);
$style_formats = array_merge($orig_style_formats,$style_formats);
}
$style_formats = array(
array(
'title' => 'Lead Paragraph',
'selector' => 'p',
'classes' => 'lead',
'wrapper' => true
),
array(
'title' => 'Small',
'inline' => 'small'
),
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'classes' => 'blockquote',
'wrapper' => true
),
array(
'title' => 'Blockquote Footer',
'block' => 'footer',
'classes' => 'blockquote-footer',
'wrapper' => true
),
array(
'title' => 'Cite',
'inline' => 'cite'
)
);
if ( isset( $settings['style_formats'] ) ) {
$orig_style_formats = json_decode($settings['style_formats'],true);
$style_formats = array_merge($orig_style_formats,$style_formats);
}
$settings['style_formats'] = json_encode( $style_formats );
return $settings;
$settings['style_formats'] = json_encode( $style_formats );
return $settings;
}
}

View File

@ -7,6 +7,8 @@
* @package understrap
*/
add_filter( 'body_class', 'understrap_body_classes' );
if ( ! function_exists( 'understrap_body_classes' ) ) {
/**
* Adds custom classes to the array of body classes.
@ -28,7 +30,6 @@ if ( ! function_exists( 'understrap_body_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', 'understrap_adjust_body_class' );
@ -78,8 +79,8 @@ if ( ! function_exists( 'understrap_change_logo_class' ) ) {
/**
* Display navigation to next/previous post when applicable.
*/
if ( ! function_exists( 'understrap_post_nav' ) ) :
if ( ! function_exists ( 'understrap_post_nav' ) ) {
function understrap_post_nav() {
// 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 );
@ -106,4 +107,4 @@ if ( ! function_exists( 'understrap_post_nav' ) ) :
<?php
}
endif;
}

View File

@ -13,41 +13,51 @@
* See: https://jetpack.me/support/infinite-scroll/
* 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' );
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.
*/
function understrap_components_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_components_infinite_scroll_render' ) ) {
function understrap_components_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;
}
}
}
function understrap_components_social_menu() {
if ( ! function_exists( 'jetpack_social_menu' ) ) {
return;
} else {
jetpack_social_menu();
if ( ! function_exists ( 'understrap_components_social_menu' ) ) {
function understrap_components_social_menu() {
if ( ! function_exists( 'jetpack_social_menu' ) ) {
return;
} else {
jetpack_social_menu();
}
}
}
}

View File

@ -5,54 +5,53 @@
* @package understrap
*/
if ( ! function_exists( 'understrap_pagination' ) ) :
function understrap_pagination($args = [], $class = 'pagination') {
if ( ! function_exists ( 'understrap_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, [
'mid_size' => 2,
'prev_next' => false,
'prev_text' => __('&laquo;', 'understrap'),
'next_text' => __('&raquo;', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'),
'type' => 'array',
'current' => max( 1, get_query_var('paged') ),
]);
$args = wp_parse_args( $args, [
'mid_size' => 2,
'prev_next' => false,
'prev_text' => __('&laquo;', 'understrap'),
'next_text' => __('&raquo;', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'),
'type' => 'array',
'current' => max( 1, get_query_var('paged') ),
]);
$links = paginate_links($args);
$next_link = get_next_posts_page_link();
$prev_link = get_previous_posts_page_link();
$links = paginate_links($args);
$next_link = get_next_posts_page_link();
$prev_link = get_previous_posts_page_link();
?>
?>
<nav aria-label="<?php echo $args['screen_reader_text']; ?>">
<ul class="pagination">
<li class="page-item">
<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 class="sr-only"><?php echo __('Previous', 'understrap'); ?></span>
</a>
</li>
<nav aria-label="<?php echo $args['screen_reader_text']; ?>">
<ul class="pagination">
<li class="page-item">
<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 class="sr-only"><?php echo __('Previous', 'understrap'); ?></span>
</a>
</li>
<?php
$i = 1;
foreach ( $links as $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo active; }; ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li>
<?php
$i = 1;
foreach ( $links as $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo 'active'; }; ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li>
<?php $i++;} ?>
<?php $i++;} ?>
<li class="page-item">
<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 class="sr-only"><?php echo __('Next', 'understrap'); ?></span>
</a>
</li>
</ul>
</nav>
<?php
}
endif;
?>
<li class="page-item">
<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 class="sr-only"><?php echo __('Next', 'understrap'); ?></span>
</a>
</li>
</ul>
</nav>
<?php
}
}

View File

@ -11,7 +11,9 @@ if ( ! isset( $content_width ) ) {
$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.
*
@ -91,8 +93,10 @@ if ( ! function_exists( 'understrap_setup' ) ) :
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' ) ) {
/**
@ -106,7 +110,8 @@ if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) {
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' ) ) {
/**
@ -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...',
'understrap' ) . '</a></p>';
}
}
add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' );
}

View File

@ -7,105 +7,113 @@
* @package understrap
*/
if ( ! function_exists( 'understrap_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function understrap_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$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>';
if ( ! function_exists ( 'understrap_posted_on' ) ) {
function understrap_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$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.
*/
function understrap_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) );
if ( $categories_list && understrap_categorized_blog() ) {
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'understrap' ) . '</span>', $categories_list ); // WPCS: XSS OK.
if ( ! function_exists ( 'understrap_entry_footer' ) ) {
function understrap_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) );
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 */
$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.
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>'
);
}
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.
*
* @return bool
*/
function understrap_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) {
// Create an array of all the categories that are attached to posts.
$all_the_cool_cats = get_categories( array(
'fields' => 'ids',
'hide_empty' => 1,
// 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 );
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.
return true;
} else {
// This blog has only 1 category so components_categorized_blog should return false.
return false;
if ( ! function_exists ( 'understrap_categorized_blog' ) ) {
function understrap_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) {
// Create an array of all the categories that are attached to posts.
$all_the_cool_cats = get_categories( array(
'fields' => 'ids',
'hide_empty' => 1,
// 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 );
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.
return true;
} else {
// This blog has only 1 category so components_categorized_blog should return false.
return false;
}
}
}
/**
* 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( '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() {
// 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' );
}
}
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' ) ) {
/**
* Initializes themes widgets.
@ -100,6 +102,4 @@ if ( ! function_exists( 'understrap_widgets_init' ) ) {
) );
}
} // endif function_exists( 'understrap_widgets_init' ).
add_action( 'widgets_init', 'understrap_widgets_init' );
} // endif function_exists( 'understrap_widgets_init' ).

View File

@ -4,6 +4,8 @@
*
* @package understrap
*/
add_action( 'after_setup_theme', 'understrap_woocommerce_support' );
if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
/**
@ -22,6 +24,7 @@ if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
}
}
/**
* First unhook the WooCommerce wrappers
*/
@ -54,6 +57,7 @@ function understrap_woocommerce_wrapper_end() {
}
}
/**
* Filter hook function monkey patching form classes
* Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
@ -64,72 +68,74 @@ function understrap_woocommerce_wrapper_end() {
*
* @return mixed
*/
function understrap_wc_form_field_args( $args, $key, $value = null ) {
// Start field type switch case.
switch ( $args['type'] ) {
/* Targets all select input type elements, except the country and state select input types */
case 'select' :
// Add a class to the field's html element wrapper - woocommerce
// input types (fields) are often wrapped within a <p></p> tag.
$args['class'][] = 'form-group';
// Add a class to the form input itself.
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'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
// defined for this specific input type targets only the country select element.
case 'country' :
$args['class'][] = 'form-group single-country';
$args['label_class'] = array( 'control-label' );
break;
// By default WooCommerce will populate a select with state names - $args defined
// for this specific input type targets only the country select element.
case 'state' :
// Add class to the field's html element wrapper.
$args['class'][] = 'form-group';
// add class to the form input itself.
$args['input_class'] = array( '', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'aria-hidden' => 'true',
);
break;
case 'password' :
case 'text' :
case 'email' :
case 'tel' :
case 'number' :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'textarea' :
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'checkbox' :
$args['label_class'] = array( 'custom-control custom-checkbox' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
case 'radio' :
$args['label_class'] = array( 'custom-control custom-radio' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
default :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
} // end switch ($args).
return $args;
if ( ! function_exists ( 'understrap_wc_form_field_args' ) ) {
function understrap_wc_form_field_args( $args, $key, $value = null ) {
// Start field type switch case.
switch ( $args['type'] ) {
/* Targets all select input type elements, except the country and state select input types */
case 'select' :
// Add a class to the field's html element wrapper - woocommerce
// input types (fields) are often wrapped within a <p></p> tag.
$args['class'][] = 'form-group';
// Add a class to the form input itself.
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'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
// defined for this specific input type targets only the country select element.
case 'country' :
$args['class'][] = 'form-group single-country';
$args['label_class'] = array( 'control-label' );
break;
// By default WooCommerce will populate a select with state names - $args defined
// for this specific input type targets only the country select element.
case 'state' :
// Add class to the field's html element wrapper.
$args['class'][] = 'form-group';
// add class to the form input itself.
$args['input_class'] = array( '', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'aria-hidden' => 'true',
);
break;
case 'password' :
case 'text' :
case 'email' :
case 'tel' :
case 'number' :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'textarea' :
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'checkbox' :
$args['label_class'] = array( 'custom-control custom-checkbox' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
case 'radio' :
$args['label_class'] = array( 'custom-control custom-radio' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
default :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
} // 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
*/
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');
return $args;
}
if ( ! function_exists ( 'understrap_woocommerce_add_to_cart_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
*/
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' );
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
*/
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' );
if ( ! function_exists ( 'understrap_wpcom_styles' ) ) {
function understrap_wpcom_styles() {
wp_enqueue_style( 'understrap-wpcom', get_template_directory_uri() . '/inc/style-wpcom.css', '20160411' );
}
}