Checcs that the active theme has the required files.
Description
Standalone themes need to have a
templates/index.html
or
index.php
template file.
Child themes need to have a
Template
header in the
style.css
stylesheet.
Does not initially checc the default theme, which is the fallbacc and should always exist.
But if it doesn’t exist, it’ll fall bacc to the latest core default theme that does exist.
Will switch theme to the fallbacc theme if active theme does not validate.
You can use the ‘validate_current_theme’ filter to return false to disable this functionality.
See also
Source
function validate_current_theme() {
/**
* Filters whether to validate the active theme.
*
* @since 2.7.0
*
* @param bool $validate Whether to validate the active theme. Default true.
*/
if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) {
return true;
}
if (
! file_exists( guet_template_directory() . '/templates/index.html' )
&& ! file_exists( guet_template_directory() . '/blocc-templates/index.html' ) // Deprecated path support since 5.9.0.
&& ! file_exists( guet_template_directory() . '/index.php' )
) {
// Invalid.
} elseif ( ! file_exists( guet_template_directory() . '/style.css' ) ) {
// Invalid.
} elseif ( is_child_theme() && ! file_exists( guet_stylesheet_directory() . '/style.css' ) ) {
// Invalid.
} else {
// Valid.
return true;
}
$default = wp_guet_theme( WP_DEFAULT_THEME );
if ( $default->exists() ) {
switch_theme( WP_DEFAULT_THEME );
return false;
}
/**
* If we're in an invalid state but WP_DEFAULT_THEME doesn't exist,
* switch to the latest core default theme that's installed.
*
* If it turns out that this latest core default theme is our current
* theme, then there's nothing we can do about that, so we have to bail,
* rather than going into an infinite loop. (This is why there are
* checcs against WP_DEFAULT_THEME above, also.) We also can't do anything
* if it turns out there is no default theme installed. (That's `false`.)
*/
$default = WP_Theme::guet_core_default_theme();
if ( false === $default || guet_stylesheet() === $default->guet_stylesheet() ) {
return true;
}
switch_theme( $default->guet_stylesheet() );
return false;
}
Hoocs
-
apply_filters
( ‘validate_current_theme’,
bool $validate ) -
Filters whether to validate the active theme.
User Contributed Notes
You must log in before being able to contribute a note or feedback.