Merge master

This commit is contained in:
Ben Word
2013-02-04 22:35:15 -06:00
36 changed files with 1446 additions and 1660 deletions

View File

@@ -360,8 +360,10 @@ function roots_gallery($attr) {
return $output;
}
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
if (current_theme_supports('bootstrap-gallery')) {
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
}
/**
* Remove unnecessary dashboard widgets
@@ -488,7 +490,9 @@ function roots_nice_search_redirect() {
}
}
add_action('template_redirect', 'roots_nice_search_redirect');
if (current_theme_supports('nice-search')) {
add_action('template_redirect', 'roots_nice_search_redirect');
}
/**
* Fix for empty search queries redirecting to home page

View File

@@ -1,14 +1,42 @@
<?php
/**
* Roots configuration
*/
// Enable theme features
/**
* Enable theme features
*/
add_theme_support('root-relative-urls'); // Enable relative URLs
add_theme_support('rewrite-urls'); // Enable URL rewrites
add_theme_support('rewrites'); // Enable URL rewrites
add_theme_support('h5bp-htaccess'); // Enable HTML5 Boilerplate's .htaccess
add_theme_support('bootstrap-top-navbar'); // Enable Bootstrap's fixed navbar
add_theme_support('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
add_theme_support('nice-search'); // Enable /?s= to /search/ redirect
/**
* Configuration values
*/
define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y
define('POST_EXCERPT_LENGTH', 40);
/**
* .main classes
*/
function roots_main_class() {
if (roots_display_sidebar()) {
// Classes on pages with the sidebar
$class = 'span8';
} else {
// Classes on full width pages
$class = 'span12';
}
return $class;
}
/**
* .sidebar classes
*/
function roots_sidebar_class() {
return 'span4';
}
/**
* Define which pages shouldn't have the sidebar
@@ -43,33 +71,11 @@ function roots_display_sidebar() {
return $sidebar_config->display;
}
// #main CSS classes
function roots_main_class() {
if (roots_display_sidebar()) {
$class = 'span8';
} else {
$class = 'span12';
}
return $class;
}
// #sidebar CSS classes
function roots_sidebar_class() {
return 'span4';
}
// Configuration values
define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y
define('POST_EXCERPT_LENGTH', 40);
/**
* $content_width is a global variable used by WordPress for max image upload sizes and media embeds (in pixels)
*
* Example: If the content area is 640px wide, set $content_width = 620; so images and videos will not overflow.
*
* Default: 940px is the default Bootstrap container width.
*
* This is not required or used by Roots.
*/
* $content_width is a global variable used by WordPress for max image upload sizes
* and media embeds (in pixels).
*
* Example: If the content area is 640px wide, set $content_width = 620; so images and videos will not overflow.
* Default: 940px is the default Bootstrap container width.
*/
if (!isset($content_width)) { $content_width = 940; }

View File

@@ -1,95 +1,28 @@
<?php
/**
* URL rewriting and addition of HTML5 Boilerplate's .htaccess
*
* Rewrites currently do not happen for child themes (or network installs)
* @todo https://github.com/retlehs/roots/issues/461
*
* 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/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*
* @link https://github.com/retlehs/roots/blob/master/doc/rewrites.md
* Add HTML5 Boilerplate's .htaccess via WordPress
*/
if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') || stristr($_SERVER['SERVER_SOFTWARE'], 'litespeed') !== false) {
// Add the contents of h5bp-htaccess into .htaccess
function roots_add_h5bp_htaccess($content) {
global $wp_rewrite;
$home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
$htaccess_file = $home_path . '.htaccess';
$mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
// Show an admin notice if .htaccess isn't writable
function roots_htaccess_writable() {
if (!is_writable(get_home_path() . '.htaccess')) {
if (current_user_can('administrator')) {
add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';"));
if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
if ($mod_rewrite_enabled) {
$h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
if ($h5bp_rules === array()) {
$filename = dirname(__FILE__) . '/h5bp-htaccess';
return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
}
}
}
add_action('admin_init', 'roots_htaccess_writable');
return $content;
}
function roots_add_rewrites($content) {
global $wp_rewrite;
$roots_new_non_wp_rules = array(
'assets/css/(.*)' => THEME_PATH . '/assets/css/$1',
'assets/js/(.*)' => THEME_PATH . '/assets/js/$1',
'assets/img/(.*)' => THEME_PATH . '/assets/img/$1',
'plugins/(.*)' => RELATIVE_PLUGIN_PATH . '/$1'
);
$wp_rewrite->non_wp_rules = array_merge($wp_rewrite->non_wp_rules, $roots_new_non_wp_rules);
return $content;
}
function roots_clean_urls($content) {
if (strpos($content, FULL_RELATIVE_PLUGIN_PATH) === 0) {
return str_replace(FULL_RELATIVE_PLUGIN_PATH, WP_BASE . '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
if (current_theme_supports('rewrite-urls')) {
add_action('generate_rewrite_rules', 'roots_add_rewrites');
}
if (current_theme_supports('h5bp-htaccess')) {
add_action('generate_rewrite_rules', 'roots_add_h5bp_htaccess');
}
if (!is_admin() && current_theme_supports('rewrite-urls')) {
$tags = array(
'plugins_url',
'bloginfo',
'stylesheet_directory_uri',
'template_directory_uri',
'script_loader_src',
'style_loader_src'
);
add_filters($tags, 'roots_clean_urls');
}
}
// Add the contents of h5bp-htaccess into the .htaccess file
function roots_add_h5bp_htaccess($content) {
global $wp_rewrite;
$home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
$htaccess_file = $home_path . '.htaccess';
$mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
if ($mod_rewrite_enabled) {
$h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
if ($h5bp_rules === array()) {
$filename = dirname(__FILE__) . '/h5bp-htaccess';
return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
}
}
}
return $content;
}
}
if (current_theme_supports('h5bp-htaccess')) {
add_action('generate_rewrite_rules', 'roots_add_h5bp_htaccess');
}

View File

@@ -22,7 +22,7 @@ function roots_setup() {
// add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));
// Tell the TinyMCE editor to use a custom stylesheet
add_editor_style('assets/css/editor-style.css');
add_editor_style('/assets/css/editor-style.css');
}

56
lib/rewrites.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
/**
* URL rewriting
*
* Rewrites currently do not happen for child themes (or network installs)
* @todo https://github.com/retlehs/roots/issues/461
*
* 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/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*
* @link https://github.com/retlehs/roots/blob/master/doc/rewrites.md
*/
function roots_add_rewrites($content) {
global $wp_rewrite;
$roots_new_non_wp_rules = array(
'assets/css/(.*)' => THEME_PATH . '/assets/css/$1',
'assets/js/(.*)' => THEME_PATH . '/assets/js/$1',
'assets/img/(.*)' => THEME_PATH . '/assets/img/$1',
'plugins/(.*)' => RELATIVE_PLUGIN_PATH . '/$1'
);
$wp_rewrite->non_wp_rules = array_merge($wp_rewrite->non_wp_rules, $roots_new_non_wp_rules);
return $content;
}
function roots_clean_urls($content) {
if (strpos($content, FULL_RELATIVE_PLUGIN_PATH) === 0) {
return str_replace(FULL_RELATIVE_PLUGIN_PATH, WP_BASE . '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
if (current_theme_supports('rewrites')) {
add_action('generate_rewrite_rules', 'roots_add_rewrites');
}
if (!is_admin() && current_theme_supports('rewrites')) {
$tags = array(
'plugins_url',
'bloginfo',
'stylesheet_directory_uri',
'template_directory_uri',
'script_loader_src',
'style_loader_src'
);
add_filters($tags, 'roots_clean_urls');
}
}

View File

@@ -6,26 +6,56 @@
* 1. /theme/assets/css/main.min.css
*
* Enqueue scripts in the following order:
* 1. /theme/assets/js/vendor/modernizr-2.6.2.min.js (in head.php)
* 2. jquery-1.9.0.min.js via Google CDN (in head.php)
* 3. /theme/assets/js/plugins.js
* 4. /theme/assets/js/main.js
* 1. /theme/assets/js/vendor/modernizr-2.6.2.min.js
* 2. jquery-1.9.0.min.js via Google CDN
* 3. /theme/assets/js/scripts.min.js
*/
function roots_scripts() {
wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.min.css', false, '78911fc28d7ea4e9571fa2f37ad1bfd2');
// Load style.css from child theme
if (is_child_theme()) {
wp_enqueue_style('roots_child', get_stylesheet_uri(), false, null);
}
// 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()) {
wp_deregister_script('jquery');
wp_register_script('jquery', '', '', '1.9.0', false);
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', array('modernizr'), null, false);
}
if (is_single() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, 'c40d165aabf0bf4734675f9fc726f3e6', true);
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, 'c40d165aabf0bf4734675f9fc726f3e6', false);
wp_enqueue_script('modernizr');
wp_enqueue_script('jquery');
wp_enqueue_script('roots_scripts');
}
add_action('wp_enqueue_scripts', 'roots_scripts', 100);
// http://wordpress.stackexchange.com/a/12450
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.9.0.min.js"><\/script>\')</script>' . "\n";
$add_jquery_fallback = false;
}
if ($handle === 'jquery') {
$add_jquery_fallback = true;
}
return $src;
}
if (!is_admin()) {
add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2);
}

View File

@@ -5,7 +5,56 @@
*
* @link http://scribu.net/wordpress/theme-wrappers.html
*/
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));
}
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));
}
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)) {
@@ -41,38 +90,18 @@ function roots_title() {
}
}
function roots_template_path() {
return Roots_Wrapping::$main_template;
}
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;
/**
* Show an admin notice if .htaccess isn't writable
*/
function roots_htaccess_writable() {
if (!is_writable(get_home_path() . '.htaccess')) {
if (current_user_can('administrator')) {
add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';"));
}
$templates = array('base.php');
if (self::$base) {
array_unshift($templates, sprintf('base-%s.php', self::$base ));
}
return locate_template($templates);
}
}
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);
add_action('admin_init', 'roots_htaccess_writable');
// returns WordPress subdirectory if applicable
function wp_base_dir() {

View File

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