Bootstrap 3 RC1

This commit is contained in:
Ben Word
2013-07-28 12:32:45 -05:00
109 changed files with 6315 additions and 7210 deletions

View File

@@ -126,54 +126,6 @@ function roots_body_class($classes) {
}
add_filter('body_class', 'roots_body_class');
/**
* Root relative URLs
*
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in config.php:
* current_theme_supports('root-relative-urls');
*
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
*/
function roots_root_relative_url($input) {
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function roots_enable_root_relative_urls() {
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (roots_enable_root_relative_urls()) {
$root_rel_filters = array(
'bloginfo_url',
'the_permalink',
'wp_list_pages',
'wp_list_categories',
'roots_wp_nav_menu_item',
'the_content_more_link',
'the_tags',
'get_pagenum_link',
'get_comment_link',
'month_link',
'day_link',
'year_link',
'tag_link',
'the_author_posts_link',
'script_loader_src',
'style_loader_src'
);
add_filters($root_rel_filters, 'roots_root_relative_url');
}
/**
* Wrap embedded media as suggested by Readability
*
@@ -234,105 +186,6 @@ function roots_caption($output, $attr, $content) {
}
add_filter('img_caption_shortcode', 'roots_caption', 10, 3);
/**
* Clean up gallery_shortcode()
*
* Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap
*
* @link http://twitter.github.com/bootstrap/components.html#thumbnails
*/
function roots_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if (!empty($attr['ids'])) {
if (empty($attr['orderby'])) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr);
if ($output != '') {
return $output;
}
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby']) {
unset($attr['orderby']);
}
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => '',
'icontag' => '',
'captiontag' => '',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));
$id = intval($id);
if ($order === 'RAND') {
$orderby = 'none';
}
if (!empty($include)) {
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($exclude)) {
$attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
} else {
$attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
}
if (empty($attachments)) {
return '';
}
if (is_feed()) {
$output = "\n";
foreach ($attachments as $att_id => $attachment) {
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
}
return $output;
}
$output = '<ul class="thumbnails gallery">';
$i = 0;
foreach ($attachments as $id => $attachment) {
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$output .= '<li>' . $link;
if (trim($attachment->post_excerpt)) {
$output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
if (current_theme_supports('bootstrap-gallery')) {
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
}
/**
* Remove unnecessary dashboard widgets
*

View File

@@ -16,7 +16,7 @@ class Roots_Walker_Comment extends Walker_Comment {
echo '</ul>';
}
function start_el(&$output, $comment, $depth, $args, $id = 0) {
function start_el(&$output, $comment, $depth = 0, $args = array(), $id = 0) {
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;

View File

@@ -21,10 +21,10 @@ define('POST_EXCERPT_LENGTH', 40);
function roots_main_class() {
if (roots_display_sidebar()) {
// Classes on pages with the sidebar
$class = 'span8';
$class = 'col-sm-8 col-lg-8';
} else {
// Classes on full width pages
$class = 'span12';
$class = 'col-lg-12';
}
return $class;
@@ -34,7 +34,7 @@ function roots_main_class() {
* .sidebar classes
*/
function roots_sidebar_class() {
return 'span4';
return 'col-sm-4 col-lg-4';
}
/**
@@ -78,3 +78,13 @@ function roots_display_sidebar() {
* Default: 940px is the default Bootstrap container width.
*/
if (!isset($content_width)) { $content_width = 940; }
/**
* Define helper constants
*/
$get_theme_name = explode('/themes/', get_template_directory());
define('RELATIVE_PLUGIN_PATH', str_replace(home_url() . '/', '', plugins_url()));
define('RELATIVE_CONTENT_PATH', str_replace(home_url() . '/', '', content_url()));
define('THEME_NAME', next($get_theme_name));
define('THEME_PATH', RELATIVE_CONTENT_PATH . '/themes/' . THEME_NAME);

100
lib/gallery.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
/**
* Clean up gallery_shortcode()
*
* Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap
*
* @link http://twitter.github.com/bootstrap/components.html#thumbnails
*/
function roots_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if (!empty($attr['ids'])) {
if (empty($attr['orderby'])) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr);
if ($output != '') {
return $output;
}
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby']) {
unset($attr['orderby']);
}
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => '',
'icontag' => '',
'captiontag' => '',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => 'file'
), $attr));
$id = intval($id);
if ($order === 'RAND') {
$orderby = 'none';
}
if (!empty($include)) {
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($exclude)) {
$attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
} else {
$attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
}
if (empty($attachments)) {
return '';
}
if (is_feed()) {
$output = "\n";
foreach ($attachments as $att_id => $attachment) {
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
}
return $output;
}
$output = '<ul class="thumbnails gallery">';
$i = 0;
foreach ($attachments as $id => $attachment) {
$image = ('file' == $link) ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$output .= '<li>' . $image;
if (trim($attachment->post_excerpt)) {
$output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
if (current_theme_supports('bootstrap-gallery')) {
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
}

View File

@@ -26,11 +26,3 @@ add_action('after_setup_theme', 'roots_setup');
// Backwards compatibility for older than PHP 5.3.0
if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); }
// Define helper constants
$get_theme_name = explode('/themes/', get_template_directory());
define('RELATIVE_PLUGIN_PATH', str_replace(home_url() . '/', '', plugins_url()));
define('RELATIVE_CONTENT_PATH', str_replace(home_url() . '/', '', content_url()));
define('THEME_NAME', next($get_theme_name));
define('THEME_PATH', RELATIVE_CONTENT_PATH . '/themes/' . THEME_NAME);

View File

@@ -30,7 +30,7 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
elseif (stristr($item_html, 'li class="divider')) {
$item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
}
elseif (stristr($item_html, 'li class="nav-header')) {
elseif (stristr($item_html, 'li class="dropdown-header')) {
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
}
@@ -42,11 +42,7 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
$element->is_dropdown = ((!empty($children_elements[$element->ID]) && (($depth + 1) < $max_depth || ($max_depth === 0))));
if ($element->is_dropdown) {
if ($depth === 0) {
$element->classes[] = 'dropdown';
} elseif ($depth === 1) {
$element->classes[] = 'dropdown-submenu';
}
$element->classes[] = 'dropdown';
}
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
@@ -85,7 +81,7 @@ function roots_nav_menu_args($args = '') {
}
if (current_theme_supports('bootstrap-top-navbar')) {
$roots_nav_menu_args['depth'] = 3;
$roots_nav_menu_args['depth'] = 2;
}
if (!$args['walker']) {

48
lib/relative-urls.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
/**
* Root relative URLs
*
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in config.php:
* current_theme_supports('root-relative-urls');
*
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
*/
function roots_root_relative_url($input) {
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function roots_enable_root_relative_urls() {
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (roots_enable_root_relative_urls()) {
$root_rel_filters = array(
'bloginfo_url',
'the_permalink',
'wp_list_pages',
'wp_list_categories',
'roots_wp_nav_menu_item',
'the_content_more_link',
'the_tags',
'get_pagenum_link',
'get_comment_link',
'month_link',
'day_link',
'year_link',
'tag_link',
'the_author_posts_link',
'script_loader_src',
'style_loader_src'
);
add_filters($root_rel_filters, 'roots_root_relative_url');
}

View File

@@ -2,14 +2,13 @@
/**
* URL rewriting
*
* Rewrites currently do not happen for child themes (or network installs)
* @todo https://github.com/retlehs/roots/issues/461
* Rewrites do not happen for multisite installations or child themes
*
* Rewrite:
* /wp-content/themes/themename/css/ to /css/
* /wp-content/themes/themename/js/ to /js/
* /wp-content/themes/themename/img/ to /img/
* /wp-content/plugins/ to /plugins/
* /wp-content/themes/themename/assets/css/ to /assets/css/
* /wp-content/themes/themename/assets/js/ to /assets/js/
* /wp-content/themes/themename/assets/img/ to /assets/img/
* /wp-content/plugins/ to /plugins/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*

View File

@@ -4,27 +4,21 @@
*
* Enqueue stylesheets in the following order:
* 1. /theme/assets/css/main.min.css
* 2. /child-theme/style.css (if a child theme is activated)
*
* Enqueue scripts in the following order:
* 1. jquery-1.10.1.min.js via Google CDN
* 1. jquery-1.10.2.min.js via Google CDN
* 2. /theme/assets/js/vendor/modernizr-2.6.2.min.js
* 3. /theme/assets/js/main.min.js (in footer)
*/
function roots_scripts() {
wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.min.css', false, '642fb47e4d0c5276c3ad6084dae68f1a');
// Load style.css from child theme
if (is_child_theme()) {
wp_enqueue_style('roots_child', get_stylesheet_uri(), false, null);
}
wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.min.css', false, '21d5bb922df17c9861ba2d713a807b4e');
// jQuery is loaded using the same method from HTML5 Boilerplate:
// Grab Google CDN's latest jQuery with a protocol relative URL; fallback to local if offline
// It's kept in the header instead of footer to avoid conflicts with plugins.
if (!is_admin() && current_theme_supports('jquery-cdn')) {
wp_deregister_script('jquery');
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js', false, null, false);
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false, null, false);
add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2);
}
@@ -33,7 +27,7 @@ function roots_scripts() {
}
wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.6.2.min.js', false, null, false);
wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, '8b9f4205f4a36229fdc83067ea78e79e', true);
wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, '4ea84cbe0a24ca4fc02cc9503f22126f', true);
wp_enqueue_script('modernizr');
wp_enqueue_script('jquery');
wp_enqueue_script('roots_scripts');
@@ -45,7 +39,7 @@ function roots_jquery_local_fallback($src, $handle) {
static $add_jquery_fallback = false;
if ($add_jquery_fallback) {
echo '<script>window.jQuery || document.write(\'<script src="' . get_template_directory_uri() . '/assets/js/vendor/jquery-1.10.1.min.js"><\/script>\')</script>' . "\n";
echo '<script>window.jQuery || document.write(\'<script src="' . get_template_directory_uri() . '/assets/js/vendor/jquery-1.10.2.min.js"><\/script>\')</script>' . "\n";
$add_jquery_fallback = false;
}

37
lib/titles.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
/**
* Page titles
*/
function roots_title() {
if (is_home()) {
if (get_option('page_for_posts', true)) {
echo get_the_title(get_option('page_for_posts', true));
} else {
_e('Latest Posts', 'roots');
}
} elseif (is_archive()) {
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
if ($term) {
echo $term->name;
} elseif (is_post_type_archive()) {
echo get_queried_object()->labels->name;
} elseif (is_day()) {
printf(__('Daily Archives: %s', 'roots'), get_the_date());
} elseif (is_month()) {
printf(__('Monthly Archives: %s', 'roots'), get_the_date('F Y'));
} elseif (is_year()) {
printf(__('Yearly Archives: %s', 'roots'), get_the_date('Y'));
} elseif (is_author()) {
$author = get_queried_object();
printf(__('Author Archives: %s', 'roots'), $author->display_name);
} else {
single_cat_title();
}
} elseif (is_search()) {
printf(__('Search Results for %s', 'roots'), get_search_query());
} elseif (is_404()) {
_e('Not Found', 'roots');
} else {
the_title();
}
}

View File

@@ -1,93 +1,7 @@
<?php
/**
* Theme wrapper
*
* @link http://scribu.net/wordpress/theme-wrappers.html
* Utility functions
*/
function roots_template_path() {
return Roots_Wrapping::$main_template;
}
function roots_sidebar_path() {
return Roots_Wrapping::sidebar();
}
class Roots_Wrapping {
// Stores the full path to the main template file
static $main_template;
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
static $base;
static function wrap($template) {
self::$main_template = $template;
self::$base = substr(basename(self::$main_template), 0, -4);
if (self::$base === 'index') {
self::$base = false;
}
$templates = array('base.php');
if (self::$base) {
array_unshift($templates, sprintf('base-%s.php', self::$base));
}
$templates = apply_filters('roots_wrap_base', $templates);
return locate_template($templates);
}
static function sidebar() {
$templates = array('templates/sidebar.php');
if (self::$base) {
array_unshift($templates, sprintf('templates/sidebar-%s.php', self::$base));
}
$templates = apply_filters('roots_wrap_sidebar', $templates);
return locate_template($templates);
}
}
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);
/**
* Page titles
*/
function roots_title() {
if (is_home()) {
if (get_option('page_for_posts', true)) {
echo get_the_title(get_option('page_for_posts', true));
} else {
_e('Latest Posts', 'roots');
}
} elseif (is_archive()) {
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
if ($term) {
echo $term->name;
} elseif (is_post_type_archive()) {
echo get_queried_object()->labels->name;
} elseif (is_day()) {
printf(__('Daily Archives: %s', 'roots'), get_the_date());
} elseif (is_month()) {
printf(__('Monthly Archives: %s', 'roots'), get_the_date('F Y'));
} elseif (is_year()) {
printf(__('Yearly Archives: %s', 'roots'), get_the_date('Y'));
} elseif (is_author()) {
$author = get_queried_object();
printf(__('Author Archives: %s', 'roots'), $author->display_name);
} else {
single_cat_title();
}
} elseif (is_search()) {
printf(__('Search Results for %s', 'roots'), get_search_query());
} elseif (is_404()) {
_e('Not Found', 'roots');
} else {
the_title();
}
}
function add_filters($tags, $function) {
foreach($tags as $tag) {
add_filter($tag, $function);

View File

@@ -5,7 +5,7 @@
function roots_widgets_init() {
// Sidebars
register_sidebar(array(
'name' => __('Primary Sidebar', 'roots'),
'name' => __('Primary', 'roots'),
'id' => 'sidebar-primary',
'before_widget' => '<section class="widget %1$s %2$s"><div class="widget-inner">',
'after_widget' => '</div></section>',

48
lib/wrapper.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
/**
* Theme wrapper
*
* @link http://scribu.net/wordpress/theme-wrappers.html
*/
function roots_template_path() {
return Roots_Wrapping::$main_template;
}
function roots_sidebar_path() {
return new Roots_Wrapping('templates/sidebar.php');
}
class Roots_Wrapping {
// Stores the full path to the main template file
static $main_template;
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
static $base;
public function __construct($template='base.php') {
$this->slug = basename($template, '.php');
$this->templates = array($template);
if (self::$base) {
$str = substr($template, 0, -4);
array_unshift($this->templates, sprintf($str . '-%s.php', self::$base));
}
}
public function __toString() {
$this->templates = apply_filters('roots_wrap_' . $this->slug, $this->templates);
return locate_template($this->templates);
}
static function wrap($main) {
self::$main_template = $main;
self::$base = basename(self::$main_template, '.php');
if (self::$base === 'index') {
self::$base = false;
}
return new Roots_Wrapping();
}
}
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);