Merge pull request #912 from roots/move-rewrites-to-plugin

Move rewrites to a plugin, Roots 6.5.1
This commit is contained in:
Ben Word
2013-11-05 13:13:36 -08:00
11 changed files with 10 additions and 84 deletions

View File

@@ -1,4 +1,5 @@
### HEAD ### 6.5.1: November 5th, 2013
* Move clean URLs to a [plugin](https://github.com/roots/roots-rewrites)
* Update to Bootstrap 3.0.1 * Update to Bootstrap 3.0.1
### 6.5.0: August 23rd, 2013 ### 6.5.0: August 23rd, 2013

View File

@@ -16,17 +16,6 @@ Clone the git repo - `git clone git://github.com/roots/roots.git` - or [download
npm install npm install
``` ```
If you're using Nginx you'll need to add the Roots rewrites to your server config before the PHP block (`location ~ \.php$`) to use the clean URLs feature:
```nginx
location ~ ^/assets/(img|js|css|fonts)/(.*)$ {
try_files $uri $uri/ /wp-content/themes/roots/assets/$1/$2;
}
location ~ ^/plugins/(.*)$ {
try_files $uri $uri/ /wp-content/plugins/$1;
}
```
Reference the [theme activation](http://roots.io/roots-101/#theme-activation) documentation to understand everything that happens once you activate Roots. Reference the [theme activation](http://roots.io/roots-101/#theme-activation) documentation to understand everything that happens once you activate Roots.
## Theme Development ## Theme Development
@@ -57,7 +46,7 @@ Edit `lib/init.php` to setup custom navigation menus and post thumbnail sizes.
* [Theme activation](http://roots.io/roots-101/#theme-activation) * [Theme activation](http://roots.io/roots-101/#theme-activation)
* [Theme wrapper](http://roots.io/an-introduction-to-the-roots-theme-wrapper/) * [Theme wrapper](http://roots.io/an-introduction-to-the-roots-theme-wrapper/)
* Root relative URLs * Root relative URLs
* Clean URLs (no more `/wp-content/`) * [Clean URLs with a plugin](https://github.com/roots/roots-rewrites) (no more `/wp-content/`)
* All static theme assets are rewritten to the website root (`/assets/*`) * All static theme assets are rewritten to the website root (`/assets/*`)
* Cleaner HTML output of navigation menus * Cleaner HTML output of navigation menus
* Cleaner output of `wp_head` and enqueued scripts/styles * Cleaner output of `wp_head` and enqueued scripts/styles

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
/*! /*!
* Roots 6.5.0 * Roots 6.5.1
*/ */
@import "bootstrap/bootstrap.less"; @import "bootstrap/bootstrap.less";

View File

@@ -13,7 +13,6 @@ require_once locate_template('/lib/cleanup.php'); // Cleanup
require_once locate_template('/lib/nav.php'); // Custom nav modifications 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/gallery.php'); // Custom [gallery] modifications
require_once locate_template('/lib/comments.php'); // Custom comments modifications require_once locate_template('/lib/comments.php'); // Custom comments modifications
require_once locate_template('/lib/rewrites.php'); // URL rewriting for assets
require_once locate_template('/lib/relative-urls.php'); // Root relative URLs 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/widgets.php'); // Sidebars and widgets
require_once locate_template('/lib/scripts.php'); // Scripts and stylesheets require_once locate_template('/lib/scripts.php'); // Scripts and stylesheets

View File

@@ -3,7 +3,6 @@
* Enable theme features * Enable theme features
*/ */
add_theme_support('root-relative-urls'); // Enable relative URLs add_theme_support('root-relative-urls'); // Enable relative URLs
add_theme_support('rewrites'); // Enable URL rewrites
add_theme_support('bootstrap-top-navbar'); // Enable Bootstrap's top navbar 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('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
add_theme_support('nice-search'); // Enable /?s= to /search/ redirect add_theme_support('nice-search'); // Enable /?s= to /search/ redirect
@@ -78,13 +77,3 @@ function roots_display_sidebar() {
* Default: 1140px is the default Bootstrap container width. * Default: 1140px is the default Bootstrap container width.
*/ */
if (!isset($content_width)) { $content_width = 1140; } if (!isset($content_width)) { $content_width = 1140; }
/**
* 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

@@ -1,52 +0,0 @@
<?php
/**
* URL rewriting
*
* Rewrites do not happen for multisite installations or child themes
*
* Rewrite:
* /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.
*
*
*/
function roots_add_rewrites($content) {
global $wp_rewrite;
$roots_new_non_wp_rules = array(
'assets/(.*)' => THEME_PATH . '/assets/$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, RELATIVE_PLUGIN_PATH) > 0) {
return str_replace('/' . RELATIVE_PLUGIN_PATH, '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme()) {
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

@@ -11,7 +11,7 @@
* 3. /theme/assets/js/main.min.js (in footer) * 3. /theme/assets/js/main.min.js (in footer)
*/ */
function roots_scripts() { function roots_scripts() {
wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.min.css', false, '9a2dd99b82ca338b034e8730b94139d2'); wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.min.css', false, 'eb6334a114ec5f4f5c96dff76170aade');
// jQuery is loaded using the same method from HTML5 Boilerplate: // 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 // Grab Google CDN's latest jQuery with a protocol relative URL; fallback to local if offline
@@ -27,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('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, '2a3e700c4c6e3d70a95b00241a845695', true); wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, 'e976bc66a7d279f3d265efbe1e0e14fb', true);
wp_enqueue_script('modernizr'); wp_enqueue_script('modernizr');
wp_enqueue_script('jquery'); wp_enqueue_script('jquery');
wp_enqueue_script('roots_scripts'); wp_enqueue_script('roots_scripts');

View File

@@ -1,6 +1,6 @@
{ {
"name": "roots", "name": "roots",
"version": "6.5.0", "version": "6.5.1",
"author": "Ben Word <ben@benword.com>", "author": "Ben Word <ben@benword.com>",
"homepage": "http://roots.io", "homepage": "http://roots.io",
"repository": { "repository": {

View File

@@ -2,7 +2,7 @@
Theme Name: Roots Theme Name: Roots
Theme URI: http://roots.io/ Theme URI: http://roots.io/
Description: Roots is a starting WordPress theme made for developers that's based on HTML5 Boilerplate and Bootstrap. <a href="https://github.com/retlehs/roots/contributors">Contribute on GitHub</a> Description: Roots is a starting WordPress theme made for developers that's based on HTML5 Boilerplate and Bootstrap. <a href="https://github.com/retlehs/roots/contributors">Contribute on GitHub</a>
Version: 6.5.0 Version: 6.5.1
Author: Ben Word Author: Ben Word
Author URI: http://benword.com/ Author URI: http://benword.com/