From f597e2fe949a1e18eb778b9a5bd102de88570555 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 18 May 2017 14:03:27 +0200 Subject: Initial commit. --- inc/bootstrap-wp-navwalker.php | 223 +++++++++++++++++++++++++++++++++++++++++ inc/custom-comments.php | 30 ++++++ inc/customizer.php | 63 ++++++++++++ inc/enqueue.php | 47 +++++++++ inc/extras.php | 26 +++++ inc/jetpack.php | 38 +++++++ inc/setup.php | 100 ++++++++++++++++++ inc/template-tags.php | 123 +++++++++++++++++++++++ inc/widgets.php | 50 +++++++++ inc/wpcom.php | 29 ++++++ 10 files changed, 729 insertions(+) create mode 100644 inc/bootstrap-wp-navwalker.php create mode 100644 inc/custom-comments.php create mode 100644 inc/customizer.php create mode 100644 inc/enqueue.php create mode 100644 inc/extras.php create mode 100644 inc/jetpack.php create mode 100644 inc/setup.php create mode 100644 inc/template-tags.php create mode 100644 inc/widgets.php create mode 100644 inc/wpcom.php (limited to 'inc') diff --git a/inc/bootstrap-wp-navwalker.php b/inc/bootstrap-wp-navwalker.php new file mode 100644 index 0000000..d175e56 --- /dev/null +++ b/inc/bootstrap-wp-navwalker.php @@ -0,0 +1,223 @@ +\n"; + } + + /** + * @see Walker::start_el() + * @since 3.0.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $item Menu item data object. + * @param int $depth Depth of menu item. Used for padding. + * @param int $current_page Menu item ID. + * @param object $args + */ + public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { + $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; + + /** + * Dividers, Headers or Disabled + * ============================= + * Determine whether the item is a Divider, Header, Disabled or regular + * menu item. To prevent errors we use the strcasecmp() function to so a + * comparison that is not case sensitive. The strcasecmp() function returns + * a 0 if the strings are equal. + */ + if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) { + $output .= $indent . ''; + $fb_output .= ''; + + if ( $container ) + $fb_output .= ''; + + echo $fb_output; + } + } +} diff --git a/inc/custom-comments.php b/inc/custom-comments.php new file mode 100644 index 0000000..32f2d2e --- /dev/null +++ b/inc/custom-comments.php @@ -0,0 +1,30 @@ + '
' . ' ' . + '
', + 'email' => '
' . + '
', + 'url' => '
' . + '
', + ); + return $fields; + } + + add_filter( 'comment_form_defaults', 'bootstrap3_comment_form' ); + function bootstrap3_comment_form( $args ) { + $args['comment_field'] = '
+ + +
'; + $args['class_submit'] = 'btn btn-default'; // since WP 4.1 + return $args; + } diff --git a/inc/customizer.php b/inc/customizer.php new file mode 100644 index 0000000..fc7886b --- /dev/null +++ b/inc/customizer.php @@ -0,0 +1,63 @@ +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' ); + +function understrap_theme_customize_register( $wp_customize ) { + + $wp_customize->add_section( 'understrap_theme_slider_options', array( + 'title' => __( 'Slider Settings', 'understrap' ) + ) ); + + $wp_customize->add_setting( 'understrap_theme_slider_count_setting', array( + 'default' => '1', + 'sanitize_callback' => 'absint' + ) ); + + $wp_customize->add_control( 'understrap_theme_slider_count', array( + 'label' => __( 'Number of slides displaying at once', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_count_setting' + ) ); + + $wp_customize->add_setting( 'understrap_theme_slider_time_setting', array( + 'default' => '5000', + 'sanitize_callback' => 'absint' + ) ); + + $wp_customize->add_control( 'understrap_theme_slider_time', array( + 'label' => __( 'Slider Time (in ms)', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_time_setting' + ) ); + + +} +add_action( 'customize_register', 'understrap_theme_customize_register' ); + + + +/** + * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. + */ +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/enqueue.php b/inc/enqueue.php new file mode 100644 index 0000000..a84698f --- /dev/null +++ b/inc/enqueue.php @@ -0,0 +1,47 @@ + intval( get_theme_mod( 'understrap_theme_slider_time_setting', 5000 )), + "items"=> intval( get_theme_mod( 'understrap_theme_slider_count_setting', 1 )) + ); + + + wp_enqueue_script("understrap-slider-script", get_stylesheet_directory_uri() . '/js/slider_settings.js', array(), '0.3.9'); + wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data ); + } +} +endif; + + + + diff --git a/inc/extras.php b/inc/extras.php new file mode 100644 index 0000000..5e7aecf --- /dev/null +++ b/inc/extras.php @@ -0,0 +1,26 @@ + 'main', + 'render' => 'understrap_infinite_scroll_render', + 'footer' => 'page', + ) ); + // Add theme support for Responsive Videos. + add_theme_support( 'jetpack-responsive-videos' ); +} +add_action( 'after_setup_theme', 'understrap_jetpack_setup' ); +/** + * Custom render function for Infinite Scroll. + */ +function understrap_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; + } +} diff --git a/inc/setup.php b/inc/setup.php new file mode 100644 index 0000000..622c570 --- /dev/null +++ b/inc/setup.php @@ -0,0 +1,100 @@ + tag in the document head, and expect WordPress to + * provide it for us. + */ + add_theme_support( 'title-tag' ); + + /* + * Enable support for Post Thumbnails on posts and pages. + * + * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails + */ + //add_theme_support( 'post-thumbnails' ); + + // 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" ); + + /* + * 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' => '', + ) ) ); +} +endif; // understrap_setup +add_action( 'after_setup_theme', 'understrap_setup' ); + +/** +* Adding the Read more link to excerpts +*/ +/*function new_excerpt_more( $more ) { + return '

