PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / trunk
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). vtrunk
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / vendor / wordpress / mcp-adapter / includes / Autoloader.php
commercebird / vendor / wordpress / mcp-adapter / includes Last commit date
Abilities 2 months ago Cli 2 months ago Core 2 months ago Domain 2 months ago Handlers 2 months ago Infrastructure 2 months ago Servers 2 months ago Transport 2 months ago Autoloader.php 2 months ago Plugin.php 2 months ago
Autoloader.php
92 lines
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