PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / vendor / jetpack-autoloader / class-plugins-handler.php

class-plugins-handler.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at vendor/jetpack-autoloader/class-plugins-handler.php

165 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file was automatically generated by automattic/jetpack-autoloader.
4 *
5 * @package automattic/jetpack-autoloader
6 */
7
8 namespace Automattic\Jetpack\Autoloader\jp9596fa42a27a19b46fd381ad6137fd57\al5_0_23;
9
10 // phpcs:ignore
11
12 /**
13 * This class handles locating and caching all of the active plugins.
14 */
15 class Plugins_Handler {
16 /**
17 * The transient key for plugin paths.
18 */
19 const TRANSIENT_KEY = 'jetpack_autoloader_plugin_paths';
20
21 /**
22 * The locator for finding plugins in different locations.
23 *
24 * @var Plugin_Locator
25 */
26 private $plugin_locator;
27
28 /**
29 * The processor for transforming cached paths.
30 *
31 * @var Path_Processor
32 */
33 private $path_processor;
34
35 /**
36 * The constructor.
37 *
38 * @param Plugin_Locator $plugin_locator The locator for finding active plugins.
39 * @param Path_Processor $path_processor The processor for transforming cached paths.
40 */
41 public function __construct( $plugin_locator, $path_processor ) {
42 $this->plugin_locator = $plugin_locator;
43 $this->path_processor = $path_processor;
44 }
45
46 /**
47 * Gets all of the active plugins we can find.
48 *
49 * @param bool $include_deactivating When true, plugins deactivating this request will be considered active.
50 * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown.
51 *
52 * @return string[]
53 */
54 public function get_active_plugins( $include_deactivating, $record_unknown ) {
55 global $jetpack_autoloader_activating_plugins_paths;
56
57 // We're going to build a unique list of plugins from a few different sources
58 // to find all of our "active" plugins. While we need to return an integer
59 // array, we're going to use an associative array internally to reduce
60 // the amount of time that we're going to spend checking uniqueness
61 // and merging different arrays together to form the output.
62 $active_plugins = array();
63
64 // Make sure that plugins which have activated this request are considered as "active" even though
65 // they probably won't be present in any option.
66 if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) {
67 foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) {
68 $active_plugins[ $path ] = $path;
69 }
70 }
71
72 // This option contains all of the plugins that have been activated.
73 $plugins = $this->plugin_locator->find_using_option( 'active_plugins' );
74 foreach ( $plugins as $path ) {
75 $active_plugins[ $path ] = $path;
76 }
77
78 // This option contains all of the multisite plugins that have been activated.
79 if ( is_multisite() ) {
80 $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true );
81 foreach ( $plugins as $path ) {
82 $active_plugins[ $path ] = $path;
83 }
84 }
85
86 // These actions contain plugins that are being activated/deactivated during this request.
87 $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) );
88 foreach ( $plugins as $path ) {
89 $active_plugins[ $path ] = $path;
90 }
91
92 // When the current plugin isn't considered "active" there's a problem.
93 // Since we're here, the plugin is active and currently being loaded.
94 // We can support this case (mu-plugins and non-standard activation)
95 // by adding the current plugin to the active list and marking it
96 // as an unknown (activating) plugin. This also has the benefit
97 // of causing a reset because the active plugins list has
98 // been changed since it was saved in the global.
99 $current_plugin = $this->plugin_locator->find_current_plugin();
100 if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) {
101 $active_plugins[ $current_plugin ] = $current_plugin;
102 $jetpack_autoloader_activating_plugins_paths[] = $current_plugin;
103 }
104
105 // When deactivating plugins aren't desired we should entirely remove them from the active list.
106 if ( ! $include_deactivating ) {
107 // These actions contain plugins that are being deactivated during this request.
108 $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) );
109 foreach ( $plugins as $path ) {
110 unset( $active_plugins[ $path ] );
111 }
112 }
113
114 // Transform the array so that we don't have to worry about the keys interacting with other array types later.
115 return array_values( $active_plugins );
116 }
117
118 /**
119 * Gets all of the cached plugins if there are any.
120 *
121 * @return string[]
122 */
123 public function get_cached_plugins() {
124 $cached = get_transient( self::TRANSIENT_KEY );
125 if ( ! is_array( $cached ) || empty( $cached ) ) {
126 return array();
127 }
128
129 // We need to expand the tokens to an absolute path for this webserver.
130 return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached );
131 }
132
133 /**
134 * Saves the plugin list to the cache.
135 *
136 * @param array $plugins The plugin list to save to the cache.
137 */
138 public function cache_plugins( $plugins ) {
139 // We store the paths in a tokenized form so that that webservers with different absolute paths don't break.
140 $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins );
141
142 set_transient( self::TRANSIENT_KEY, $plugins );
143 }
144
145 /**
146 * Checks to see whether or not the plugin list given has changed when compared to the
147 * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal
148 * with cases where the active list may change due to filtering..
149 *
150 * @param string[] $plugins The plugins list to check against the global cache.
151 *
152 * @return bool True if the plugins have changed, otherwise false.
153 */
154 public function have_plugins_changed( $plugins ) {
155 global $jetpack_autoloader_cached_plugin_paths;
156
157 if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) {
158 $jetpack_autoloader_cached_plugin_paths = $plugins;
159 return true;
160 }
161
162 return false;
163 }
164 }
165