WordPress – preview and modify a theme till we are satisfied

Since we at Saturn provide wordpress as a CMS, and have more than a handful of experienced WordPress customizers, and themeres we have handled several challeges related to WordPress. The latest one being that the client was offered a facelift, and they wanted to preview the progress of integration. I searched the plugin repositories and blogs, found a lot of solutions, which include theme switchers, theme preview, and even suggestions to have a local copy. Well with our client, we could not think of a local copy, since the database dump itself was about 320GB and the images and videows was a whopping 1200 GB. Well after reading through the source of get_option, a wave struck me.



function new_theme_preview(){
    if(isset(
$_COOKIE['ShowNewTheme'])){
        return 
'myNewTheme';
    }
    return 
false;
}
 
add_filter('pre_option_current_theme''new_theme_preview'10);
 


I added the above to the end of an active plugin, then created two files newtheme.php and oldtheme.php, containing code to set and remove the cookie. The files were put into the top level folder. Once I am done with the theming, I could remove all these manually.

// newtheme.php
setcookie 'ShowNewTheme''1');
header("Location: ./");
 
//oldtheme.php
setcookie 'ShowNewTheme'false);
header("Location: ./");