Commit 8a60d326 authored by Nick's avatar Nick

Merge branch 'autoloader' into 'master'

switches to using the autoloader

See merge request !3
parents d6350bb7 b2ccbdec
......@@ -3,7 +3,7 @@
Plugin Name: WCDC Advanced Hooks
Plugin URI: http://designsbynickthegeek.com
Description: Sample Plugin for Advanced WordPress Hooks
Version: 0.2
Version: 0.3
Author: Nick the Geek
Author URI: http://designsbynickthegeek.com
*/
......@@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* Sets the `WCDC_AH_DIR`, `WCDC_AH_CLASSES`, and `WCDC_AH_ASSETS` constants.
* Registers the autoloader.
* Adds required actions/filters.
* Requires all files (in later version the autoloader will handle this)
* Uses an autoloader to load files as needed automatically.
*/
class WCDC_Advanced_Hooks_Init {
......@@ -33,50 +33,17 @@ class WCDC_Advanced_Hooks_Init {
* @access public
*/
static $classes = array(
'class.WCDC_Advanced_Hooks.php' => 'WCDC_Advanced_Hooks',
'class.WCDC_Advanced_Hooks_CPT.php' => 'WCDC_Advanced_Hooks_CPT',
'class.WCDC_Advanced_Hooks_Output.php' => 'WCDC_Advanced_Hooks_Output',
'class.WCDC_Advanced_Hooks_Post_Meta_Save.php' => 'WCDC_Advanced_Hooks_Post_Meta_Save',
'class.WCDC_Advanced_Hooks_Post_Meta.php' => 'WCDC_Advanced_Hooks_Post_Meta',
'class.WCDC_Advanced_Hooks_Settings.php' => 'WCDC_Advanced_Hooks_Settings',
'class.WCDC_Advanced_Hooks_Sanitize.php' => 'WCDC_Advanced_Hooks_Sanitize',
'class.WCDC_Advanced_Hooks_Scripts_Styles.php' => 'WCDC_Advanced_Hooks_Scripts_Styles',
'class.WCDC_Advanced_Hooks_Widget.php' => 'WCDC_Advanced_Hooks_Widget',
'WCDC_Advanced_Hooks',
'WCDC_Advanced_Hooks_CPT',
'WCDC_Advanced_Hooks_Output',
'WCDC_Advanced_Hooks_Post_Meta_Save',
'WCDC_Advanced_Hooks_Post_Meta',
'WCDC_Advanced_Hooks_Settings',
'WCDC_Advanced_Hooks_Sanitize',
'WCDC_Advanced_Hooks_Scripts_Styles',
'WCDC_Advanced_Hooks_Widget',
);
/**
* Files needed for is_admin pages
*
* @var array
* @access public
*/
var $is_admin = array(
'class.WCDC_Advanced_Hooks.php' => 'WCDC_Advanced_Hooks',
'class.WCDC_Advanced_Hooks_CPT.php' => 'WCDC_Advanced_Hooks_CPT',
'class.WCDC_Advanced_Hooks_Post_Meta_Save.php' => 'WCDC_Advanced_Hooks_Post_Meta_Save',
'class.WCDC_Advanced_Hooks_Post_Meta.php' => 'WCDC_Advanced_Hooks_Post_Meta',
'class.WCDC_Advanced_Hooks_Settings.php' => 'WCDC_Advanced_Hooks_Settings',
'class.WCDC_Advanced_Hooks_Sanitize.php' => 'WCDC_Advanced_Hooks_Sanitize',
'class.WCDC_Advanced_Hooks_Scripts_Styles.php' => 'WCDC_Advanced_Hooks_Scripts_Styles',
'class.WCDC_Advanced_Hooks_Widget.php' => 'WCDC_Advanced_Hooks_Widget',
);
/**
* Files needed for ! is_admin pages
*
* @var array
* @access public
*/
var $not_is_admin = array(
'class.WCDC_Advanced_Hooks.php' => 'WCDC_Advanced_Hooks',
'class.WCDC_Advanced_Hooks_CPT.php' => 'WCDC_Advanced_Hooks_CPT',
'class.WCDC_Advanced_Hooks_Output.php' => 'WCDC_Advanced_Hooks_Output',
'class.WCDC_Advanced_Hooks_Scripts_Styles.php' => 'WCDC_Advanced_Hooks_Scripts_Styles',
'class.WCDC_Advanced_Hooks_Widget.php' => 'WCDC_Advanced_Hooks_Widget',
);
/**
* __construct function.
* Defines constants.
......@@ -91,10 +58,7 @@ class WCDC_Advanced_Hooks_Init {
define( 'WCDC_AH_CLASSES', WCDC_AH_DIR . 'includes/classes/' );
define( 'WCDC_AH_ASSETS' , plugin_dir_url( __FILE__ ) . 'assets/' );
# spl_autoload_register( array( 'WCDC_Advanced_Hooks_Init', 'autoloader' ) );
//at this point all files will be loaded all the time.
$this->load_files();
spl_autoload_register( array( 'WCDC_Advanced_Hooks_Init', 'autoloader' ) );
//since this is loaded on init if we are doing it right, we will want to start the register post type object right away
$this->register_post_type();
......@@ -103,27 +67,6 @@ class WCDC_Advanced_Hooks_Init {
}
/**
* Loads all the files.
* We improved this a bit so that files will load for is_admin or not is_admin.
* We can still do better.
*
* @access public
* @return void
*/
function load_files() {
foreach ( WCDC_Advanced_Hooks_Init::$classes as $file => $class ) {
if ( is_admin() && empty( $this->is_admin[$file] ) ) {
continue;
} elseif ( ! is_admin() && empty( $this->not_is_admin[$file] ) ) {
continue;
}
require_once( WCDC_AH_CLASSES . $file );
}
}
/**
* Registers all the actions/filters.
*
......@@ -186,11 +129,11 @@ class WCDC_Advanced_Hooks_Init {
*/
static function autoloader( $class ) {
if ( ! isset( WCDC_Advanced_Hooks_Init::$classes[ $class ] ) ) {
if ( ! in_array( $class, WCDC_Advanced_Hooks_Init::$classes ) ) {
return;
}
include( WCDC_AH_CLASSES . WCDC_Advanced_Hooks_Init::$classes[ $class ] );
include( sprintf( '%sclass.%s.php', WCDC_AH_CLASSES, $class ) );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment