PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / wordpress / mcp-adapter / includes / Autoloader.php

Autoloader.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/wordpress/mcp-adapter/includes/Autoloader.php

92 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PSR-4 Autoloader for PHP classes inside plugin.
4 *
5 * Ensures that autoloaders are present, and logs an Admin notice if not.
6 *
7 * Can be bypassed by defining the WP_MCP_AUTOLOAD constant to false.
8 *
9 * @package WP\MCP
10 */
11
12 declare( strict_types=1 );
13
14 namespace WP\MCP;
15
16 /**
17 * Class - Autoloader
18 */
19 final class Autoloader {
20 /**
21 * Whether the autoloader has been loaded.
22 *
23 * @var bool
24 */
25 protected static bool $is_loaded = false;
26
27 /**
28 * Attempt to autoload the Composer dependencies.
29 */
30 public static function autoload(): bool {
31 // If we're not *supposed* to autoload anything, then return true.
32 if ( defined( 'WP_MCP_AUTOLOAD' ) && false === WP_MCP_AUTOLOAD ) {
33 return true;
34 }
35
36 if ( self::$is_loaded ) {
37 return self::$is_loaded;
38 }
39
40 $autoloader = WP_MCP_DIR . '/vendor/autoload.php';
41 self::$is_loaded = self::require_autoloader( $autoloader );
42
43 return self::$is_loaded;
44 }
45
46 /**
47 * Attempts to load the autoloader file, if it exists.
48 *
49 * @param string $autoloader_file The path to the autoloader file.
50 */
51 private static function require_autoloader( string $autoloader_file ): bool {
52 if ( ! is_readable( $autoloader_file ) ) {
53 self::missing_autoloader_notice();
54
55 return false;
56 }
57
58 return (bool) require_once $autoloader_file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Autoloader is a Composer file.
59 }
60
61 /**
62 * Displays a notice if the autoloader is missing.
63 */
64 private static function missing_autoloader_notice(): void {
65
66 $hooks = array(
67 'admin_notices',
68 'network_admin_notices',
69 );
70
71 foreach ( $hooks as $hook ) {
72 add_action(
73 $hook,
74 static function () {
75 $error_message = __( 'MCP Adapter: The Composer autoloader was not found. If you installed the plugin from the GitHub source code, make sure to run `composer install`.', 'mcp-adapter' );
76
77 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
78 error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice.
79 }
80 ?>
81 <div class="error notice">
82 <p>
83 <?php echo esc_html( $error_message ); ?>
84 </p>
85 </div>
86 <?php
87 }
88 );
89 }
90 }
91 }
92