Created
January 24, 2014 22:31
-
-
Save franz-josef-kaiser/8608140 to your computer and use it in GitHub Desktop.
An external themes directory (above wp root folder) that runs on a separate domain. Best used as mu plugin for your development stack. Greatly simplifies local development. Props: Thomas "toscho" Scholz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Plugin Name: Local Theme Roots */ | |
/** | |
* Create a custom theme directory on a custom domain. | |
* Best used as mu plugin in a local development stack. | |
* | |
* @author Thomas Scholz | |
* @param string $root URL or path | |
* @return string | |
*/ | |
add_filter( 'theme_root_uri', 'switch_theme_root_local' ); | |
add_filter( 'theme_root', 'switch_theme_root_local' ); | |
function switch_theme_root_local( $root ) | |
{ | |
// local multi-sites end with '.dev'. Example: wprepo.vanilla-mu.dev | |
if ( 0 !== stripos( strrev( $_SERVER['HTTP_HOST'] ), 'ved.' ) ) | |
{ | |
return $root; | |
} | |
if ( 'theme_root_uri' === current_filter() ) | |
{ | |
remove_filter( current_filter(), __FUNCTION__ ); | |
return "http://themes.dev/"; | |
} | |
// If we made it so far we are in the 'theme_root' filter. | |
$new_root = trailingslashit( dirname( dirname( __DIR__ ) ) ).'themes.dev'; | |
# Too early to use register_theme_directory() | |
$GLOBALS['wp_theme_directories'][] = $new_root; | |
remove_filter( current_filter(), __FUNCTION__ ); | |
return $new_root; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment