Autoloader.php
72 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Includes the composer Autoloader used for packages and classes in the src/ directory. |
| 4 | * |
| 5 | * @package Automattic/WooCommerce |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\WooCommerce; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Autoloader class. |
| 14 | * |
| 15 | * @since 3.7.0 |
| 16 | */ |
| 17 | class Autoloader { |
| 18 | |
| 19 | /** |
| 20 | * Static-only class. |
| 21 | */ |
| 22 | private function __construct() {} |
| 23 | |
| 24 | /** |
| 25 | * Require the autoloader and return the result. |
| 26 | * |
| 27 | * If the autoloader is not present, let's log the failure and display a nice admin notice. |
| 28 | * |
| 29 | * @return boolean |
| 30 | */ |
| 31 | public static function init() { |
| 32 | $autoloader = dirname( __DIR__ ) . '/vendor/autoload_packages.php'; |
| 33 | |
| 34 | if ( ! is_readable( $autoloader ) ) { |
| 35 | self::missing_autoloader(); |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | return require $autoloader; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * If the autoloader is missing, add an admin notice. |
| 44 | */ |
| 45 | protected static function missing_autoloader() { |
| 46 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 47 | error_log( // phpcs:ignore |
| 48 | esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, please refer to this document to set up your development environment: https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment', 'woocommerce' ) |
| 49 | ); |
| 50 | } |
| 51 | add_action( |
| 52 | 'admin_notices', |
| 53 | function() { |
| 54 | ?> |
| 55 | <div class="notice notice-error"> |
| 56 | <p> |
| 57 | <?php |
| 58 | printf( |
| 59 | /* translators: 1: is a link to a support document. 2: closing link */ |
| 60 | esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, %1$splease refer to this document%2$s to set up your development environment.', 'woocommerce' ), |
| 61 | '<a href="' . esc_url( 'https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment' ) . '" target="_blank" rel="noopener noreferrer">', |
| 62 | '</a>' |
| 63 | ); |
| 64 | ?> |
| 65 | </p> |
| 66 | </div> |
| 67 | <?php |
| 68 | } |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 |