get_theme();
if (empty($theme)) {
return $stylesheet;
}
$theme = get_theme($theme);
// Don't let people peek at unpublished themes.
if (isset($theme['Status']) && $theme['Status'] != 'publish')
return $template;
if (empty($theme)) {
return $stylesheet;
}
return $theme['Stylesheet'];
}
function get_template($template) {
$theme = $this->get_theme();
if (empty($theme)) {
return $template;
}
$theme = get_theme($theme);
if ( empty( $theme ) ) {
return $template;
}
// Don't let people peek at unpublished themes.
if (isset($theme['Status']) && $theme['Status'] != 'publish')
return $template;
return $theme['Template'];
}
function get_theme() {
if ( ! empty($_COOKIE["wptheme" . COOKIEHASH] ) ) {
return $_COOKIE["wptheme" . COOKIEHASH];
} else {
return '';
}
}
function set_theme_cookie() {
load_plugin_textdomain('theme-switcher');
$expire = time() + 30000000;
if ( ! empty($_GET["wptheme"] ) ) {
setcookie(
"wptheme" . COOKIEHASH,
stripslashes($_GET["wptheme"]),
$expire,
COOKIEPATH
);
$redirect = remove_query_arg('wptheme');
wp_redirect($redirect);
exit;
}
}
function theme_switcher_markup($style = "text", $instance = array()) {
if ( ! $theme_data = wp_cache_get('themes-data', 'theme-switcher') ) {
$themes = (array) get_themes();
if ( function_exists('is_site_admin') ) {
$allowed_themes = (array) get_site_option( 'allowedthemes' );
foreach( $themes as $key => $theme ) {
if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
unset( $themes[ $key ] );
}
}
}
$default_theme = get_current_theme();
$theme_data = array();
foreach ((array) $themes as $theme_name => $data) {
// Skip unpublished themes.
if (empty($theme_name) || isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish')
continue;
$theme_data[add_query_arg('wptheme', $theme_name, get_option('home'))] = $theme_name;
}
asort($theme_data);
wp_cache_set('themes-data', $theme_data, 'theme-switcher');
}
$ts = '';
if ( $style == 'dropdown' ) {
$ts .= '';
}
return $ts;
}
}
$theme_switcher = new ThemeSwitcher();
function wp_theme_switcher_dropdown() {
global $wp_admin_bar, $wpdb, $theme_switcher;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
/* Add the main siteadmin menu item */
$wp_admin_bar->add_menu( array( 'id' => 'switch_themes', 'title' => 'Switch Theme', 'href' => '#', 'meta' => array ( 'class' => 'themeswitchermenumain' ) ) );
$wp_admin_bar->add_menu( array( 'parent' => 'switch_themes', 'title' => $theme_switcher->theme_switcher_markup('dropdown'), 'href' => '#', 'meta' => array ( 'class' => 'themeswitchermenu' ) ) );
}
add_action( 'admin_bar_menu', 'wp_theme_switcher_dropdown', 1000 );
function themeswitcher_load_css()
{
wp_register_style("themeswitcher_style", WP_PLUGIN_URL."/theme-switcher/style.css");
wp_enqueue_style("themeswitcher_style",WP_PLUGIN_URL."/theme-switcher/style.css");
}
add_action('wp_print_styles', 'themeswitcher_load_css');