WordPress at Your Fingertips
function is not described


Shutdown_Handler::__invoke() public WC 1.0

Handles the shutdown of the autoloader.

{} It's a method of the class: Shutdown_Handler{}

No Hooks.


null. Nothing.


$Shutdown_Handler = new Shutdown_Handler();

Code of Shutdown_Handler::__invoke() WC 5.5.2

public function __invoke() {
	// Don't save a broken cache if an error happens during some plugin's initialization.
	if ( ! did_action( 'plugins_loaded' ) ) {
		// Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame.
		if ( ! empty( $this->cached_plugins ) ) {
			$this->plugins_handler->cache_plugins( array() );


	// Load the active plugins fresh since the list we pulled earlier might not contain
	// plugins that were activated but did not reset the autoloader. This happens
	// when a plugin is in the cache but not "active" when the autoloader loads.
	// We also want to make sure that plugins which are deactivating are not
	// considered "active" so that they will be removed from the cache now.
	try {
		$active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader );
	} catch ( \Exception $ex ) {
		// When the package is deleted before shutdown it will throw an exception.
		// In the event this happens we should erase the cache.
		if ( ! empty( $this->cached_plugins ) ) {
			$this->plugins_handler->cache_plugins( array() );

	// The paths should be sorted for easy comparisons with those loaded from the cache.
	// Note we don't need to sort the cached entries because they're already sorted.
	sort( $active_plugins );

	// We don't want to waste time saving a cache that hasn't changed.
	if ( $this->cached_plugins === $active_plugins ) {

	$this->plugins_handler->cache_plugins( $active_plugins );