'error', 'dismiss' => false, ), ); } ); } } ); } /** * Attempts to load the autoloader file, if it exists. * * @param string $autoloader_file The path to the autoloader file. */ private static function require_autoloader( string $autoloader_file ): bool { if ( ! is_readable( $autoloader_file ) ) { self::missing_autoloader_notice(); return false; } return (bool) require_once $autoloader_file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Autoloader is a Composer file. } /** * Displays a notice if the autoloader is missing. */ private static function missing_autoloader_notice(): void { // Defer notice until translation functions are available. add_action( 'init', static function () { $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' ); // Log a notice. _doing_it_wrong( self::class, esc_html( $error_message ), '0.7.0' ); // Log an admin notice. $hooks = array( 'admin_notices', 'network_admin_notices', ); foreach ( $hooks as $hook ) { add_action( $hook, static function () use ( $error_message ) { wp_admin_notice( esc_html( $error_message ), array( 'type' => 'error', 'dismiss' => false, ), ); } ); } } ); } }