PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / wordpress / mcp-adapter / includes / Autoloader.php
ameliabooking / vendor / wordpress / mcp-adapter / includes Last commit date
Abilities 1 month ago Cli 1 month ago Core 1 month ago Domain 1 month ago Handlers 1 month ago Infrastructure 1 month ago Servers 1 month ago Transport 1 month ago Autoloader.php 1 month ago Plugin.php 1 month 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