From 00c9709fd9763542e848f6278db8ba26af5c9886 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Oct 2018 23:46:42 +0200 Subject: Initial commit. --- inc/class-wp-bootstrap-navwalker.php | 559 +++++++++++++++++++++++++++++++++++ inc/custom-comments.php | 71 +++++ inc/custom-header.php | 49 +++ inc/customizer.php | 135 +++++++++ inc/editor.php | 78 +++++ inc/enqueue.php | 34 +++ inc/extras.php | 114 +++++++ inc/hooks.php | 49 +++ inc/jetpack.php | 67 +++++ inc/pagination.php | 56 ++++ inc/setup.php | 132 +++++++++ inc/style-wpcom.css | 7 + inc/template-tags.php | 137 +++++++++ inc/theme-settings.php | 36 +++ inc/widgets.php | 119 ++++++++ inc/woocommerce.php | 140 +++++++++ inc/wpcom.php | 51 ++++ 17 files changed, 1834 insertions(+) create mode 100644 inc/class-wp-bootstrap-navwalker.php create mode 100644 inc/custom-comments.php create mode 100644 inc/custom-header.php create mode 100644 inc/customizer.php create mode 100644 inc/editor.php create mode 100644 inc/enqueue.php create mode 100644 inc/extras.php create mode 100644 inc/hooks.php create mode 100644 inc/jetpack.php create mode 100644 inc/pagination.php create mode 100644 inc/setup.php create mode 100644 inc/style-wpcom.css create mode 100644 inc/template-tags.php create mode 100755 inc/theme-settings.php create mode 100644 inc/widgets.php create mode 100644 inc/woocommerce.php create mode 100644 inc/wpcom.php (limited to 'inc') diff --git a/inc/class-wp-bootstrap-navwalker.php b/inc/class-wp-bootstrap-navwalker.php new file mode 100644 index 0000000..a343fcc --- /dev/null +++ b/inc/class-wp-bootstrap-navwalker.php @@ -0,0 +1,559 @@ +item_spacing ) && 'discard' === $args->item_spacing ) { + $t = ''; + $n = ''; + } else { + $t = "\t"; + $n = "\n"; + } + $indent = str_repeat( $t, $depth ); + // Default class to add to the file. + $classes = array( 'dropdown-menu' ); + /** + * Filters the CSS class(es) applied to a menu list element. + * + * @since WP 4.8.0 + * + * @param array $classes The CSS classes that are applied to the menu `'; + if ( $container ) { + $fallback_output .= ''; + } + + // if $args has 'echo' key and it's true echo, otherwise return. + if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { + echo $fallback_output; // WPCS: XSS OK. + } else { + return $fallback_output; + } + } + } + + /** + * Find any custom linkmod or icon classes and store in their holder + * arrays then remove them from the main classes array. + * + * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only + * Supported iconsets: Font Awesome 4/5, Glypicons + * + * NOTE: This accepts the linkmod and icon arrays by reference. + * + * @since 4.0.0 + * + * @param array $classes an array of classes currently assigned to the item. + * @param array $linkmod_classes an array to hold linkmod classes. + * @param array $icon_classes an array to hold icon classes. + * @param integer $depth an integer holding current depth level. + * + * @return array $classes a maybe modified array of classnames. + */ + private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { + // Loop through $classes array to find linkmod or icon classes. + foreach ( $classes as $key => $class ) { + // If any special classes are found, store the class in it's + // holder array and and unset the item from $classes. + if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { + // Test for .disabled or .sr-only classes. + $linkmod_classes[] = $class; + unset( $classes[ $key ] ); + } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { + // Test for .dropdown-header or .dropdown-divider and a + // depth greater than 0 - IE inside a dropdown. + $linkmod_classes[] = $class; + unset( $classes[ $key ] ); + } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { + // Font Awesome. + $icon_classes[] = $class; + unset( $classes[ $key ] ); + } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { + // Glyphicons. + $icon_classes[] = $class; + unset( $classes[ $key ] ); + } + } + + return $classes; + } + + /** + * Return a string containing a linkmod type and update $atts array + * accordingly depending on the decided. + * + * @since 4.0.0 + * + * @param array $linkmod_classes array of any link modifier classes. + * + * @return string empty for default, a linkmod type string otherwise. + */ + private function get_linkmod_type( $linkmod_classes = array() ) { + $linkmod_type = ''; + // Loop through array of linkmod classes to handle their $atts. + if ( ! empty( $linkmod_classes ) ) { + foreach ( $linkmod_classes as $link_class ) { + if ( ! empty( $link_class ) ) { + + // check for special class types and set a flag for them. + if ( 'dropdown-header' === $link_class ) { + $linkmod_type = 'dropdown-header'; + } elseif ( 'dropdown-divider' === $link_class ) { + $linkmod_type = 'dropdown-divider'; + } elseif ( 'dropdown-item-text' === $link_class ) { + $linkmod_type = 'dropdown-item-text'; + } + } + } + } + return $linkmod_type; + } + + /** + * Update the attributes of a nav item depending on the limkmod classes. + * + * @since 4.0.0 + * + * @param array $atts array of atts for the current link in nav item. + * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. + * + * @return array maybe updated array of attributes for item. + */ + private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { + if ( ! empty( $linkmod_classes ) ) { + foreach ( $linkmod_classes as $link_class ) { + if ( ! empty( $link_class ) ) { + // update $atts with a space and the extra classname... + // so long as it's not a sr-only class. + if ( 'sr-only' !== $link_class ) { + $atts['class'] .= ' ' . esc_attr( $link_class ); + } + // check for special class types we need additional handling for. + if ( 'disabled' === $link_class ) { + // Convert link to '#' and unset open targets. + $atts['href'] = '#'; + unset( $atts['target'] ); + } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { + // Store a type flag and unset href and target. + unset( $atts['href'] ); + unset( $atts['target'] ); + } + } + } + } + return $atts; + } + + /** + * Wraps the passed text in a screen reader only class. + * + * @since 4.0.0 + * + * @param string $text the string of text to be wrapped in a screen reader class. + * @return string the string wrapped in a span with the class. + */ + private function wrap_for_screen_reader( $text = '' ) { + if ( $text ) { + $text = '' . $text . ''; + } + return $text; + } + + /** + * Returns the correct opening element and attributes for a linkmod. + * + * @since 4.0.0 + * + * @param string $linkmod_type a sting containing a linkmod type flag. + * @param string $attributes a string of attributes to add to the element. + * + * @return string a string with the openign tag for the element with attribibutes added. + */ + private function linkmod_element_open( $linkmod_type, $attributes = '' ) { + $output = ''; + if ( 'dropdown-item-text' === $linkmod_type ) { + $output .= ''; + } elseif ( 'dropdown-header' === $linkmod_type ) { + // For a header use a span with the .h6 class instead of a real + // header tag so that it doesn't confuse screen readers. + $output .= ''; + } elseif ( 'dropdown-divider' === $linkmod_type ) { + // this is a divider. + $output .= ''; + } + return $output; + } + } +} diff --git a/inc/custom-comments.php b/inc/custom-comments.php new file mode 100644 index 0000000..c4aa7c7 --- /dev/null +++ b/inc/custom-comments.php @@ -0,0 +1,71 @@ + '
' . + '
', + 'email' => '', + 'url' => '
' . + '
', + 'cookies' => '', + ); + + return $fields; + } +} // endif function_exists( 'understrap_bootstrap_comment_form_fields' ) + +add_filter( 'comment_form_defaults', 'understrap_bootstrap_comment_form' ); + +/** + * Builds the form. + * + * @param string $args Arguments for form's fields. + * + * @return mixed + */ + +if ( ! function_exists( 'understrap_bootstrap_comment_form' ) ) { + + function understrap_bootstrap_comment_form( $args ) { + $args['comment_field'] = '
+
+ + +
+
'; + $args['class_submit'] = 'btn btn-secondary'; // since WP 4.1. + return $args; + } +} // endif function_exists( 'understrap_bootstrap_comment_form' ) diff --git a/inc/custom-header.php b/inc/custom-header.php new file mode 100644 index 0000000..b66a416 --- /dev/null +++ b/inc/custom-header.php @@ -0,0 +1,49 @@ + 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' ), + ), + ) ); + } +} \ No newline at end of file diff --git a/inc/customizer.php b/inc/customizer.php new file mode 100644 index 0000000..6729d77 --- /dev/null +++ b/inc/customizer.php @@ -0,0 +1,135 @@ +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' ) ) { + /** + * Register individual settings through customizer's API. + * + * @param WP_Customize_Manager $wp_customize Customizer reference. + */ + function understrap_theme_customize_register( $wp_customize ) { + + // Theme layout settings. + $wp_customize->add_section( 'understrap_theme_layout_options', array( + 'title' => __( 'Theme Layout Settings', 'understrap' ), + 'capability' => 'edit_theme_options', + 'description' => __( 'Container width and sidebar defaults', 'understrap' ), + 'priority' => 160, + ) ); + + /** + * Select sanitization function + * + * @param string $input Slug to sanitize. + * @param WP_Customize_Setting $setting Setting instance. + * @return string Sanitized slug if it is a valid choice; otherwise, the setting default. + */ + function understrap_theme_slug_sanitize_select( $input, $setting ){ + + // Ensure input is a slug (lowercase alphanumeric characters, dashes and underscores are allowed only). + $input = sanitize_key( $input ); + + // Get the list of possible select options. + $choices = $setting->manager->get_control( $setting->id )->choices; + + // If the input is a valid key, return it; otherwise, return the default. + return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); + + } + + $wp_customize->add_setting( 'understrap_container_type', array( + 'default' => 'container', + 'type' => 'theme_mod', + 'sanitize_callback' => 'understrap_theme_slug_sanitize_select', + 'capability' => 'edit_theme_options', + ) ); + + $wp_customize->add_control( + new WP_Customize_Control( + $wp_customize, + 'understrap_container_type', array( + 'label' => __( 'Container Width', 'understrap' ), + 'description' => __( 'Choose between Bootstrap\'s container and container-fluid', 'understrap' ), + 'section' => 'understrap_theme_layout_options', + 'settings' => 'understrap_container_type', + 'type' => 'select', + 'choices' => array( + 'container' => __( 'Fixed width container', 'understrap' ), + 'container-fluid' => __( 'Full width container', 'understrap' ), + ), + 'priority' => '10', + ) + ) ); + + $wp_customize->add_setting( 'understrap_sidebar_position', array( + 'default' => 'right', + 'type' => 'theme_mod', + 'sanitize_callback' => 'sanitize_text_field', + 'capability' => 'edit_theme_options', + ) ); + + $wp_customize->add_control( + new WP_Customize_Control( + $wp_customize, + 'understrap_sidebar_position', array( + 'label' => __( 'Sidebar Positioning', 'understrap' ), + 'description' => __( 'Set sidebar\'s default position. Can either be: right, left, both or none. Note: this can be overridden on individual pages.', + 'understrap' ), + 'section' => 'understrap_theme_layout_options', + 'settings' => 'understrap_sidebar_position', + 'type' => 'select', + 'sanitize_callback' => 'understrap_theme_slug_sanitize_select', + 'choices' => array( + 'right' => __( 'Right sidebar', 'understrap' ), + 'left' => __( 'Left sidebar', 'understrap' ), + 'both' => __( 'Left & Right sidebars', 'understrap' ), + 'none' => __( 'No sidebar', 'understrap' ), + ), + 'priority' => '20', + ) + ) ); + } +} // endif function_exists( 'understrap_theme_customize_register' ). +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' ) ) { + /** + * Setup JS integration for live previewing. + */ + 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' ); diff --git a/inc/editor.php b/inc/editor.php new file mode 100644 index 0000000..4b71ee9 --- /dev/null +++ b/inc/editor.php @@ -0,0 +1,78 @@ + '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; + } +} diff --git a/inc/enqueue.php b/inc/enqueue.php new file mode 100644 index 0000000..a51937f --- /dev/null +++ b/inc/enqueue.php @@ -0,0 +1,34 @@ +get( 'Version' ); + + $css_version = $theme_version . '.' . filemtime(get_template_directory() . '/css/theme.css'); + wp_enqueue_style( 'theme-styles', get_stylesheet_directory_uri() . '/css/theme.css', array(), $css_version ); + + wp_enqueue_script( 'jquery'); + + $js_version = $theme_version . '.' . filemtime(get_template_directory() . '/js/theme.min.js'); + wp_enqueue_script( 'theme-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), $js_version, true ); + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); + } + } +} // endif function_exists( 'understrap_scripts' ). + +add_action( 'wp_enqueue_scripts', 'understrap_scripts' ); diff --git a/inc/extras.php b/inc/extras.php new file mode 100644 index 0000000..94f7485 --- /dev/null +++ b/inc/extras.php @@ -0,0 +1,114 @@ + $value ) { + if ( 'tag' == $value ) { + unset( $classes[ $key ] ); + } + } + + return $classes; + + } +} + +// Filter custom logo with correct classes. +add_filter( 'get_custom_logo', 'understrap_change_logo_class' ); + +if ( ! function_exists( 'understrap_change_logo_class' ) ) { + /** + * Replaces logo CSS class. + * + * @param string $html Markup. + * + * @return mixed + */ + function understrap_change_logo_class( $html ) { + + $html = str_replace( 'class="custom-logo"', 'class="img-fluid"', $html ); + $html = str_replace( 'class="custom-logo-link"', 'class="navbar-brand custom-logo-link"', $html ); + $html = str_replace( 'alt=""', 'title="Home" alt="logo"' , $html ); + + return $html; + } +} + +/** + * Display navigation to next/previous post when applicable. + */ + +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 ); + $next = get_adjacent_post( false, '', false ); + + if ( ! $next && ! $previous ) { + return; + } + ?> + + + %2$s | %3$s(%4$s)', + esc_url( __( 'http://wordpress.org/', 'understrap' ) ), + sprintf( + /* translators:*/ + esc_html__( 'Proudly powered by %s', 'understrap' ), 'WordPress' + ), + sprintf( // WPCS: XSS ok. + /* translators:*/ + esc_html__( 'Theme: %1$s by %2$s.', 'understrap' ), $the_theme->get( 'Name' ), 'understrap.com' + ), + sprintf( // WPCS: XSS ok. + /* translators:*/ + esc_html__( 'Version: %1$s', 'understrap' ), $the_theme->get( 'Version' ) + ) + ); + + echo apply_filters( 'understrap_site_info_content', $site_info ); // WPCS: XSS ok. + } +} diff --git a/inc/jetpack.php b/inc/jetpack.php new file mode 100644 index 0000000..1c2579c --- /dev/null +++ b/inc/jetpack.php @@ -0,0 +1,67 @@ + 'main', + 'render' => 'understrap_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. + */ + +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; + } + } +} + +if ( ! function_exists ( 'understrap_components_social_menu' ) ) { + function understrap_components_social_menu() { + if ( ! function_exists( 'jetpack_social_menu' ) ) { + return; + } else { + jetpack_social_menu(); + } + } +} \ No newline at end of file diff --git a/inc/pagination.php b/inc/pagination.php new file mode 100644 index 0000000..9a6ff79 --- /dev/null +++ b/inc/pagination.php @@ -0,0 +1,56 @@ +max_num_pages <= 1) return; + + $args = wp_parse_args( $args, array( + 'mid_size' => 2, + 'prev_next' => true, + 'prev_text' => __('«', 'understrap'), + 'next_text' => __('»', 'understrap'), + 'screen_reader_text' => __('Posts navigation', 'understrap'), + 'type' => 'array', + 'current' => max( 1, get_query_var('paged') ), + ) ); + + $links = paginate_links($args); + + ?> + + + + diff --git a/inc/setup.php b/inc/setup.php new file mode 100644 index 0000000..5118851 --- /dev/null +++ b/inc/setup.php @@ -0,0 +1,132 @@ + tag in the document head, and expect WordPress to + * provide it for us. + */ + add_theme_support( 'title-tag' ); + + // This theme uses wp_nav_menu() in one location. + register_nav_menus( array( + 'primary' => __( 'Primary Menu', 'understrap' ), + ) ); + + /* + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + add_theme_support( 'html5', array( + 'search-form', + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) ); + + /* + * Adding Thumbnail basic support + */ + add_theme_support( 'post-thumbnails' ); + + /* + * Adding support for Widget edit icons in customizer + */ + add_theme_support( 'customize-selective-refresh-widgets' ); + + /* + * Enable support for Post Formats. + * See http://codex.wordpress.org/Post_Formats + */ + add_theme_support( 'post-formats', array( + 'aside', + 'image', + 'video', + 'quote', + 'link', + ) ); + + // Set up the WordPress core custom background feature. + add_theme_support( 'custom-background', apply_filters( 'understrap_custom_background_args', array( + 'default-color' => 'ffffff', + 'default-image' => '', + ) ) ); + + // Set up the WordPress Theme logo feature. + add_theme_support( 'custom-logo' ); + + // Check and setup theme default settings. + understrap_setup_theme_default_settings(); + + } +} + + +add_filter( 'excerpt_more', 'understrap_custom_excerpt_more' ); + +if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) { + /** + * Removes the ... from the excerpt read more link + * + * @param string $more The excerpt. + * + * @return string + */ + function understrap_custom_excerpt_more( $more ) { + return ''; + } +} + +add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' ); + +if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) { + /** + * Adds a custom read more link to all excerpts, manually or automatically generated + * + * @param string $post_excerpt Posts's excerpt. + * + * @return string + */ + function understrap_all_excerpts_get_more_link( $post_excerpt ) { + + return $post_excerpt . '

' . __( 'Mehr lesen...', + 'understrap' ) . '

'; + } +} diff --git a/inc/style-wpcom.css b/inc/style-wpcom.css new file mode 100644 index 0000000..0b6da17 --- /dev/null +++ b/inc/style-wpcom.css @@ -0,0 +1,7 @@ +/* + * Theme Name: Components + * + * Add any WordPress.com-specific CSS here + * + * This file is enqueued in /inc/wpcom.php + */ \ No newline at end of file diff --git a/inc/template-tags.php b/inc/template-tags.php new file mode 100644 index 0000000..8ef2eb6 --- /dev/null +++ b/inc/template-tags.php @@ -0,0 +1,137 @@ +%2$s'; + $time_string = sprintf( $time_string, + esc_attr( get_the_date( 'c' ) ), + esc_html( get_the_date() ) + ); + /* + $time_string = ''; + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string = ''; + } + $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' ), + esc_html_x( 'Autor:', 'post date', 'understrap' ), + '' . $time_string . '' + ); + */ + $posted_on = '' . $time_string . ''; + $byline = sprintf( + esc_html_x( 'Autor: %s', 'post author', 'understrap' ), + '' . esc_html( get_the_author() ) . '' + ); + echo ' | ' . $posted_on . ' | '; comments_number("0 Kommentare", "1 Kommentar", "% Kommentare"); echo ''; // WPCS: XSS OK. + } +} + + +/** + * Prints HTML with meta information for the categories, tags and comments. + */ +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( 'folder ' . esc_html__( '%1$s', 'understrap' ) . '', $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( 'label' . esc_html__( '%1$s', 'understrap' ) . '', $tags_list ); // WPCS: XSS OK. + } + } + /* + if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { + echo ''; + comments_popup_link( esc_html__( 'Leave a comment', 'understrap' ), esc_html__( '1 Comment', 'understrap' ), esc_html__( '% Comments', 'understrap' ) ); + echo ''; + } + */ + # /* translators: %s: Name of current post */ + /* + edit_post_link( + sprintf( + esc_html__( 'Edit %s', 'understrap' ), + the_title( '"', '"', false ) + ), + '', + '' + ); + */ + } +} + + +/** + * Returns true if a blog has more than 1 category. + * + * @return bool + */ +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. + */ +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' ); + } +} diff --git a/inc/theme-settings.php b/inc/theme-settings.php new file mode 100755 index 0000000..9bee616 --- /dev/null +++ b/inc/theme-settings.php @@ -0,0 +1,36 @@ + 6 ) : + // Four widgets per row if there are exactly four or more than six + $widget_classes .= ' col-md-3'; + elseif ( 6 == $widget_count ) : + // If two widgets are published + $widget_classes .= ' col-md-2'; + elseif ( $widget_count >= 3 ) : + // Three widgets per row if there's three or more widgets + $widget_classes .= ' col-md-4'; + elseif ( 2 == $widget_count ) : + // If two widgets are published + $widget_classes .= ' col-md-6'; + elseif ( 1 == $widget_count ) : + // If just on widget is active + $widget_classes .= ' col-md-12'; + endif; + return $widget_classes; + endif; + } +} + +add_action( 'widgets_init', 'understrap_widgets_init' ); + +if ( ! function_exists( 'understrap_widgets_init' ) ) { + /** + * Initializes themes widgets. + */ + function understrap_widgets_init() { + register_sidebar( array( + 'name' => __( 'Right Sidebar', 'understrap' ), + 'id' => 'right-sidebar', + 'description' => __( 'Right sidebar widget area', 'understrap' ), + 'before_widget' => '', + 'before_title' => '

', + 'after_title' => '

', + ) ); + + register_sidebar( array( + 'name' => __( 'Left Sidebar', 'understrap' ), + 'id' => 'left-sidebar', + 'description' => __( 'Left sidebar widget area', 'understrap' ), + 'before_widget' => '', + 'before_title' => '

', + 'after_title' => '

', + ) ); + + register_sidebar( array( + 'name' => __( 'Hero Slider', 'understrap' ), + 'id' => 'hero', + 'description' => __( 'Hero slider area. Place two or more widgets here and they will slide!', 'understrap' ), + 'before_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Hero Canvas', 'understrap' ), + 'id' => 'herocanvas', + 'description' => __( 'Full size canvas hero area for Bootstrap and other custom HTML markup', 'understrap' ), + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Top Full', 'understrap' ), + 'id' => 'statichero', + 'description' => __( 'Full top widget with dynamic grid', 'understrap' ), + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '

