Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from roots/new
Browse files Browse the repository at this point in the history
New Soil
  • Loading branch information
retlehs committed Apr 1, 2014
2 parents 4bad41d + 0ca4d3c commit 2247e2b
Show file tree
Hide file tree
Showing 23 changed files with 381 additions and 253 deletions.
24 changes: 0 additions & 24 deletions .gitmodules

This file was deleted.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
### 3.0.0: March 31st, 2014
* Rewrite, Soil is now a plugin with functionality migrated out of the Roots starter theme: clean-up, relative URLs, nice search. Take a look at [Bedrock](https://github.com/roots/bedrock) if you like the ideas from the old Soil, and use Composer to manage plugins on your WP installation.

### 2.0.0: November 1st, 2012
* Add base mu-plugin for all site specific functionality (custom post types, taxonomies, meta boxes, shortcodes)
* Update all plugins
* Remove SLD Custom Content and Taxonomies

### 1.0.0: July 30th, 2012
* Initial commit
* Initial commit
19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Roots

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# Soil

Soil contains plugins that I use on every new WordPress project (except for [Gravity Forms](http://www.rootstheme.com/gravityforms/)) along with [Roots](http://www.rootstheme.com/).
## Features

There's also a mu-plugin for site specific functionality (custom post types, taxonomies, meta boxes, shortcodes, and examples of each are included).
### Clean-up

Take a look at [Jump Start Your WordPress Site Development with Soil](http://benword.com/jump-start-your-wordpress-site-development-with-soil/).
Enable Soil's clean-up with:

## Installation
```php
add_theme_support('soil-clean-up');
```

* Clone the git repo
* Run `git submodule update --init --recursive`
* `wp_head()` clean up
* Remove WP version from RSS feeds
* Clean up `<html>` attributes
* Clean up `<link>` tags
* Clean up `body_class()`
* Wrap embedded media as suggested by Readability
* Use `<figure>` and `<figcaption>` for WP captions
* Remove unnecessary dashboard widgets
* Remove unnecessary self-closing tags

## Must Use Plugins (mu-plugins)
### Relative URLs

* [Options Framework Plugin](https://github.com/devinsays/options-framework-plugin)
* [Custom Metaboxes and Fields](https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/)
* [CF Post Formats](https://github.com/crowdfavorite/wp-post-formats)
* **Base** — Site specific functionality (custom post types, taxonomies, meta boxes, shortcodes)
Enable Soil's root relative URLs with:

## Plugins
```php
add_theme_support('soil-relative-urls');
```

* [WordPress SEO](http://wordpress.org/extend/plugins/wordpress-seo/)
* [W3 Total Cache](http://wordpress.org/extend/plugins/w3-total-cache/)
* [Query Multiple Taxonomies](https://github.com/scribu/wp-query-multiple-taxonomies)
* [Front-end Editor](https://github.com/scribu/wp-front-end-editor)
### Nice search

## Themes
Enable Soil's nice search (`/search/query/`) with:

* [Roots](http://www.rootstheme.com/)
```php
add_theme_support('soil-nice-search');
```
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "roots/soil",
"type": "wordpress-plugin",
"license": "MIT",
"description": "Clean up WordPress markup, relative URLs, nice search",
"homepage": "http://roots.io/plugins/soil/",
"authors": [
{
"name": "Ben Word",
"email": "ben@benword.com",
"homepage": "https://github.com/retlehs"
},
{
"name": "Scott Walkinshaw",
"email": "scott.walkinshaw@gmail.com",
"homepage": "https://github.com/swalkinshaw"
}
],
"keywords": [
"wordpress"
],
"support": {
"issues": "https://github.com/roots/soil/issues",
"forum": "http://discourse.roots.io/"
},
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0"
}
}
202 changes: 202 additions & 0 deletions modules/clean-up.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?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 soil_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', 'soil_rel_canonical');
}
}

function soil_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', 'soil_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 soil_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('soil/language_attributes', $output);

return $output;
}
add_filter('language_attributes', 'soil_language_attributes');

/**
* Clean up output of stylesheet <link> tags
*/
function soil_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', 'soil_clean_style_tag');

/**
* Add and remove body_class() classes
*/
function soil_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', 'soil_body_class');

/**
* Wrap embedded media as suggested by Readability
*
* @link https://gist.github.com/965956
* @link http://www.readability.com/publishers/guidelines#publisher
*/
function soil_embed_wrap($cache, $url, $attr = '', $post_ID = '') {
return '<div class="entry-content-asset">' . $cache . '</div>';
}
add_filter('embed_oembed_html', 'soil_embed_wrap', 10, 4);

/**
* Use <figure> and <figcaption> for captions
*
* @link http://justintadlock.com/archives/2011/07/01/captions-in-wordpress
*/
function soil_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="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', 'soil_caption', 10, 3);

/**
* Remove unnecessary dashboard widgets
*
* @link http://www.deluxeblogtips.com/2011/01/remove-dashboard-widgets-in-wordpress.html
*/
function soil_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', 'soil_remove_dashboard_widgets');

/**
* Remove unnecessary self-closing tags
*/
function soil_remove_self_closing_tags($input) {
return str_replace(' />', '>', $input);
}
add_filter('get_avatar', 'soil_remove_self_closing_tags'); // <img />
add_filter('comment_id_fields', 'soil_remove_self_closing_tags'); // <input />
add_filter('post_thumbnail_html', 'soil_remove_self_closing_tags'); // <img />

/**
* Don't return the default description in the RSS feed if it hasn't been changed
*/
function soil_remove_default_description($bloginfo) {
$default_tagline = 'Just another WordPress site';
return ($bloginfo === $default_tagline) ? '' : $bloginfo;
}
add_filter('get_bloginfo_rss', 'soil_remove_default_description');

/**
* 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 soil_request_filter($query_vars) {
if (isset($_GET['s']) && empty($_GET['s']) && !is_admin()) {
$query_vars['s'] = ' ';
}

return $query_vars;
}
add_filter('request', 'soil_request_filter');
19 changes: 19 additions & 0 deletions modules/nice-search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Redirects search results from /?s=query to /search/query/, converts %20 to +
*
* @link http://txfx.net/wordpress-plugins/nice-search/
*/
function soil_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();
}
}
add_action('template_redirect', 'soil_nice_search_redirect');
Loading

0 comments on commit 2247e2b

Please sign in to comment.