From 9af92e46f5cd5243cbdff865502e923c6a20642d Mon Sep 17 00:00:00 2001 From: Mike Pretzlaw Date: Sat, 9 Sep 2017 19:00:20 +0200 Subject: [PATCH] Autoloader more global - github #119 --- woocommerce-shipcloud.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/woocommerce-shipcloud.php b/woocommerce-shipcloud.php index be16a8b9..715838f5 100644 --- a/woocommerce-shipcloud.php +++ b/woocommerce-shipcloud.php @@ -105,7 +105,6 @@ public function load_plugin() { * @since 1.0.0 */ private function constants() { - define( 'WCSC_FOLDER', $this->get_folder() ); define( 'WCSC_RELATIVE_FOLDER', substr( WCSC_FOLDER, strlen( WP_PLUGIN_DIR ), strlen( WCSC_FOLDER ) ) ); define( 'WCSC_URLPATH', $this->get_url_path() ); define( 'WCSC_COMPONENTFOLDER', WCSC_FOLDER . '/components' ); @@ -306,13 +305,9 @@ public function load_components() { require_once( WCSC_FOLDER . '/components/component.php' ); require_once( WCSC_FOLDER . '/components/core/core.php' ); require_once( WCSC_FOLDER . '/components/woo/woo.php' ); - - // Add autoloader for everything else. - spl_autoload_register( array( $this, 'load_vendor' ) ); - spl_autoload_register( array( $this, 'load_shipcloud' ) ); } - public function load_vendor( $class ) { + public static function load_vendor( $class ) { $filename = WCSC_FOLDER . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . str_replace( array( '\\' ), array( DIRECTORY_SEPARATOR ), $class ) . '.php'; @@ -331,7 +326,7 @@ public function load_vendor( $class ) { * * @return bool */ - public function load_shipcloud( $class ) { + public static function load_shipcloud( $class ) { $filename = WCSC_FOLDER . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . strtolower( @@ -507,3 +502,11 @@ function woocommerce_shipcloud_init() { } add_action( 'plugins_loaded', 'woocommerce_shipcloud_init' ); + +define( 'WCSC_FOLDER', plugin_dir_path( __FILE__ ) ); + +/** + * Early add autoloader. + */ +spl_autoload_register( '\\WooCommerce_Shipcloud::load_vendor' ); +spl_autoload_register( '\\WooCommerce_Shipcloud::load_shipcloud' );