', + 'after_title' => '

', + ) ); + + register_sidebar( array( + 'name' => __( 'Footer Full', 'understrap' ), + 'id' => 'footerfull', + 'description' => __( 'Full sized footer widget with dynamic grid', 'understrap' ), + 'before_widget' => '', + 'before_title' => '

', + 'after_title' => '

', + ) ); + + } +} // endif function_exists( 'understrap_widgets_init' ). diff --git a/inc/woocommerce.php b/inc/woocommerce.php new file mode 100644 index 0000000..3cd8e9b --- /dev/null +++ b/inc/woocommerce.php @@ -0,0 +1,140 @@ +'; + echo '
'; + echo '
'; + get_template_part( 'global-templates/left-sidebar-check' ); + echo '
'; + } +} +if ( ! function_exists( 'understrap_woocommerce_wrapper_end' ) ) { +function understrap_woocommerce_wrapper_end() { + echo '
'; + get_template_part( 'global-templates/right-sidebar-check' ); + echo '
'; + echo '
'; + echo ''; + } +} + + +/** + * Filter hook function monkey patching form classes + * Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826 + * + * @param string $args Form attributes. + * @param string $key Not in use. + * @param null $value Not in use. + * + * @return mixed + */ +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

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; + } +} \ No newline at end of file diff --git a/inc/wpcom.php b/inc/wpcom.php new file mode 100644 index 0000000..ca42c38 --- /dev/null +++ b/inc/wpcom.php @@ -0,0 +1,51 @@ + '', + 'border' => '', + 'text' => '', + 'link' => '', + 'url' => '', + ); + } + + /* Add WP.com print styles */ + add_theme_support( 'print-styles' ); + } +} + + +/* + * WordPress.com-specific 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' ); + } +} \ No newline at end of file -- cgit v1.2.3