WP_CLI

Runner::setup_skip_plugins_filters()privateWP-CLI 1.0

Set up the filters to skip the loaded plugins

Method of the class: Runner{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->setup_skip_plugins_filters();

Runner::setup_skip_plugins_filters() code WP-CLI 2.8.0-alpha

private function setup_skip_plugins_filters() {
	$wp_cli_filter_active_plugins = static function ( $plugins ) {
		$skipped_plugins = WP_CLI::get_runner()->config['skip-plugins'];
		if ( true === $skipped_plugins ) {
			return [];
		}
		if ( ! is_array( $plugins ) ) {
			return $plugins;
		}
		foreach ( $plugins as $a => $b ) {
			// active_sitewide_plugins stores plugin name as the key.
			if ( false !== strpos( current_filter(), 'active_sitewide_plugins' ) && Utils\is_plugin_skipped( $a ) ) {
				unset( $plugins[ $a ] );
				// active_plugins stores plugin name as the value.
			} elseif ( false !== strpos( current_filter(), 'active_plugins' ) && Utils\is_plugin_skipped( $b ) ) {
				unset( $plugins[ $a ] );
			}
		}
		// Reindex because active_plugins expects a numeric index.
		if ( false !== strpos( current_filter(), 'active_plugins' ) ) {
			$plugins = array_values( $plugins );
		}
		return $plugins;
	};

	$hooks = [
		'pre_site_option_active_sitewide_plugins',
		'site_option_active_sitewide_plugins',
		'pre_option_active_plugins',
		'option_active_plugins',
	];
	foreach ( $hooks as $hook ) {
		WP_CLI::add_wp_hook( $hook, $wp_cli_filter_active_plugins, 999 );
	}
	WP_CLI::add_wp_hook(
		'plugins_loaded',
		static function () use ( $hooks, $wp_cli_filter_active_plugins ) {
			foreach ( $hooks as $hook ) {
				remove_filter( $hook, $wp_cli_filter_active_plugins, 999 );
			}
		},
		0
	);
}