Skip to content

Instantly share code, notes, and snippets.

@antom
Last active August 29, 2015 13:56
Show Gist options
  • Save antom/9052205 to your computer and use it in GitHub Desktop.
Save antom/9052205 to your computer and use it in GitHub Desktop.
If you've been editing your WordPress theme in the admin area and you get the dreaded 'white screen of death' after saving, simply upload this to the root folder to select a working theme to reset to. You should then be able to access the admin ok to fix the bug in the offending theme.
<?php
define('SHORTINIT',true);
$wp_dir = getcwd();
// if WordPress isn't in the root (eg. set up for Git), do something like this:
// $wp_dir = getcwd() . '/path/to/wordpress/subdirectory';
require_once($wp_dir . '/wp-load.php');
if (isset($_GET['to'])) {
global $wpdb;
$query = $wpdb->query('
UPDATE
wp_options
SET
option_value = "' . $_GET['to'] . '"
WHERE
FIND_IN_SET(option_name,"template,stylesheet,current_template")
');
echo '<p>The attempt to reset your WordPress template to <em>',$_GET['to'],'</em> was ',($query?'':'not '),'successful.</p>';
} else {
$dirs = array();
$path = WP_CONTENT_DIR . '/themes/';
foreach(scandir($path) as $item) {
if (is_dir($path . $item) && !in_array($item,array('.','..'))) {
$dirs[] = sprintf('<li><a href="?to=%1$s">%1$s</a></li>',$item);
}
}
echo '<p>Found templates: </p><ul>',(count($dirs) ? implode('',$dirs) : '<li>No themes found.</li>'),'</ul>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment