WP_CLI
Runner::action_setup_theme_wp_cli_skip_themes
Set up the filters to skip the loaded theme
Method of the class: Runner{}
No Hooks.
Returns
null. Nothing (null).
Usage
$Runner = new Runner(); $Runner->action_setup_theme_wp_cli_skip_themes();
Runner::action_setup_theme_wp_cli_skip_themes() Runner::action setup theme wp cli skip themes code WP-CLI 2.13.0-alpha
public function action_setup_theme_wp_cli_skip_themes() {
$wp_cli_filter_active_theme = static function ( $value ) {
$skipped_themes = WP_CLI::get_runner()->config['skip-themes'];
if ( true === $skipped_themes ) {
return '';
}
if ( ! is_array( $skipped_themes ) ) {
$skipped_themes = explode( ',', $skipped_themes );
}
$checked_value = $value;
// Always check against the stylesheet value
// This ensures a child theme can be skipped when template differs
if ( false !== stripos( current_filter(), 'option_template' ) ) {
$checked_value = get_option( 'stylesheet' );
}
if ( '' === $checked_value || in_array( $checked_value, $skipped_themes, true ) ) {
return '';
}
return $value;
};
$hooks = [
'pre_option_template',
'option_template',
'pre_option_stylesheet',
'option_stylesheet',
];
foreach ( $hooks as $hook ) {
add_filter( $hook, $wp_cli_filter_active_theme, 999 );
}
// Noop memoization added in WP 6.4.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_stylesheet_path'] = null;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_template_path'] = null;
// Remove theme-related actions not directly tied into the theme lifecycle.
if ( WP_CLI::get_runner()->config['skip-themes'] ) {
$theme_related_actions = [
[ 'init', '_register_theme_block_patterns' ], // Block patterns registration in WP Core.
[ 'init', 'gutenberg_register_theme_block_patterns' ], // Block patterns registration in the GB plugin.
];
foreach ( $theme_related_actions as $action ) {
list( $hook, $callback ) = $action;
remove_action( $hook, $callback );
}
}
// Clean up after the TEMPLATEPATH and STYLESHEETPATH constants are defined
WP_CLI::add_wp_hook(
'after_setup_theme',
static function () use ( $hooks, $wp_cli_filter_active_theme ) {
foreach ( $hooks as $hook ) {
remove_filter( $hook, $wp_cli_filter_active_theme, 999 );
}
// Noop memoization added in WP 6.4 again.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_stylesheet_path'] = null;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_template_path'] = null;
},
0
);
}