code formatting

This commit is contained in:
Stef Kariotidis 2016-11-21 18:25:56 +02:00
parent 968278f240
commit b41729840f
6 changed files with 439 additions and 341 deletions

View File

@ -12,7 +12,8 @@ if ( class_exists( 'WooCommerce' ) ) {
get_option( 'woocommerce_cart_page_id' ) == $this_page_id || get_option( 'woocommerce_checkout_page_id' ) == $this_page_id ||
get_option( 'woocommerce_pay_page_id' ) == $this_page_id || get_option( 'woocommerce_thanks_page_id' ) === $this_page_id ||
get_option( 'woocommerce_myaccount_page_id' ) == $this_page_id || get_option( 'woocommerce_edit_address_page_id' ) == $this_page_id ||
get_option( 'woocommerce_view_order_page_id' ) == $this_page_id || get_option( 'woocommerce_terms_page_id' ) == $this_page_id) {
get_option( 'woocommerce_view_order_page_id' ) == $this_page_id || get_option( 'woocommerce_terms_page_id' ) == $this_page_id
) {
$is_woocommerce = true;
}
@ -46,7 +47,7 @@ if ( class_exists( 'WooCommerce' ) ) {
echo $html;
}
}
?>

View File

@ -60,7 +60,7 @@
'menu_class' => 'nav navbar-nav',
'fallback_cb' => '',
'menu_id' => 'main-menu',
'walker' => new wp_bootstrap_navwalker()
'walker' => new WP_Bootstrap_Navwalker()
)
); ?>

View File

