Skip to content

Commit

Permalink
Autoloader more global
Browse files Browse the repository at this point in the history
- github #119
  • Loading branch information
Mike Pretzlaw committed Sep 9, 2017
1 parent 7863900 commit 9af92e4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions woocommerce-shipcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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';
Expand All @@ -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(
Expand Down Expand Up @@ -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' );

0 comments on commit 9af92e4

Please sign in to comment.