Close #992 - Move some Roots features into Soil
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
// Captions
|
||||
.wp-caption {
|
||||
&:extend(.thumbnail all);
|
||||
}
|
||||
|
||||
// Gallery shortcode
|
||||
.gallery-row {
|
||||
padding: (@line-height-computed / 2) 0;
|
||||
@@ -12,6 +12,7 @@
|
||||
figure.alignnone {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: @screen-sm-min) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@import "_global"; // Base styling & custom mixins
|
||||
@import "components/_buttons"; // Button tweaks
|
||||
@import "components/_forms"; // Form tweaks
|
||||
@import "components/_gallery"; // WordPress galleries
|
||||
@import "components/_media"; // WordPress media
|
||||
@import "components/_wp-classes"; // WordPress generated classes
|
||||
@import "layouts/_general"; // General styling
|
||||
@import "layouts/_header"; // Header styling
|
||||
|
||||
@@ -9,11 +9,8 @@ require_once locate_template('/lib/sidebar.php'); // Sidebar class
|
||||
require_once locate_template('/lib/config.php'); // Configuration
|
||||
require_once locate_template('/lib/activation.php'); // Theme activation
|
||||
require_once locate_template('/lib/titles.php'); // Page titles
|
||||
require_once locate_template('/lib/cleanup.php'); // Cleanup
|
||||
require_once locate_template('/lib/nav.php'); // Custom nav modifications
|
||||
require_once locate_template('/lib/gallery.php'); // Custom [gallery] modifications
|
||||
require_once locate_template('/lib/comments.php'); // Custom comments modifications
|
||||
require_once locate_template('/lib/relative-urls.php'); // Root relative URLs
|
||||
require_once locate_template('/lib/widgets.php'); // Sidebars and widgets
|
||||
require_once locate_template('/lib/scripts.php'); // Scripts and stylesheets
|
||||
require_once locate_template('/lib/custom.php'); // Custom functions
|
||||
|
||||
261
lib/cleanup.php
261
lib/cleanup.php
@@ -1,261 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Clean up wp_head()
|
||||
*
|
||||
* Remove unnecessary <link>'s
|
||||
* Remove inline CSS used by Recent Comments widget
|
||||
* Remove inline CSS used by posts with galleries
|
||||
* Remove self-closing tag and change ''s to "'s on rel_canonical()
|
||||
*/
|
||||
function roots_head_cleanup() {
|
||||
// Originally from http://wpengineer.com/1438/wordpress-header/
|
||||
remove_action('wp_head', 'feed_links', 2);
|
||||
remove_action('wp_head', 'feed_links_extra', 3);
|
||||
remove_action('wp_head', 'rsd_link');
|
||||
remove_action('wp_head', 'wlwmanifest_link');
|
||||
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
|
||||
remove_action('wp_head', 'wp_generator');
|
||||
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
|
||||
|
||||
global $wp_widget_factory;
|
||||
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
|
||||
|
||||
if (!class_exists('WPSEO_Frontend')) {
|
||||
remove_action('wp_head', 'rel_canonical');
|
||||
add_action('wp_head', 'roots_rel_canonical');
|
||||
}
|
||||
}
|
||||
|
||||
function roots_rel_canonical() {
|
||||
global $wp_the_query;
|
||||
|
||||
if (!is_singular()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$id = $wp_the_query->get_queried_object_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$link = get_permalink($id);
|
||||
echo "\t<link rel=\"canonical\" href=\"$link\">\n";
|
||||
}
|
||||
add_action('init', 'roots_head_cleanup');
|
||||
|
||||
/**
|
||||
* Remove the WordPress version from RSS feeds
|
||||
*/
|
||||
add_filter('the_generator', '__return_false');
|
||||
|
||||
/**
|
||||
* Clean up language_attributes() used in <html> tag
|
||||
*
|
||||
* Remove dir="ltr"
|
||||
*/
|
||||
function roots_language_attributes() {
|
||||
$attributes = array();
|
||||
$output = '';
|
||||
|
||||
if (is_rtl()) {
|
||||
$attributes[] = 'dir="rtl"';
|
||||
}
|
||||
|
||||
$lang = get_bloginfo('language');
|
||||
|
||||
if ($lang) {
|
||||
$attributes[] = "lang=\"$lang\"";
|
||||
}
|
||||
|
||||
$output = implode(' ', $attributes);
|
||||
$output = apply_filters('roots_language_attributes', $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
add_filter('language_attributes', 'roots_language_attributes');
|
||||
|
||||
/**
|
||||
* Manage output of wp_title()
|
||||
*/
|
||||
function roots_wp_title($title) {
|
||||
if (is_feed()) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$title .= get_bloginfo('name');
|
||||
|
||||
return $title;
|
||||
}
|
||||
add_filter('wp_title', 'roots_wp_title', 10);
|
||||
|
||||
/**
|
||||
* Clean up output of stylesheet <link> tags
|
||||
*/
|
||||
function roots_clean_style_tag($input) {
|
||||
preg_match_all("!<link rel='stylesheet'\s?(id='[^']+')?\s+href='(.*)' type='text/css' media='(.*)' />!", $input, $matches);
|
||||
// Only display media if it is meaningful
|
||||
$media = $matches[3][0] !== '' && $matches[3][0] !== 'all' ? ' media="' . $matches[3][0] . '"' : '';
|
||||
return '<link rel="stylesheet" href="' . $matches[2][0] . '"' . $media . '>' . "\n";
|
||||
}
|
||||
add_filter('style_loader_tag', 'roots_clean_style_tag');
|
||||
|
||||
/**
|
||||
* Add and remove body_class() classes
|
||||
*/
|
||||
function roots_body_class($classes) {
|
||||
// Add post/page slug
|
||||
if (is_single() || is_page() && !is_front_page()) {
|
||||
$classes[] = basename(get_permalink());
|
||||
}
|
||||
|
||||
// Remove unnecessary classes
|
||||
$home_id_class = 'page-id-' . get_option('page_on_front');
|
||||
$remove_classes = array(
|
||||
'page-template-default',
|
||||
$home_id_class
|
||||
);
|
||||
$classes = array_diff($classes, $remove_classes);
|
||||
|
||||
return $classes;
|
||||
}
|
||||
add_filter('body_class', 'roots_body_class');
|
||||
|
||||
/**
|
||||
* Wrap embedded media as suggested by Readability
|
||||
*
|
||||
* @link https://gist.github.com/965956
|
||||
* @link http://www.readability.com/publishers/guidelines#publisher
|
||||
*/
|
||||
function roots_embed_wrap($cache, $url, $attr = '', $post_ID = '') {
|
||||
return '<div class="entry-content-asset">' . $cache . '</div>';
|
||||
}
|
||||
add_filter('embed_oembed_html', 'roots_embed_wrap', 10, 4);
|
||||
|
||||
/**
|
||||
* Add Bootstrap thumbnail styling to images with captions
|
||||
* Use <figure> and <figcaption>
|
||||
*
|
||||
* @link http://justintadlock.com/archives/2011/07/01/captions-in-wordpress
|
||||
*/
|
||||
function roots_caption($output, $attr, $content) {
|
||||
if (is_feed()) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'id' => '',
|
||||
'align' => 'alignnone',
|
||||
'width' => '',
|
||||
'caption' => ''
|
||||
);
|
||||
|
||||
$attr = shortcode_atts($defaults, $attr);
|
||||
|
||||
// If the width is less than 1 or there is no caption, return the content wrapped between the [caption] tags
|
||||
if ($attr['width'] < 1 || empty($attr['caption'])) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Set up the attributes for the caption <figure>
|
||||
$attributes = (!empty($attr['id']) ? ' id="' . esc_attr($attr['id']) . '"' : '' );
|
||||
$attributes .= ' class="thumbnail wp-caption ' . esc_attr($attr['align']) . '"';
|
||||
$attributes .= ' style="width: ' . (esc_attr($attr['width']) + 10) . 'px"';
|
||||
|
||||
$output = '<figure' . $attributes .'>';
|
||||
$output .= do_shortcode($content);
|
||||
$output .= '<figcaption class="caption wp-caption-text">' . $attr['caption'] . '</figcaption>';
|
||||
$output .= '</figure>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
add_filter('img_caption_shortcode', 'roots_caption', 10, 3);
|
||||
|
||||
/**
|
||||
* Remove unnecessary dashboard widgets
|
||||
*
|
||||
* @link http://www.deluxeblogtips.com/2011/01/remove-dashboard-widgets-in-wordpress.html
|
||||
*/
|
||||
function roots_remove_dashboard_widgets() {
|
||||
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
|
||||
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
|
||||
remove_meta_box('dashboard_primary', 'dashboard', 'normal');
|
||||
remove_meta_box('dashboard_secondary', 'dashboard', 'normal');
|
||||
}
|
||||
add_action('admin_init', 'roots_remove_dashboard_widgets');
|
||||
|
||||
/**
|
||||
* Clean up the_excerpt()
|
||||
*/
|
||||
function roots_excerpt_length($length) {
|
||||
return POST_EXCERPT_LENGTH;
|
||||
}
|
||||
|
||||
function roots_excerpt_more($more) {
|
||||
return ' … <a href="' . get_permalink() . '">' . __('Continued', 'roots') . '</a>';
|
||||
}
|
||||
add_filter('excerpt_length', 'roots_excerpt_length');
|
||||
add_filter('excerpt_more', 'roots_excerpt_more');
|
||||
|
||||
/**
|
||||
* Remove unnecessary self-closing tags
|
||||
*/
|
||||
function roots_remove_self_closing_tags($input) {
|
||||
return str_replace(' />', '>', $input);
|
||||
}
|
||||
add_filter('get_avatar', 'roots_remove_self_closing_tags'); // <img />
|
||||
add_filter('comment_id_fields', 'roots_remove_self_closing_tags'); // <input />
|
||||
add_filter('post_thumbnail_html', 'roots_remove_self_closing_tags'); // <img />
|
||||
|
||||
/**
|
||||
* Don't return the default description in the RSS feed if it hasn't been changed
|
||||
*/
|
||||
function roots_remove_default_description($bloginfo) {
|
||||
$default_tagline = 'Just another WordPress site';
|
||||
return ($bloginfo === $default_tagline) ? '' : $bloginfo;
|
||||
}
|
||||
add_filter('get_bloginfo_rss', 'roots_remove_default_description');
|
||||
|
||||
/**
|
||||
* Redirects search results from /?s=query to /search/query/, converts %20 to +
|
||||
*
|
||||
* @link http://txfx.net/wordpress-plugins/nice-search/
|
||||
*/
|
||||
function roots_nice_search_redirect() {
|
||||
global $wp_rewrite;
|
||||
if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$search_base = $wp_rewrite->search_base;
|
||||
if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
|
||||
wp_redirect(home_url("/{$search_base}/" . urlencode(get_query_var('s'))));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
if (current_theme_supports('nice-search')) {
|
||||
add_action('template_redirect', 'roots_nice_search_redirect');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix for empty search queries redirecting to home page
|
||||
*
|
||||
* @link http://wordpress.org/support/topic/blank-search-sends-you-to-the-homepage#post-1772565
|
||||
* @link http://core.trac.wordpress.org/ticket/11330
|
||||
*/
|
||||
function roots_request_filter($query_vars) {
|
||||
if (isset($_GET['s']) && empty($_GET['s'])) {
|
||||
$query_vars['s'] = ' ';
|
||||
}
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter('request', 'roots_request_filter');
|
||||
|
||||
/**
|
||||
* Tell WordPress to use searchform.php from the templates/ directory
|
||||
*/
|
||||
function roots_get_search_form($form) {
|
||||
$form = '';
|
||||
locate_template('/templates/searchform.php', true, false);
|
||||
return $form;
|
||||
}
|
||||
add_filter('get_search_form', 'roots_get_search_form');
|
||||
@@ -2,17 +2,17 @@
|
||||
/**
|
||||
* Enable theme features
|
||||
*/
|
||||
add_theme_support('root-relative-urls'); // Enable relative URLs
|
||||
add_theme_support('soil-clean-up'); // Enable clean up from Soil
|
||||
add_theme_support('soil-relative-urls'); // Enable relative URLs from Soil
|
||||
add_theme_support('soil-nice-search'); // Enable /?s= to /search/ redirect from Soil
|
||||
add_theme_support('bootstrap-top-navbar'); // Enable Bootstrap's top navbar
|
||||
add_theme_support('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
|
||||
add_theme_support('nice-search'); // Enable /?s= to /search/ redirect
|
||||
add_theme_support('jquery-cdn'); // Enable to load jQuery from the Google CDN
|
||||
|
||||
/**
|
||||
* Configuration values
|
||||
*/
|
||||
define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y (Note: Universal Analytics only, not Classic Analytics)
|
||||
define('POST_EXCERPT_LENGTH', 40); // Length in words for excerpt_length filter (http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_length)
|
||||
|
||||
/**
|
||||
* .main classes
|
||||
|
||||
24
lib/init.php
24
lib/init.php
@@ -23,3 +23,27 @@ function roots_setup() {
|
||||
add_editor_style('/assets/css/editor-style.css');
|
||||
}
|
||||
add_action('after_setup_theme', 'roots_setup');
|
||||
|
||||
/**
|
||||
* Register sidebars
|
||||
*/
|
||||
function roots_widgets_init() {
|
||||
register_sidebar(array(
|
||||
'name' => __('Primary', 'roots'),
|
||||
'id' => 'sidebar-primary',
|
||||
'before_widget' => '<section class="widget %1$s %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3>',
|
||||
'after_title' => '</h3>',
|
||||
));
|
||||
|
||||
register_sidebar(array(
|
||||
'name' => __('Footer', 'roots'),
|
||||
'id' => 'sidebar-footer',
|
||||
'before_widget' => '<section class="widget %1$s %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3>',
|
||||
'after_title' => '</h3>',
|
||||
));
|
||||
}
|
||||
add_action('widgets_init', 'roots_widgets_init');
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?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])) {
|
||||
return $input;
|
||||
} elseif (($matches[1] === $_SERVER['SERVER_NAME']) || $matches[1] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) {
|
||||
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');
|
||||
}
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Utility functions
|
||||
*/
|
||||
function add_filters($tags, $function) {
|
||||
foreach($tags as $tag) {
|
||||
add_filter($tag, $function);
|
||||
}
|
||||
}
|
||||
|
||||
function is_element_empty($element) {
|
||||
$element = trim($element);
|
||||
return empty($element) ? false : true;
|
||||
}
|
||||
|
||||
// Tell WordPress to use searchform.php from the templates/ directory
|
||||
function roots_get_search_form($form) {
|
||||
$form = '';
|
||||
locate_template('/templates/searchform.php', true, false);
|
||||
return $form;
|
||||
}
|
||||
add_filter('get_search_form', 'roots_get_search_form');
|
||||
|
||||
133
lib/widgets.php
133
lib/widgets.php
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Register sidebars and widgets
|
||||
*/
|
||||
function roots_widgets_init() {
|
||||
// Sidebars
|
||||
register_sidebar(array(
|
||||
'name' => __('Primary', 'roots'),
|
||||
'id' => 'sidebar-primary',
|
||||
'before_widget' => '<section class="widget %1$s %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3>',
|
||||
'after_title' => '</h3>',
|
||||
));
|
||||
|
||||
register_sidebar(array(
|
||||
'name' => __('Footer', 'roots'),
|
||||
'id' => 'sidebar-footer',
|
||||
'before_widget' => '<section class="widget %1$s %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3>',
|
||||
'after_title' => '</h3>',
|
||||
));
|
||||
|
||||
// Widgets
|
||||
register_widget('Roots_Vcard_Widget');
|
||||
}
|
||||
add_action('widgets_init', 'roots_widgets_init');
|
||||
|
||||
/**
|
||||
* Example vCard widget
|
||||
*/
|
||||
class Roots_Vcard_Widget extends WP_Widget {
|
||||
private $fields = array(
|
||||
'title' => 'Title (optional)',
|
||||
'street_address' => 'Street Address',
|
||||
'locality' => 'City/Locality',
|
||||
'region' => 'State/Region',
|
||||
'postal_code' => 'Zipcode/Postal Code',
|
||||
'tel' => 'Telephone',
|
||||
'email' => 'Email'
|
||||
);
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_roots_vcard', 'description' => __('Use this widget to add a vCard', 'roots'));
|
||||
|
||||
$this->WP_Widget('widget_roots_vcard', __('Roots: vCard', 'roots'), $widget_ops);
|
||||
$this->alt_option_name = 'widget_roots_vcard';
|
||||
|
||||
add_action('save_post', array(&$this, 'flush_widget_cache'));
|
||||
add_action('deleted_post', array(&$this, 'flush_widget_cache'));
|
||||
add_action('switch_theme', array(&$this, 'flush_widget_cache'));
|
||||
}
|
||||
|
||||
function widget($args, $instance) {
|
||||
$cache = wp_cache_get('widget_roots_vcard', 'widget');
|
||||
|
||||
if (!is_array($cache)) {
|
||||
$cache = array();
|
||||
}
|
||||
|
||||
if (!isset($args['widget_id'])) {
|
||||
$args['widget_id'] = null;
|
||||
}
|
||||
|
||||
if (isset($cache[$args['widget_id']])) {
|
||||
echo $cache[$args['widget_id']];
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? __('vCard', 'roots') : $instance['title'], $instance, $this->id_base);
|
||||
|
||||
foreach($this->fields as $name => $label) {
|
||||
if (!isset($instance[$name])) { $instance[$name] = ''; }
|
||||
}
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ($title) {
|
||||
echo $before_title, $title, $after_title;
|
||||
}
|
||||
?>
|
||||
<p class="vcard">
|
||||
<a class="fn org url" href="<?php echo home_url('/'); ?>"><?php bloginfo('name'); ?></a><br>
|
||||
<span class="adr">
|
||||
<span class="street-address"><?php echo $instance['street_address']; ?></span><br>
|
||||
<span class="locality"><?php echo $instance['locality']; ?></span>,
|
||||
<span class="region"><?php echo $instance['region']; ?></span>
|
||||
<span class="postal-code"><?php echo $instance['postal_code']; ?></span><br>
|
||||
</span>
|
||||
<span class="tel"><span class="value"><?php echo $instance['tel']; ?></span></span><br>
|
||||
<a class="email" href="mailto:<?php echo $instance['email']; ?>"><?php echo $instance['email']; ?></a>
|
||||
</p>
|
||||
<?php
|
||||
echo $after_widget;
|
||||
|
||||
$cache[$args['widget_id']] = ob_get_flush();
|
||||
wp_cache_set('widget_roots_vcard', $cache, 'widget');
|
||||
}
|
||||
|
||||
function update($new_instance, $old_instance) {
|
||||
$instance = array_map('strip_tags', $new_instance);
|
||||
|
||||
$this->flush_widget_cache();
|
||||
|
||||
$alloptions = wp_cache_get('alloptions', 'options');
|
||||
|
||||
if (isset($alloptions['widget_roots_vcard'])) {
|
||||
delete_option('widget_roots_vcard');
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function flush_widget_cache() {
|
||||
wp_cache_delete('widget_roots_vcard', 'widget');
|
||||
}
|
||||
|
||||
function form($instance) {
|
||||
foreach($this->fields as $name => $label) {
|
||||
${$name} = isset($instance[$name]) ? esc_attr($instance[$name]) : '';
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id($name)); ?>"><?php _e("{$label}:", 'roots'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id($name)); ?>" name="<?php echo esc_attr($this->get_field_name($name)); ?>" type="text" value="<?php echo ${$name}; ?>">
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user