WordPress.org

Forums

Theme Switcher Error (3 posts)

  1. m_eclipse
    Member
    Posted 9 years ago #

    I recently installed the WP Theme Switcher plugin and it went well, not a problem.

    However I went to switch themes on my site the next day and I got these error messages:

    Warning: Cannot modify header information - headers already sent by (output started at /home/pretsorg/public_html/eclipse/index.php:2) in /home/pretsorg/public_html/eclipse/wp-content/plugins/theme-switcher.php on line 37

    Warning: Cannot modify header information - headers already sent by (output started at /home/pretsorg/public_html/eclipse/index.php:2) in /home/pretsorg/public_html/eclipse/wp-content/plugins/theme-switcher.php on line 44

    I'm not sure what is causing these errors and I've reinstalled the plugin several times. I also tried setting the name of my themes and the folder they're in to the same name, and also deleting spaces in the theme name.

    Someone told me that whitespace might be the problem, but I'm rather clueless as to what this is.

    Any help would be greatly appreciated.
    Also, my site is http://prettyskies.org/eclipse
    The error I get is on this page: http://prettyskies.org/eclipse/index.php?wptheme=Supernatural+Patience

    And this is the actual theme switcher plugin that I'm using:

    <?php

    /*
    Plugin Name: Theme Switcher
    Plugin URI: http://wordpress.org/
    Description: Allow your readers to switch themes.
    Version: 0.5
    Author: Ryan Boren
    Author URI: http://boren.nu/

    Adapted from Alex King's style switcher.
    http://www.alexking.org/software/wordpress/

    To use, add the following to your sidebar menu:

  2. Themes:
    <?php wp_theme_switcher(); ?>
  3. This will create a list of themes for your readers to select.

    If you would like a dropdown box rather than a list, add this:

  4. Themes:
    <?php wp_theme_switcher('dropdown'); ?>
  5. */

    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 = '<ul id="themeswitcher">'."\n";

    if ($style == 'dropdown') {
    $ts .= ''."\n"
    . ' <select name="themeswitcher" onchange="location.href=\''.get_settings('home').'/index.php?wptheme=\' + this.options[this.selectedIndex].value;">'."\n" ;

    foreach ($theme_names as $theme_name) {
    // Skip unpublished themes.
    if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish')
    continue;

    if ((!empty($_COOKIE["wptheme" . COOKIEHASH]) && $_COOKIE["wptheme" . COOKIEHASH] == $theme_name)
    || (empty($_COOKIE["wptheme" . COOKIEHASH]) && ($theme_name == $default_theme))) {
    $ts .= ' <option value="'.$theme_name.'" selected="selected">'
    . htmlspecialchars($theme_name)
    . '</option>'."\n"
    ;
    } else {
    $ts .= ' <option value="'.$theme_name.'">'
    . htmlspecialchars($theme_name)
    . '</option>'."\n"
    ;
    }
    }
    $ts .= ' </select>'."\n"
    . ''."\n"
    ;
    } else {
    foreach ($theme_names as $theme_name) {
    // Skip unpublished themes.
    if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish')
    continue;

    $display = htmlspecialchars($theme_name);

    if ((!empty($_COOKIE["wptheme" . COOKIEHASH]) && $_COOKIE["wptheme" . COOKIEHASH] == $theme_name)
    || (empty($_COOKIE["wptheme" . COOKIEHASH]) && ($theme_name == $default_theme))) {
    $ts .= '

  6. '.$display.'
  7. '."\n";
    } else {
    $ts .= '
  8. <a href="'
    .get_settings('home').'/'. 'index.php'
    .'?wptheme='.urlencode($theme_name).'">'
    .$display.'
  9. '."\n";
    }
    }
    }
    $ts .= '';
    }

    echo $ts;
    }

    ts_set_theme_cookie();

    add_filter('template', 'ts_get_template');
    add_filter('stylesheet', 'ts_get_stylesheet');

    ?>

  • sadish
    Member
    Posted 9 years ago #

    you might have a blank space at the end of the plugin or at the beginning of the plugin.
    Please remove all of the empty spaces. thats it.

    Thanks
    Sadish

  • m_eclipse
    Member
    Posted 9 years ago #

    I checked, but thats not the problem. I did change a part of the plugin and now I get this error instead:

    Parse error: syntax error, unexpected ';' in /home/pretsorg/public_html/eclipse/wp-content/plugins/theme-switcher.php on line 36

    This is what my line 36 looks like:
    COOKIEPATH ;

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags