WP_CLI

Runner::action_setup_theme_wp_cli_skip_themes()publicWP-CLI 1.0

Set up the filters to skip the loaded theme

Method of the class: Runner{}

No Hooks.

Return

null. Nothing (null).

Usage

$Runner = new Runner();
$Runner->action_setup_theme_wp_cli_skip_themes();

Runner::action_setup_theme_wp_cli_skip_themes() code WP-CLI 2.8.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 );
	}
	// 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 );
			}
		},
		0
	);
}