resume_theme

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

WordPress Version: 6.5

/**
 * Tries to resume a single theme.
 *
 * If a redirect was provided and a functions.php file was found, we first ensure that
 * functions.php file does not throw fatal errors anymore.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the file. If the theme fails, then the redirection will not be overwritten
 * with the success message and the theme will not be resumed.
 *
 * @since 5.2.0
 *
 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
 * @global string $wp_template_path   Path to current theme's template directory.
 *
 * @param string $theme    Single theme to resume.
 * @param string $redirect Optional. URL to redirect to. Default empty string.
 * @return bool|WP_Error True on success, false if `$theme` was not paused,
 *                       `WP_Error` on failure.
 */
function resume_theme($theme, $redirect = '')
{
    global $wp_stylesheet_path, $wp_template_path;
    list($extension) = explode('/', $theme);
    /*
     * We'll override this later if the theme could be resumed without
     * creating a fatal error.
     */
    if (!empty($redirect)) {
        $functions_path = '';
        if (str_contains($wp_stylesheet_path, $extension)) {
            $functions_path = $wp_stylesheet_path . '/functions.php';
        } elseif (str_contains($wp_template_path, $extension)) {
            $functions_path = $wp_template_path . '/functions.php';
        }
        if (!empty($functions_path)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('theme-resume-error_' . $theme), $redirect));
            // Load the theme's functions.php to test whether it throws a fatal error.
            ob_start();
            if (!defined('WP_SANDBOX_SCRAPING')) {
                define('WP_SANDBOX_SCRAPING', true);
            }
            include $functions_path;
            ob_clean();
        }
    }
    $result = wp_paused_themes()->delete($extension);
    if (!$result) {
        return new WP_Error('could_not_resume_theme', __('Could not resume the theme.'));
    }
    return true;
}

WordPress Version: 6.4

/**
 * Tries to resume a single theme.
 *
 * If a redirect was provided and a functions.php file was found, we first ensure that
 * functions.php file does not throw fatal errors anymore.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the file. If the theme fails, then the redirection will not be overwritten
 * with the success message and the theme will not be resumed.
 *
 * @since 5.2.0
 *
 * @param string $theme    Single theme to resume.
 * @param string $redirect Optional. URL to redirect to. Default empty string.
 * @return bool|WP_Error True on success, false if `$theme` was not paused,
 *                       `WP_Error` on failure.
 */
function resume_theme($theme, $redirect = '')
{
    list($extension) = explode('/', $theme);
    /*
     * We'll override this later if the theme could be resumed without
     * creating a fatal error.
     */
    if (!empty($redirect)) {
        $stylesheet_path = get_stylesheet_directory();
        $template_path = get_template_directory();
        $functions_path = '';
        if (str_contains($stylesheet_path, $extension)) {
            $functions_path = $stylesheet_path . '/functions.php';
        } elseif (str_contains($template_path, $extension)) {
            $functions_path = $template_path . '/functions.php';
        }
        if (!empty($functions_path)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('theme-resume-error_' . $theme), $redirect));
            // Load the theme's functions.php to test whether it throws a fatal error.
            ob_start();
            if (!defined('WP_SANDBOX_SCRAPING')) {
                define('WP_SANDBOX_SCRAPING', true);
            }
            include $functions_path;
            ob_clean();
        }
    }
    $result = wp_paused_themes()->delete($extension);
    if (!$result) {
        return new WP_Error('could_not_resume_theme', __('Could not resume the theme.'));
    }
    return true;
}

WordPress Version: 6.3

/**
 * Tries to resume a single theme.
 *
 * If a redirect was provided and a functions.php file was found, we first ensure that
 * functions.php file does not throw fatal errors anymore.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the file. If the theme fails, then the redirection will not be overwritten
 * with the success message and the theme will not be resumed.
 *
 * @since 5.2.0
 *
 * @param string $theme    Single theme to resume.
 * @param string $redirect Optional. URL to redirect to. Default empty string.
 * @return bool|WP_Error True on success, false if `$theme` was not paused,
 *                       `WP_Error` on failure.
 */
function resume_theme($theme, $redirect = '')
{
    list($extension) = explode('/', $theme);
    /*
     * We'll override this later if the theme could be resumed without
     * creating a fatal error.
     */
    if (!empty($redirect)) {
        $functions_path = '';
        if (str_contains(STYLESHEETPATH, $extension)) {
            $functions_path = STYLESHEETPATH . '/functions.php';
        } elseif (str_contains(TEMPLATEPATH, $extension)) {
            $functions_path = TEMPLATEPATH . '/functions.php';
        }
        if (!empty($functions_path)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('theme-resume-error_' . $theme), $redirect));
            // Load the theme's functions.php to test whether it throws a fatal error.
            ob_start();
            if (!defined('WP_SANDBOX_SCRAPING')) {
                define('WP_SANDBOX_SCRAPING', true);
            }
            include $functions_path;
            ob_clean();
        }
    }
    $result = wp_paused_themes()->delete($extension);
    if (!$result) {
        return new WP_Error('could_not_resume_theme', __('Could not resume the theme.'));
    }
    return true;
}

WordPress Version: 5.2

/**
 * Tries to resume a single theme.
 *
 * If a redirect was provided and a functions.php file was found, we first ensure that
 * functions.php file does not throw fatal errors anymore.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the file. If the theme fails, then the redirection will not be overwritten
 * with the success message and the theme will not be resumed.
 *
 * @since 5.2.0
 *
 * @param string $theme    Single theme to resume.
 * @param string $redirect Optional. URL to redirect to. Default empty string.
 * @return bool|WP_Error True on success, false if `$theme` was not paused,
 *                       `WP_Error` on failure.
 */
function resume_theme($theme, $redirect = '')
{
    list($extension) = explode('/', $theme);
    /*
     * We'll override this later if the theme could be resumed without
     * creating a fatal error.
     */
    if (!empty($redirect)) {
        $functions_path = '';
        if (strpos(STYLESHEETPATH, $extension)) {
            $functions_path = STYLESHEETPATH . '/functions.php';
        } elseif (strpos(TEMPLATEPATH, $extension)) {
            $functions_path = TEMPLATEPATH . '/functions.php';
        }
        if (!empty($functions_path)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('theme-resume-error_' . $theme), $redirect));
            // Load the theme's functions.php to test whether it throws a fatal error.
            ob_start();
            if (!defined('WP_SANDBOX_SCRAPING')) {
                define('WP_SANDBOX_SCRAPING', true);
            }
            include $functions_path;
            ob_clean();
        }
    }
    $result = wp_paused_themes()->delete($extension);
    if (!$result) {
        return new WP_Error('could_not_resume_theme', __('Could not resume the theme.'));
    }
    return true;
}