// and Ryan Boren , // as well as the Google Search widget code by Automattic. // Widgetized by Ben de Groot . // You can redistribute this software and/or modify it under the terms of // the GNU General Public License as published by the Free Software Foundation; // either version 2 of the License, or (at your option) any later version. // // // PLUGIN CODE // // // function ts_set_theme_cookie() { $expire = time() + 30000000; if (!empty($_GET["wptheme"])) { setcookie("wptheme" . COOKIEHASH, stripslashes($_GET["wptheme"]), $expire, COOKIEPATH ); $redirect = get_settings('home').'/'; if (function_exists('wp_redirect')) wp_redirect($redirect); else header("Location: ". $redirect); exit; } } function ts_get_theme() { if (!empty($_COOKIE["wptheme" . COOKIEHASH])) { return $_COOKIE["wptheme" . COOKIEHASH]; } else { return ''; } } function ts_get_template($template) { $theme = ts_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 ts_get_stylesheet($stylesheet) { $theme = ts_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 wp_theme_switcher($style = "text") { $themes = get_themes(); $default_theme = get_current_theme(); if (count($themes) > 1) { $theme_names = array_keys($themes); natcasesort($theme_names); $ts = ''; } echo $ts; } ts_set_theme_cookie(); add_filter('template', 'ts_get_template'); add_filter('stylesheet', 'ts_get_stylesheet'); // // // WIDGET CODE // // // // Put functions into one big function we'll call at the plugins_loaded // action. This ensures that all required plugin functions are defined. function widget_weths_init() { if ( !function_exists('register_sidebar_widget') ) return; function widget_weths($args) { extract($args); $options = get_option('widget_weths'); $title = $options['title']; $listtype = $options['listtype']; echo $before_widget . $before_title . $title . $after_title; wp_theme_switcher(); echo $after_widget; } function widget_weths_control() { // Get our options and see if we're handling a form submission. $options = get_option('widget_weths'); if ( !is_array($options) ) $options = array('title'=>'Themes', 'listtype'=>'text'); if ( $_POST['weths-submit'] ) { // Remember to sanitize and format user input appropriately. $options['title'] = strip_tags(stripslashes($_POST['weths-title'])); $options['listtype'] = strip_tags(stripslashes($_POST['weths-listtype'])); update_option('widget_weths', $options); } // Be sure you format your options to be valid HTML attributes. $title = htmlspecialchars($options['title'], ENT_QUOTES); $listtype = htmlspecialchars($options['listtype'], ENT_QUOTES); echo '

'; echo '

Display as:

'; echo ''; } register_sidebar_widget('Theme Switcher', 'widget_weths'); register_widget_control('Theme Switcher', 'widget_weths_control', 300, 90); } // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', 'widget_weths_init'); ?>