Last active
August 29, 2015 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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