Browse: Home / Classes /

Autoloader

Autoloader

Class Autoloader


Description #

Allows for autoloading of LearnDash classes.

Example usage:

 // will be `/var/www/site/wp-content/plugins/sfwd-lms'
 $this_dir = dirname(__FILE__);

 // gets hold of the singleton instance of the class
 $autoloader = Autoloader::instance();

 // register one by one or use `register_prefixes` method
 $autoloader->register_prefix( 'LearnDash__Admin__', $this_dir . '/src/admin' );
 $autoloader->register_prefix( 'LearnDash__Admin__', $this_dir . '/src/another-dir' );
 $autoloader->register_prefix( 'LearnDash__Utils__', $this_dir . '/src/some-dir' );

 // register a direct class to path
 $autoloader->register_class( 'LearnDash_Some_Deprecated_Class', $this_dir . '/src/deprecated/LearnDash_Some_Deprecated_Class.php' );

 // register a fallback dir to be searched for the class before giving up
 $autoloader->add_fallback_dir( $this_dir . '/all-the-classes' );

 // calls `spl_autoload_register`
 $autoloader->register_autoloader();

 // class will be searched in the path
 // `/var/www/site/wp-content/plugins/sfwd-lms/src/admin/Some_Class.php'
 // and
 // `/var/www/site/wp-content/plugins/sfwd-lms/src/another-dir/Some_Class.php'
 $i = new LearnDash__Admin__Some_Class();

 // class will be searched in the path
 // `/var/www/site/wp-content/plugins/sfwd-lms/utils/some-dir/Some_Util.php'
 $i = new LearnDash__Utils__Some_Util();

 // class will be searched in the path
 // `/var/www/site/wp-content/plugins/sfwd-lms/src/deprecated/LearnDash_Some_Deprecated_Class.php'
 $i = new LearnDash_Some_Deprecated_Class();

Source #

File: src/Core/Autoloader.php



Methods #