wp-staging
Last commit date
Backend
1 day ago
Backup
1 week ago
Basic
1 week ago
Component
1 week ago
Core
1 week ago
Framework
1 day ago
Frontend
5 months ago
Notifications
8 months ago
Staging
1 day ago
assets
1 day ago
languages
1 day ago
resources
1 year ago
vendor_wpstg
1 week ago
views
1 day ago
CONTRIBUTING.md
1 year ago
Deactivate.php
8 months ago
README.md
3 months ago
SECURITY.md
2 years ago
autoloader.php
1 month ago
bootstrap.php
1 month ago
commonBootstrap.php
1 day ago
constantsFree.php
1 day ago
freeBootstrap.php
1 month ago
install.php
1 week ago
opcacheBootstrap.php
1 day ago
readme.txt
1 day ago
runtimeRequirements.php
3 months ago
uninstall.php
1 week ago
wp-staging-error-handler.php
6 months ago
wp-staging.php
1 day ago
autoloader.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | // Register the autoloader for the plugin source code, and for the prefixed vendors. |
| 4 | // |
| 5 | // Defensive guards against missing/corrupted vendor_wpstg files (issue #5074): |
| 6 | // without these, a missing autoload map would make `include_once` return false, |
| 7 | // `array_merge(array, false)` would throw a TypeError on PHP 8+, and the entire |
| 8 | // WordPress site would crash. Bail early instead so bootstrap.php can detect the |
| 9 | // failed autoloader via class_exists() and show an admin notice. |
| 10 | // |
| 11 | // is_readable() (rather than file_exists()) covers the "file present but |
| 12 | // unreadable" case — security scanners chmod'ing vendor files to 000 is one |
| 13 | // of the real-world triggers — and avoids include_once emitting an E_WARNING |
| 14 | // that would leak to the page output when WP_DEBUG_DISPLAY is on. |
| 15 | $wpstgSrcMapFile = __DIR__ . '/vendor_wpstg/autoload/src.php'; |
| 16 | $wpstgVendorMapFile = __DIR__ . '/vendor_wpstg/autoload/vendor.php'; |
| 17 | $wpstgFilesMapFile = __DIR__ . '/vendor_wpstg/autoload/files.php'; |
| 18 | |
| 19 | if ( |
| 20 | !is_readable($wpstgSrcMapFile) |
| 21 | || !is_readable($wpstgVendorMapFile) |
| 22 | || !is_readable($wpstgFilesMapFile) |
| 23 | ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | // Validate ALL three maps (including files.php) before registering the |
| 28 | // autoloader. If files.php is corrupted, we must bail before |
| 29 | // spl_autoload_register so bootstrap.php's class_exists() guard sees an |
| 30 | // unregistered autoloader and surfaces the admin notice — otherwise the |
| 31 | // plugin would continue booting in a half-broken state without composer's |
| 32 | // file-based autoloads. |
| 33 | $wpstgSrcMap = include_once $wpstgSrcMapFile; |
| 34 | $wpstgVendorMap = include_once $wpstgVendorMapFile; |
| 35 | $wpstgFilesToInclude = include_once $wpstgFilesMapFile; |
| 36 | |
| 37 | if ( |
| 38 | !is_array($wpstgSrcMap) |
| 39 | || !is_array($wpstgVendorMap) |
| 40 | || !is_array($wpstgFilesToInclude) |
| 41 | ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | $class_map = array_merge($wpstgSrcMap, $wpstgVendorMap); |
| 46 | |
| 47 | spl_autoload_register( |
| 48 | // @phpstan-ignore-next-line - Autoloader return value preserved for compatibility |
| 49 | function (string $class) use ($class_map) { |
| 50 | if (isset($class_map[$class]) && file_exists($class_map[$class])) { |
| 51 | include_once $class_map[$class]; |
| 52 | |
| 53 | return true; |
| 54 | } |
| 55 | }, |
| 56 | true, |
| 57 | true |
| 58 | ); |
| 59 | |
| 60 | foreach ($wpstgFilesToInclude as $file) { |
| 61 | if (is_readable($file)) { |
| 62 | require $file; |
| 63 | } |
| 64 | } |
| 65 |