@ -1,10 +1,16 @@
<?php
//Based on Roots Sage Gallery: https://github.com/roots/sage/blob/5b9786b8ceecfe717db55666efe5bcf0c9e1801c/lib/gallery.php
/**
* Based on Roots Sage Gallery: https://github.com/roots/sage/blob/5b9786b8ceecfe717db55666efe5bcf0c9e1801c/lib/gallery.php
*
* @package understrap
*/
// Remove built in shortcode
// Remove built in shortcode.
remove_shortcode( 'gallery', 'gallery_shortcode' );
// Replace with custom shortcode
/*
* Replace with custom shortcode
*/
function shortcode_gallery( $attr ) {
$post = get_post();
static $instance = 0;
@ -36,7 +42,7 @@ function shortcode_gallery($attr) {
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => ''
'link' => '',
], $attr ) );
$id = intval( $id );
$columns = ( 12 % $columns == 0 ) ? $columns : 3;
@ -45,15 +51,34 @@ function shortcode_gallery($attr) {
$orderby = 'none';
}
if ( ! empty( $include ) ) {
$_attachments = get_posts(['include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]);
$_attachments = get_posts( [ 'include' => $include,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => $order,
'orderby' => $orderby
] );
$attachments = [];
foreach ( $_attachments as $key => $val ) {
$attachments[ $val->ID ] = $_attachments[ $key ];
}
} elseif ( ! empty( $exclude ) ) {
$attachments = get_children(['post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]);
$attachments = get_children( [ 'post_parent' => $id,
'exclude' => $exclude,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => $order,
'orderby' => $orderby
] );
} else {
$attachments = get_children(['post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]);
$attachments = get_children( [ 'post_parent' => $id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => $order,
'orderby' => $orderby
] );
}
if ( empty( $attachments ) ) {
return '';
@ -63,6 +88,7 @@ function shortcode_gallery($attr) {
foreach ( $attachments as $att_id => $attachment ) {
$output .= wp_get_attachment_link( $att_id, $size, true ) . "\n";
}
return $output;
}
$unique = ( get_query_var( 'page' ) ) ? $instance . '-p' . get_query_var( 'page' ) : $instance;
@ -91,15 +117,23 @@ function shortcode_gallery($attr) {
}
$output .= ( $i % $columns != 0 ) ? '</div>' : '';
$output .= '</div>';
return $output;
}
add_shortcode( 'gallery', 'shortcode_gallery' );
/**
* Add class="thumbnail img-thumbnail" to attachment items
*
* @param string $html markup.
*
* @return mixed
*/
function attachment_link_class( $html ) {
$html = str_replace( '<a', '<a class="thumbnail img-thumbnail"', $html );
return $html;
}
add_filter( 'wp_get_attachment_link', 'attachment_link_class', 10, 1 );

View File

@ -1,43 +1,53 @@
<?php
/**
*
* Adapted from Edward McIntyre's wp_bootstrap_navwalker class.
* Removed support for glyphicon and added support for Font Awesome
* Removed support for glyphicon and added support for Font Awesome.
*
* @package understrap
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Name: wp_bootstrap_navwalker
* Class WP_Bootstrap_Navwalker
* GitHub URI: https://github.com/twittem/wp-bootstrap-navwalker
* Description: A custom WordPress nav walker class to implement the Bootstrap 3 navigation style in a custom theme using the WordPress built in menu manager.
* Description: A custom WordPress nav walker class to implement the Bootstrap 4
* navigation style in a custom theme using the WordPress built in menu manager.
* Version: 2.0.4
* Author: Edward McIntyre - @twittem
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* @package understrap
*/
//exit if accessed directly
if(!defined('ABSPATH')) exit;
class wp_bootstrap_navwalker extends Walker_Nav_Menu {
class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {
/**
* The starting level of the menu.
*
* @see Walker::start_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
* @param mixed $args Rest of arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class=\" dropdown-menu\" role=\"menu\">\n";
}
/**
* Open element.
*
* @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
* @param mixed $args Rest arguments.
* @param int $id Element's ID.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
@ -66,9 +76,14 @@ class wp_bootstrap_navwalker extends Walker_Nav_Menu {
if ( $args->has_children )
$class_names .= ' dropdown';
*/
if($args->has_children && $depth === 0) { $class_names .= ' dropdown'; } elseif($args->has_children && $depth > 0) { $class_names .= ' dropdown-submenu'; }
if ( in_array( 'current-menu-item', $classes ) )
if ( $args->has_children && $depth === 0 ) {
$class_names .= ' dropdown';
} elseif ( $args->has_children && $depth > 0 ) {
$class_names .= ' dropdown-submenu';
}
if ( in_array( 'current-menu-item', $classes ) ) {
$class_names .= ' active';
}
// remove Font Awesome icon from classes array and save the icon
// we will add the icon back in via a <span> below so it aligns with
// the menu item
@ -107,16 +122,19 @@ class wp_bootstrap_navwalker extends Walker_Nav_Menu {
}
$item_output = $args->before;
// Font Awesome icons
if ( ! empty( $icon ) )
if ( ! empty( $icon ) ) {
$item_output .= '<a' . $attributes . '><span class="fa ' . esc_attr( $icon ) . '"></span>&nbsp;';
else
} else {
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
}
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title,
$item->ID ) . $args->link_after;
$item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
/**
* Traverse elements to create list from elements.
*
@ -135,17 +153,21 @@ class wp_bootstrap_navwalker extends Walker_Nav_Menu {
* @param int $depth Depth of current element.
* @param array $args
* @param string $output Passed by reference. Used to append additional content.
*
* @return null Null on failure with no changes to parameters.
*/
public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
if ( ! $element )
if ( ! $element ) {
return;
}
$id_field = $this->db_fields['id'];
// Display this element.
if ( is_object( $args[0] ) )
if ( is_object( $args[0] ) ) {
$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
}
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
/**
* Menu Fallback
* =============
@ -163,22 +185,27 @@ class wp_bootstrap_navwalker extends Walker_Nav_Menu {
$fb_output = null;
if ( $container ) {
$fb_output = '<' . $container;
if ( $container_class )
if ( $container_class ) {
$fb_output .= ' class="' . $container_class . '"';
if ( $container_id )
}
if ( $container_id ) {
$fb_output .= ' id="' . $container_id . '"';
}
$fb_output .= '>';
}
$fb_output .= '<ul';
if ( $menu_class )
if ( $menu_class ) {
$fb_output .= ' class="' . $menu_class . '"';
if ( $menu_id )
}
if ( $menu_id ) {
$fb_output .= ' id="' . $menu_id . '"';
}
$fb_output .= '>';
$fb_output .= '<li><a href="' . admin_url( 'nav-menus.php' ) . '">Add a menu</a></li>';
$fb_output .= '</ul>';
if ( $container )
if ( $container ) {
$fb_output .= '</' . $container . '>';
}
echo $fb_output;
}
}

View File

@ -1,30 +1,54 @@
<?php
/************* COMMENT LAYOUT *********************/
// Comment Form
/**
* Comment layout.
*
* @package understrap
*/
// Comments form.
add_filter( 'comment_form_default_fields', 'bootstrap3_comment_form_fields' );
/**
* Creates the comments form.
*
* @param string $fields Form fields.
*
* @return array
*/
function bootstrap3_comment_form_fields( $fields ) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;
$fields = array(
'author' => '<div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name', 'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'author' => '<div class="form-group comment-form-author" <label for="author">' . __( 'Name',
'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . '></div>',
'email' => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email', 'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'email' => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email',
'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . '></div>',
'url' => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website', 'understrap' ) . '</label> ' .
'url' => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website',
'understrap' ) . '</label> ' .
'<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"></div>',
);
return $fields;
}
add_filter( 'comment_form_defaults', 'bootstrap3_comment_form' );
/**
* Builds the form.
*
* @param string $args Arguments for form's fields.
*
* @return mixed
*/
function bootstrap3_comment_form( $args ) {
$args['comment_field'] = '<div class="form-group comment-form-comment">
<label for="comment">' . _x( 'Comment', 'noun', 'understrap' ) . ( ' <span class="required">*</span>' ) . '</label>
<textarea class="form-control" id="comment" name="comment" aria-required="true" cols="45" rows="8"></textarea>
</div>';
$args['class_submit'] = 'btn btn-secondary'; // since WP 4.1
$args['class_submit'] = 'btn btn-secondary'; // since WP 4.1.
return $args;
}

View File

@ -1,6 +1,6 @@
<?php
/**
* understrap Theme Customizer
* Understrap Theme Customizer
*
* @package understrap
*/
@ -11,6 +11,11 @@
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
if ( ! function_exists( 'understrap_customize_register' ) ) {
/**
* Register basic customizer support.
*
* @param object $wp_customize Customizer reference.
*/
function understrap_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
@ -21,39 +26,44 @@ if ( ! function_exists( 'understrap_customize_register' ) ) {
add_action( 'customize_register', 'understrap_customize_register' );
if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
/**
* Register individual settings through customizer's API.
*
* @param object $wp_customize Customizer reference.
*/
function understrap_theme_customize_register( $wp_customize ) {
$wp_customize->add_section( 'understrap_theme_slider_options', array(
'title' => __( 'Slider Settings', 'understrap' )
'title' => __( 'Slider Settings', 'understrap' ),
) );
$wp_customize->add_setting( 'understrap_theme_slider_count_setting', array(
'default' => '1',
'sanitize_callback' => 'absint'
'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'
'settings' => 'understrap_theme_slider_count_setting',
) );
$wp_customize->add_setting( 'understrap_theme_slider_time_setting', array(
'default' => '5000',
'sanitize_callback' => 'absint'
'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'
'settings' => 'understrap_theme_slider_time_setting',
) );
$wp_customize->add_setting( 'understrap_theme_slider_loop_setting', array(
'default' => 'true',
'sanitize_callback' => 'esc_textarea'
'sanitize_callback' => 'esc_textarea',
) );
$wp_customize->add_control( 'understrap_theme_loop', array(
@ -64,10 +74,10 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
'true' => 'yes',
'false' => 'no',
),
'settings' => 'understrap_theme_slider_loop_setting'
'settings' => 'understrap_theme_slider_loop_setting',
) );
// Theme layout settings
// Theme layout settings.
$wp_customize->add_section( 'understrap_theme_layout_options', array(
'title' => __( 'Theme Layout Settings', 'understrap' ),
'capability' => 'edit_theme_options',
@ -79,7 +89,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
'default' => 'container',
'type' => 'theme_mod',
'sanitize_callback' => 'esc_textarea',
'capability' => 'edit_theme_options'
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control(
@ -111,7 +121,8 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
$wp_customize,
'understrap_sidebar_position', array(
'label' => __( 'Sidebar Positioning', 'understrap' ),
'description' => __( "Set sidebar's position. Can either be: right, left, both or none", 'understrap' ),
'description' => __( "Set sidebar's position. Can either be: right, left, both or none",
'understrap' ),
'section' => 'understrap_theme_layout_options',
'settings' => 'understrap_sidebar_position',
'type' => 'select',
@ -125,7 +136,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
)
) );
// How to display posts index page (home.php)
// How to display posts index page (home.php).
$wp_customize->add_setting( 'understrap_posts_index_style', array(
'default' => 'default',
'type' => 'theme_mod',
@ -138,7 +149,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
$wp_customize,
'understrap_posts_index_style', array(
'label' => __( 'Posts Index Style', 'understrap' ),
'description' => __( "Choose how to display latest posts", 'understrap' ),
'description' => __( 'Choose how to display latest posts', 'understrap' ),
'section' => 'understrap_theme_layout_options',
'settings' => 'understrap_posts_index_style',
'type' => 'select',
@ -159,7 +170,8 @@ add_action( 'customize_register', 'understrap_theme_customize_register' );
*/
if ( ! function_exists( 'understrap_customize_preview_js' ) ) {
function understrap_customize_preview_js() {
wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
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' );