' . __('Read More', 'understrap') . '

'; +} +add_filter( 'excerpt_more', 'new_excerpt_more' );*/ +/* Removes the ... from the excerpt read more link */ +function custom_excerpt_more( $more ) { + return ''; +} +add_filter( 'excerpt_more', 'custom_excerpt_more' ); + +/* Adds a custom read more link to all excerpts, manually or automatically generated */ + +function all_excerpts_get_more_link($post_excerpt) { + + return $post_excerpt . ' [...]

' . __('Read More...', 'understrap') . '

'; +} +add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); diff --git a/inc/template-tags.php b/inc/template-tags.php new file mode 100644 index 0000000..067155e --- /dev/null +++ b/inc/template-tags.php @@ -0,0 +1,123 @@ +%2$s'; + 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' ), + '' . $time_string . '' + ); + + $byline = sprintf( + esc_html_x( 'by %s', 'post author', 'understrap' ), + '' . esc_html( get_the_author() ) . '' + ); + + echo '' . $posted_on . ' ' . $byline . ''; + +} +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( __( ', ', 'understrap' ) ); + if ( $categories_list && understrap_categorized_blog() ) { + printf( '' . __( 'Posted in %1$s', 'understrap' ) . '', $categories_list ); + } + + /* translators: used between list items, there is a space after the comma */ + $tags_list = get_the_tag_list( '', __( ', ', 'understrap' ) ); + if ( $tags_list ) { + printf( '' . __( 'Tagged %1$s', 'understrap' ) . '', $tags_list ); + } + } + + if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { + echo ''; + comments_popup_link( __( 'Leave a comment', 'understrap' ), __( '1 Comment', 'understrap' ), __( '% Comments', 'understrap' ) ); + echo ''; + } + + edit_post_link( + sprintf( + /* translators: %s: Name of current post */ + esc_html__( 'Edit %s', 'understrap' ), + the_title( '"', '"', false ) + ), + '', + '' + ); +} +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 understrap_categorized_blog should return true. + return true; + } else { + // This blog has only 1 category so understrap_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' ); diff --git a/inc/widgets.php b/inc/widgets.php new file mode 100644 index 0000000..38aff3d --- /dev/null +++ b/inc/widgets.php @@ -0,0 +1,50 @@ + __( 'Sidebar', 'understrap' ), + 'id' => 'sidebar-1', + 'description' => 'Sidebar widget area', + '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!', + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Hero Static', 'understrap' ), + 'id' => 'statichero', + 'description' => 'Static Hero widget. no slider functionallity', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Footer Full', 'understrap' ), + 'id' => 'footerfull', + 'description' => 'Widget area below main content and above footer', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + +} +add_action( 'widgets_init', 'understrap_widgets_init' ); \ No newline at end of file diff --git a/inc/wpcom.php b/inc/wpcom.php new file mode 100644 index 0000000..8400caa --- /dev/null +++ b/inc/wpcom.php @@ -0,0 +1,29 @@ + '', + 'border' => '', + 'text' => '', + 'link' => '', + 'url' => '', + ); + } +} +add_action( 'after_setup_theme', 'understrap_wpcom_setup' ); -- cgit v1.2.3