PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.0
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / vendor / wordpress / mcp-adapter / includes / Autoloader.php

Autoloader.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.0, at vendor/wordpress/mcp-adapter/includes/Autoloader.php

96 lines 2.3 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 // Exit if accessed directly.
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Class - Autoloader
21 */
22 final class Autoloader {
23 /**
24 * Whether the autoloader has been loaded.
25 *
26 * @var bool
27 */
28 protected static bool $is_loaded = false;
29
30 /**
31 * Attempt to autoload the Composer dependencies.
32 */
33 public static function autoload(): bool {
34 // If we're not *supposed* to autoload anything, then return true.
35 if ( defined( 'WP_MCP_AUTOLOAD' ) && false === WP_MCP_AUTOLOAD ) {
36 return true;
37 }
38
39 if ( self::$is_loaded ) {
40 return self::$is_loaded;
41 }
42
43 // Jetpack Autoloader uses `autoload_packages.php` instead of `autoload.php`.
44 $autoloader = WP_MCP_DIR . '/vendor/autoload_packages.php';
45 self::$is_loaded = self::require_autoloader( $autoloader );
46
47 return self::$is_loaded;
48 }
49
50 /**
51 * Attempts to load the autoloader file, if it exists.
52 *
53 * @param string $autoloader_file The path to the autoloader file.
54 */
55 private static function require_autoloader( string $autoloader_file ): bool {
56 if ( ! is_readable( $autoloader_file ) ) {
57 self::missing_autoloader_notice();
58
59 return false;
60 }
61
62 return (bool) require_once $autoloader_file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Autoloader is a Composer file.
63 }
64
65 /**
66 * Displays a notice if the autoloader is missing.
67 */
68 private static function missing_autoloader_notice(): void {
69
70 $hooks = array(
71 'admin_notices',
72 'network_admin_notices',
73 );
74
75 foreach ( $hooks as $hook ) {
76 add_action(
77 $hook,
78 static function () {
79 $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' );
80
81 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
82 error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice.
83 }
84 ?>
85 <div class="error notice">
86 <p>
87 <?php echo esc_html( $error_message ); ?>
88 </p>
89 </div>
90 <?php
91 }
92 );
93 }
94 }
95 }
96