rveitch
8/3/2015 - 8:50 PM

Autoload included php files

Autoload included php files

<?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