closes #104 - adding a theme option for root relative URLs (enabled by default)
This commit is contained in:
@@ -44,23 +44,24 @@ function roots_root_relative_url($input) {
|
||||
// Terrible workaround to remove the duplicate subfolder in the src of JS/CSS tags
|
||||
// Example: /subfolder/subfolder/css/style.css
|
||||
function roots_fix_duplicate_subfolder_urls($input) {
|
||||
$output = roots_root_relative_url($input);
|
||||
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
|
||||
if (isset($matches[1]) && isset($matches[2])) {
|
||||
if ($matches[1][0] === $matches[2][0]) {
|
||||
$output = substr($output, strlen($matches[1][0]) + 1);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
$output = roots_root_relative_url($input);
|
||||
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
|
||||
if (isset($matches[1]) && isset($matches[2])) {
|
||||
if ($matches[1][0] === $matches[2][0]) {
|
||||
$output = substr($output, strlen($matches[1][0]) + 1);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (!is_admin()) {
|
||||
$roots_options = roots_get_theme_options();
|
||||
if (!is_admin() && $roots_options['root_relative_urls']) {
|
||||
add_filter('bloginfo_url', 'roots_root_relative_url');
|
||||
add_filter('theme_root_uri', 'roots_root_relative_url');
|
||||
add_filter('stylesheet_directory_uri', 'roots_root_relative_url');
|
||||
add_filter('template_directory_uri', 'roots_root_relative_url');
|
||||
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('plugins_url', 'roots_root_relative_url');
|
||||
add_filter('the_permalink', 'roots_root_relative_url');
|
||||
add_filter('wp_list_pages', 'roots_root_relative_url');
|
||||
|
||||
@@ -150,6 +150,7 @@ function roots_get_default_theme_options() {
|
||||
'main_class' => $default_framework_settings['classes']['main'],
|
||||
'sidebar_class' => $default_framework_settings['classes']['sidebar'],
|
||||
'google_analytics_id' => '',
|
||||
'root_relative_urls' => true,
|
||||
'clean_menu' => true,
|
||||
'fout_b_gone' => false
|
||||
);
|
||||
@@ -218,7 +219,18 @@ function roots_theme_options_render_page() {
|
||||
<small class="description"><?php printf(__('Enter your UA-XXXXX-X ID', 'roots')); ?></small>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<tr valign="top"><th scope="row"><?php _e('Enable Root Relative URLs', 'roots'); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php _e('Enable Root Relative URLs', 'roots'); ?></span></legend>
|
||||
<select name="roots_theme_options[root_relative_urls]" id="roots_theme_options[root_relative_urls]">
|
||||
<option value="yes" <?php selected($roots_options['root_relative_urls'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
|
||||
<option value="no" <?php selected($roots_options['root_relative_urls'], false); ?>><?php echo _e('No', 'roots'); ?></option>
|
||||
</select>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top"><th scope="row"><?php _e('Cleanup Menu Output', 'roots'); ?></th>
|
||||
<td>
|
||||
@@ -270,6 +282,9 @@ function roots_theme_options_validate($input) {
|
||||
if (isset($input['google_analytics_id']))
|
||||
$output['google_analytics_id'] = $input['google_analytics_id'];
|
||||
|
||||
if (isset($input['root_relative_urls']))
|
||||
$output['root_relative_urls'] = ($input['root_relative_urls'] === 'yes') ? true : false;
|
||||
|
||||
if (isset($input['clean_menu']))
|
||||
$output['clean_menu'] = ($input['clean_menu'] === 'yes') ? true : false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user