Fix clean URL issues with non-standard setups
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
### HEAD
|
||||
* Fix issues with root relative URLs and rewrites on non-standard setups
|
||||
* Make sure rewrites are added to .htaccess immediately after activation
|
||||
* Move HTML5 Boilerplate's .htaccess to a [plugin](https://github.com/retlehs/wp-h5bp-htaccess)
|
||||
* Rename page-custom.php to template-custom.php
|
||||
|
||||
@@ -138,32 +138,7 @@ add_filter('body_class', 'roots_body_class');
|
||||
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
|
||||
*/
|
||||
function roots_root_relative_url($input) {
|
||||
// Fix for site_url() != home_url()
|
||||
if (!is_admin() && site_url() != home_url() && stristr($input, 'wp-includes') === false) {
|
||||
$input = str_replace(site_url(), '', $input);
|
||||
}
|
||||
|
||||
$output = preg_replace_callback(
|
||||
'!(https?://[^/|"]+)([^"]+)?!',
|
||||
create_function(
|
||||
'$matches',
|
||||
// If full URL is home_url("/") and this isn't a subdir install, return a slash for relative root
|
||||
'if (isset($matches[0]) && $matches[0] === home_url("/") && str_replace("http://", "", home_url("/", "http"))==$_SERVER["HTTP_HOST"]) { return "/";' .
|
||||
// If domain is equal to home_url("/"), then make URL relative
|
||||
'} elseif (isset($matches[0]) && strpos($matches[0], home_url("/")) !== false) { return $matches[2];' .
|
||||
// If domain is not equal to home_url("/"), do not make external link relative
|
||||
'} else { return $matches[0]; };'
|
||||
),
|
||||
$input
|
||||
);
|
||||
|
||||
// detect and correct for subdir installs
|
||||
if ($subdir = parse_url(home_url(), PHP_URL_PATH)) {
|
||||
if (substr($output, 0, strlen($subdir)) == (substr($output, strlen($subdir), strlen($subdir)))) {
|
||||
$output = substr($output, strlen($subdir));
|
||||
}
|
||||
}
|
||||
|
||||
$output = wp_make_link_relative($input);
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -174,10 +149,6 @@ function roots_enable_root_relative_urls() {
|
||||
if (roots_enable_root_relative_urls()) {
|
||||
$root_rel_filters = array(
|
||||
'bloginfo_url',
|
||||
'theme_root_uri',
|
||||
'stylesheet_directory_uri',
|
||||
'template_directory_uri',
|
||||
'plugins_url',
|
||||
'the_permalink',
|
||||
'wp_list_pages',
|
||||
'wp_list_categories',
|
||||
|
||||
@@ -30,9 +30,7 @@ if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); }
|
||||
// Define helper constants
|
||||
$get_theme_name = explode('/themes/', get_template_directory());
|
||||
|
||||
define('WP_BASE', wp_base_dir());
|
||||
define('THEME_NAME', next($get_theme_name));
|
||||
define('RELATIVE_PLUGIN_PATH', str_replace(site_url() . '/', '', plugins_url()));
|
||||
define('FULL_RELATIVE_PLUGIN_PATH', WP_BASE . '/' . RELATIVE_PLUGIN_PATH);
|
||||
define('RELATIVE_CONTENT_PATH', str_replace(site_url() . '/', '', content_url()));
|
||||
define('RELATIVE_PLUGIN_PATH', str_replace(home_url() . '/', '', plugins_url()));
|
||||
define('RELATIVE_CONTENT_PATH', str_replace(home_url() . '/', '', content_url()));
|
||||
define('THEME_PATH', RELATIVE_CONTENT_PATH . '/themes/' . THEME_NAME);
|
||||
|
||||
@@ -28,8 +28,8 @@ function roots_add_rewrites($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);
|
||||
if (strpos($content, RELATIVE_PLUGIN_PATH) > 0) {
|
||||
return str_replace('/' . RELATIVE_PLUGIN_PATH, '/plugins', $content);
|
||||
} else {
|
||||
return str_replace('/' . THEME_PATH, '', $content);
|
||||
}
|
||||
|
||||
@@ -85,29 +85,6 @@ function roots_title() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return WordPress subdirectory if applicable
|
||||
*/
|
||||
function wp_base_dir() {
|
||||
preg_match('!(https?://[^/|"]+)([^"]+)?!', site_url(), $matches);
|
||||
if (count($matches) === 3) {
|
||||
return end($matches);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opposite of built in WP functions for trailing slashes
|
||||
*/
|
||||
function leadingslashit($string) {
|
||||
return '/' . unleadingslashit($string);
|
||||
}
|
||||
|
||||
function unleadingslashit($string) {
|
||||
return ltrim($string, '/');
|
||||
}
|
||||
|
||||
function add_filters($tags, $function) {
|
||||
foreach($tags as $tag) {
|
||||
add_filter($tag, $function);
|
||||
|
||||
Reference in New Issue
Block a user