Created
August 3, 2015 20:50
-
-
Save rveitch/988c24aa6660391a21bc to your computer and use it in GitHub Desktop.
Autoload included php files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ! defined( 'ABSPATH' ) and exit; | |
| add_filter( 'plugins_loaded', array( 'Autoload_Includes', 'get_object' ) ); | |
| // begin class | |
| class Autoload_Includes { | |
| /* Define folder, there have inside the autoload files */ | |
| static protected $file_base = ''; | |
| /* The class object */ | |
| static protected $class_object = NULL; | |
| /* Load the object and get the current state */ | |
| public static function get_object() { | |
| if ( NULL == self::$class_object ) { | |
| self::$class_object = new self; | |
| } | |
| return self::$class_object; | |
| } | |
| /* Init function to register all used hooks */ | |
| public function __construct() { | |
| self::$file_base = dirname( __FILE__ ) . '/inc'; | |
| $this->load(); | |
| } | |
| /* Load all files in folder inc */ | |
| public static function load() { | |
| $file_base = self::$file_base; | |
| $autoload_files = glob( "$file_base/autoload/*.php" ); | |
| // load files | |
| foreach ( $autoload_files as $path ) { | |
| require_once $path; | |
| } | |
| } | |
| } // end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment