delete_theme

The timeline below displays how wordpress function delete_theme has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Removes a theme.
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        // Failed to connect. Error and request again.
        request_filesystem_credentials($redirect, '', true);
        $data = ob_get_clean();
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base theme folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    /**
     * Fires immediately before a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     */
    do_action('delete_theme', $stylesheet);
    $theme = wp_get_theme($stylesheet);
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    /**
     * Fires immediately after a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     * @param bool   $deleted    Whether the theme deletion was successful.
     */
    do_action('deleted_theme', $stylesheet, $deleted);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.l10n.php');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Clear theme caches.
    $theme->cache_delete();
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 6.4

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Removes a theme.
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        // Failed to connect. Error and request again.
        request_filesystem_credentials($redirect, '', true);
        $data = ob_get_clean();
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    /**
     * Fires immediately before a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     */
    do_action('delete_theme', $stylesheet);
    $theme = wp_get_theme($stylesheet);
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    /**
     * Fires immediately after a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     * @param bool   $deleted    Whether the theme deletion was successful.
     */
    do_action('deleted_theme', $stylesheet, $deleted);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Clear theme caches.
    $theme->cache_delete();
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 6.1

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Removes a theme.
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        // Failed to connect. Error and request again.
        request_filesystem_credentials($redirect, '', true);
        $data = ob_get_clean();
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    /**
     * Fires immediately before a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     */
    do_action('delete_theme', $stylesheet);
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    /**
     * Fires immediately after a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     * @param bool   $deleted    Whether the theme deletion was successful.
     */
    do_action('deleted_theme', $stylesheet, $deleted);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 5.8

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        // Failed to connect. Error and request again.
        request_filesystem_credentials($redirect, '', true);
        $data = ob_get_clean();
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    /**
     * Fires immediately before a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     */
    do_action('delete_theme', $stylesheet);
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    /**
     * Fires immediately after a theme deletion attempt.
     *
     * @since 5.8.0
     *
     * @param string $stylesheet Stylesheet of the theme to delete.
     * @param bool   $deleted    Whether the theme deletion was successful.
     */
    do_action('deleted_theme', $stylesheet, $deleted);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 5.4

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        // Failed to connect. Error and request again.
        request_filesystem_credentials($redirect, '', true);
        $data = ob_get_clean();
        if (!empty($data)) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 5.3

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again.
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error(
            'could_not_remove_theme',
            /* translators: %s: Theme name. */
            sprintf(__('Could not fully remove the theme %s.'), $stylesheet)
        );
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 5.1

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 *
 * @param string $stylesheet Stylesheet of the theme to delete.
 * @param string $redirect   Redirect to page when complete.
 * @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again.
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
            $json_translation_files = glob(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json');
            if ($json_translation_files) {
                array_map(array($wp_filesystem, 'delete'), $json_translation_files);
            }
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 4.6

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem Subclass
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return void|bool|WP_Error When void, echoes content.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    ob_start();
    $credentials = request_filesystem_credentials($redirect);
    $data = ob_get_clean();
    if (false === $credentials) {
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        ob_start();
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again.
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
        }
    }
    // Remove the theme from allowed themes on the network.
    if (is_multisite()) {
        WP_Theme::network_disable_theme($stylesheet);
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 4.3

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @global WP_Filesystem_Base $wp_filesystem Subclass
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return void|bool|WP_Error When void, echoes content.
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    ob_start();
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    if (false === $credentials = request_filesystem_credentials($redirect)) {
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
        }
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 4.2

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return mixed
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    ob_start();
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    if (false === $credentials = request_filesystem_credentials($redirect)) {
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
        }
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 4.1

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return mixed
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    ob_start();
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    if (false === $credentials = request_filesystem_credentials($redirect)) {
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $translations_dir = $wp_filesystem->wp_lang_dir();
    $translations_dir = trailingslashit($translations_dir);
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
        }
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}

WordPress Version: 3.7

/**
 * WordPress Theme Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return mixed
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    ob_start();
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    if (false === $credentials = request_filesystem_credentials($redirect)) {
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    //Get the base plugin folder
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    // Force refresh of theme update information
    delete_site_transient('update_themes');
    return true;
}