PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.8
Jetpack – WP Security, Backup, Speed, & Growth v8.8
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / vendor / autoload_functions.php

autoload_functions.php in Jetpack – WP Security, Backup, Speed, & Growth 8.8, at vendor/autoload_functions.php

153 lines 4.6 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\jpf07841f6f4aa8fb73b701bb0850cd730;
9
10 // phpcs:ignore
11
12 global $jetpack_packages_classmap;
13 global $jetpack_packages_filemap;
14 global $jetpack_autoloader_activating_plugins_paths;
15
16 if ( ! is_array( $jetpack_packages_classmap ) ) {
17 $jetpack_packages_classmap = array();
18 }
19
20 if ( ! is_array( $jetpack_packages_filemap ) ) {
21 $jetpack_packages_filemap = array();
22 }
23
24 if ( ! is_array( $jetpack_autoloader_activating_plugins_paths ) ) {
25 $jetpack_autoloader_activating_plugins_paths = array();
26 }
27
28 /**
29 * Used for autoloading jetpack packages.
30 *
31 * @param string $class_name Class Name to load.
32 *
33 * @return Boolean Whether the class_name was found in the classmap.
34 */
35 function autoloader( $class_name ) {
36 global $jetpack_packages_classmap;
37
38 if ( isset( $jetpack_packages_classmap[ $class_name ] ) ) {
39 require_once $jetpack_packages_classmap[ $class_name ]['path'];
40 return true;
41 }
42
43 return false;
44 }
45
46 /**
47 * Used for running the code that initializes class and file maps.
48 *
49 * @param Plugins_Handler $plugins_handler The Plugins_Handler object.
50 * @param Version_Selector $version_selector The Version_Selector object.
51 */
52 function enqueue_files( $plugins_handler, $version_selector ) {
53 require_once __DIR__ . '/class-classes-handler.php';
54 require_once __DIR__ . '/class-files-handler.php';
55
56 $classes_handler = new Classes_Handler( $plugins_handler, $version_selector );
57 $classes_handler->set_class_paths();
58
59 $files_handler = new Files_Handler( $plugins_handler, $version_selector );
60 $files_handler->set_file_paths();
61
62 $files_handler->file_loader();
63 }
64
65 /**
66 * Finds the latest installed autoloader. If this is the latest autoloader, sets
67 * up the classmap and filemap.
68 */
69 function set_up_autoloader() {
70 global $jetpack_autoloader_latest_version;
71 global $jetpack_packages_classmap;
72
73 require_once __DIR__ . '/class-plugins-handler.php';
74 require_once __DIR__ . '/class-version-selector.php';
75 require_once __DIR__ . '/class-autoloader-handler.php';
76
77 $plugins_handler = new Plugins_Handler();
78 $version_selector = new Version_Selector();
79 $autoloader_handler = new Autoloader_Handler( $plugins_handler, $version_selector );
80
81 if ( $plugins_handler->should_autoloader_reset() ) {
82 /*
83 * The autoloader must be reset when an activating plugin that was
84 * previously unknown is detected.
85 */
86 $jetpack_autoloader_latest_version = null;
87 $jetpack_packages_classmap = array();
88 }
89
90 // Find the latest autoloader.
91 if ( ! $jetpack_autoloader_latest_version ) {
92 $autoloader_handler->find_latest_autoloader();
93 }
94
95 $current_autoloader_version = $autoloader_handler->get_current_autoloader_version();
96
97 // This is the latest autoloader, so generate the classmap and filemap and register the autoloader function.
98 if ( empty( $jetpack_packages_classmap ) && $current_autoloader_version === $jetpack_autoloader_latest_version ) {
99 enqueue_files( $plugins_handler, $version_selector );
100 $autoloader_handler->update_autoloader_chain();
101 add_filter( 'upgrader_post_install', __NAMESPACE__ . '\reset_maps_after_update', 0, 3 );
102 }
103 }
104
105 /**
106 * Resets the autoloader after a plugin update.
107 *
108 * @param bool $response Installation response.
109 * @param array $hook_extra Extra arguments passed to hooked filters.
110 * @param array $result Installation result data.
111 *
112 * @return bool The passed in $response param.
113 */
114 function reset_maps_after_update( $response, $hook_extra, $result ) {
115 global $jetpack_autoloader_latest_version;
116 global $jetpack_packages_classmap;
117
118 if ( isset( $hook_extra['plugin'] ) ) {
119 /*
120 * $hook_extra['plugin'] is the path to the plugin file relative to the plugins directory:
121 * https://core.trac.wordpress.org/browser/tags/5.4/src/wp-admin/includes/class-wp-upgrader.php#L701
122 */
123 $plugin = $hook_extra['plugin'];
124
125 if ( false === strpos( $plugin, '/', 1 ) ) {
126 // Single-file plugins don't use packages, so bail.
127 return $response;
128 }
129
130 if ( ! is_plugin_active( $plugin ) ) {
131 // The updated plugin isn't active, so bail.
132 return $response;
133 }
134
135 /*
136 * $plugin is the path to the plugin file relative to the plugins directory.
137 */
138 $plugin_dir = str_replace( '\\', '/', WP_PLUGIN_DIR );
139 $plugin_path = trailingslashit( $plugin_dir ) . trailingslashit( explode( '/', $plugin )[0] );
140
141 if ( is_readable( $plugin_path . 'vendor/autoload_functions.php' ) ) {
142 // The plugin has a v2.x autoloader, so reset it.
143 $jetpack_autoloader_latest_version = null;
144 $jetpack_packages_classmap = array();
145
146 set_up_autoloader();
147 }
148 }
149
150 return $response;
151 }
152
153