class-autoloader-handler.php
5 days ago
class-autoloader-locator.php
5 days ago
class-autoloader.php
5 days ago
class-container.php
5 days ago
class-hook-manager.php
5 days ago
class-latest-autoloader-guard.php
5 days ago
class-manifest-reader.php
5 days ago
class-path-processor.php
5 days ago
class-php-autoloader.php
5 days ago
class-plugin-locator.php
5 days ago
class-plugins-handler.php
5 days ago
class-shutdown-handler.php
5 days ago
class-version-loader.php
5 days ago
class-version-selector.php
5 days ago
index.php
10 months ago
class-shutdown-handler.php
48 lines
| 1 | <?php |
| 2 | namespace Automattic\Jetpack\Autoloader\jp362475ab3000a6225facecf40e51a264\al5_0_8; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | // phpcs:ignore |
| 5 | class Shutdown_Handler { |
| 6 | private $plugins_handler; |
| 7 | private $cached_plugins; |
| 8 | private $was_included_by_autoloader; |
| 9 | public function __construct( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) { |
| 10 | $this->plugins_handler = $plugins_handler; |
| 11 | $this->cached_plugins = $cached_plugins; |
| 12 | $this->was_included_by_autoloader = $was_included_by_autoloader; |
| 13 | } |
| 14 | public function __invoke() { |
| 15 | // Don't save a broken cache if an error happens during some plugin's initialization. |
| 16 | if ( ! did_action( 'plugins_loaded' ) ) { |
| 17 | // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. |
| 18 | if ( ! empty( $this->cached_plugins ) ) { |
| 19 | $this->plugins_handler->cache_plugins( array() ); |
| 20 | } |
| 21 | return; |
| 22 | } |
| 23 | // Load the active plugins fresh since the list we pulled earlier might not contain |
| 24 | // plugins that were activated but did not reset the autoloader. This happens |
| 25 | // when a plugin is in the cache but not "active" when the autoloader loads. |
| 26 | // We also want to make sure that plugins which are deactivating are not |
| 27 | // considered "active" so that they will be removed from the cache now. |
| 28 | try { |
| 29 | $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); |
| 30 | } catch ( \Exception $ex ) { |
| 31 | // When the package is deleted before shutdown it will throw an exception. |
| 32 | // In the event this happens we should erase the cache. |
| 33 | if ( ! empty( $this->cached_plugins ) ) { |
| 34 | $this->plugins_handler->cache_plugins( array() ); |
| 35 | } |
| 36 | return; |
| 37 | } |
| 38 | // The paths should be sorted for easy comparisons with those loaded from the cache. |
| 39 | // Note we don't need to sort the cached entries because they're already sorted. |
| 40 | sort( $active_plugins ); |
| 41 | // We don't want to waste time saving a cache that hasn't changed. |
| 42 | if ( $this->cached_plugins === $active_plugins ) { |
| 43 | return; |
| 44 | } |
| 45 | $this->plugins_handler->cache_plugins( $active_plugins ); |
| 46 | } |
| 47 | } |
| 48 |