validate_theme_requirements

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

WordPress Version: 5.9

/**
 * Validates the theme requirements for WordPress version and PHP version.
 *
 * Uses the information from `Requires at least` and `Requires PHP` headers
 * defined in the theme's `style.css` file.
 *
 * @since 5.5.0
 * @since 5.8.0 Removed support for using `readme.txt` as a fallback.
 *
 * @param string $stylesheet Directory name for the theme.
 * @return true|WP_Error True if requirements are met, WP_Error on failure.
 */
function validate_theme_requirements($stylesheet)
{
    $theme = wp_get_theme($stylesheet);
    $requirements = array('requires' => (!empty($theme->get('RequiresWP'))) ? $theme->get('RequiresWP') : '', 'requires_php' => (!empty($theme->get('RequiresPHP'))) ? $theme->get('RequiresPHP') : '');
    $compatible_wp = is_wp_version_compatible($requirements['requires']);
    $compatible_php = is_php_version_compatible($requirements['requires_php']);
    if (!$compatible_wp && !$compatible_php) {
        return new WP_Error('theme_wp_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_php) {
        return new WP_Error('theme_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_wp) {
        return new WP_Error('theme_wp_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    }
    return true;
}

WordPress Version: 5.8

/**
 * Validates the theme requirements for WordPress version and PHP version.
 *
 * Uses the information from `Requires at least` and `Requires PHP` headers
 * defined in the theme's `style.css` file.
 *
 * @since 5.5.0
 * @since 5.8.0 Removed support for using `readme.txt` as a fallback.
 *
 * @param string $stylesheet Directory name for the theme.
 * @return true|WP_Error True if requirements are met, WP_Error on failure.
 */
function validate_theme_requirements($stylesheet)
{
    $theme = wp_get_theme($stylesheet);
    // If the theme is a Full Site Editing theme, check for the presence of the Gutenberg plugin.
    $theme_tags = $theme->get('Tags');
    if (!empty($theme_tags) && in_array('full-site-editing', $theme_tags, true) && !function_exists('gutenberg_is_fse_theme')) {
        return new WP_Error('theme_requires_gutenberg_plugin', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> This theme (%s) uses Full Site Editing, which requires the Gutenberg plugin to be activated.', 'theme'),
            $theme->display('Name')
        ));
    }
    $requirements = array('requires' => (!empty($theme->get('RequiresWP'))) ? $theme->get('RequiresWP') : '', 'requires_php' => (!empty($theme->get('RequiresPHP'))) ? $theme->get('RequiresPHP') : '');
    $compatible_wp = is_wp_version_compatible($requirements['requires']);
    $compatible_php = is_php_version_compatible($requirements['requires_php']);
    if (!$compatible_wp && !$compatible_php) {
        return new WP_Error('theme_wp_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_php) {
        return new WP_Error('theme_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_wp) {
        return new WP_Error('theme_wp_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    }
    return true;
}

WordPress Version: 5.5

/**
 * Validates the theme requirements for WordPress version and PHP version.
 *
 * Uses the information from `Requires at least` and `Requires PHP` headers
 * defined in the theme's `style.css` file.
 *
 * If the headers are not present in the theme's stylesheet file,
 * `readme.txt` is also checked as a fallback.
 *
 * @since 5.5.0
 *
 * @param string $stylesheet Directory name for the theme.
 * @return true|WP_Error True if requirements are met, WP_Error on failure.
 */
function validate_theme_requirements($stylesheet)
{
    $theme = wp_get_theme($stylesheet);
    $requirements = array('requires' => (!empty($theme->get('RequiresWP'))) ? $theme->get('RequiresWP') : '', 'requires_php' => (!empty($theme->get('RequiresPHP'))) ? $theme->get('RequiresPHP') : '');
    $readme_file = $theme->theme_root . '/' . $stylesheet . '/readme.txt';
    if (file_exists($readme_file)) {
        $readme_headers = get_file_data($readme_file, array('requires' => 'Requires at least', 'requires_php' => 'Requires PHP'), 'theme');
        $requirements = array_merge($readme_headers, $requirements);
    }
    $compatible_wp = is_wp_version_compatible($requirements['requires']);
    $compatible_php = is_php_version_compatible($requirements['requires_php']);
    if (!$compatible_wp && !$compatible_php) {
        return new WP_Error('theme_wp_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_php) {
        return new WP_Error('theme_php_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    } elseif (!$compatible_wp) {
        return new WP_Error('theme_wp_incompatible', sprintf(
            /* translators: %s: Theme name. */
            _x('<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'theme'),
            $theme->display('Name')
        ));
    }
    return true;
}