Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created January 15, 2016 09:06
Show Gist options
  • Save MattSandy/1105ca33f92e9217d63b to your computer and use it in GitHub Desktop.
Save MattSandy/1105ca33f92e9217d63b to your computer and use it in GitHub Desktop.
Remove Inactive Wordpress Themes
<?php define('WP_USE_THEMES', false); require('./wp-blog-header.php');
remove_inactive_themes();
function remove_inactive_themes()
{
echo '<h1>Removing Inactive Themes</h1><ul>';
$theme_dir = get_theme_root();
$template_dir = get_template_directory();
foreach (scandir($theme_dir) as $res) {
if (is_dir($theme_dir . '/' . $res)&&($res!='.')&($res!='..')) {
if($template_dir==$theme_dir . '/' . $res) {
echo "<li><em>" . $res . "</em></li>";
} else {
echo "<li><s>" . $res . "</s>...deleted</li>";
}
}
}
}
function deleteDirectory($dir) {
if (!file_exists($dir)) return true;
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if (!deleteDirectory($dir . "/" . $item)) {
chmod($dir . "/" . $item, 0777);
if (!deleteDirectory($dir . "/" . $item)) return false;
};
}
return rmdir($dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment