From 9ac6bc698ebce6b6f180b3827166848edfd2442b Mon Sep 17 00:00:00 2001 From: Scott Walkinshaw Date: Thu, 9 May 2013 17:04:26 -0400 Subject: [PATCH] Use SERVER_NAME to avoid parsing site_url() site_url() was previously retrieved and parsed many times per page before. This is cleaner and done for optimization purposes. --- lib/cleanup.php | 5 +---- lib/init.php | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/cleanup.php b/lib/cleanup.php index 3b50a70..a9f1833 100644 --- a/lib/cleanup.php +++ b/lib/cleanup.php @@ -138,12 +138,9 @@ add_filter('body_class', 'roots_body_class'); * @author Scott Walkinshaw */ function roots_root_relative_url($input) { - $parsed_url = parse_url(site_url()); - $site_domain = $parsed_url['host']; - preg_match('|https?://([^/]+)(/.*)|i', $input, $matches); - if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $site_domain) { + if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) { return wp_make_link_relative($input); } else { return $input; diff --git a/lib/init.php b/lib/init.php index 7084ac9..fb5cc59 100644 --- a/lib/init.php +++ b/lib/init.php @@ -30,7 +30,7 @@ if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); } // Define helper constants $get_theme_name = explode('/themes/', get_template_directory()); -define('THEME_NAME', next($get_theme_name)); -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); +define('THEME_NAME', next($get_theme_name)); +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);