Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
Forked from Rarst/class-autoload-wp.php
Created November 10, 2013 04:20
Show Gist options
  • Save ethanhinson/7393736 to your computer and use it in GitHub Desktop.
Save ethanhinson/7393736 to your computer and use it in GitHub Desktop.
<?php
if ( ! class_exists( 'Autoload_WP' ) ) {
/**
* Generic autoloader for classes named in WordPress coding style.
*/
class Autoload_WP {
public $dir = __DIR__;
function __construct( $dir = '' ) {
if ( ! empty( $dir ) )
$this->dir = $dir;
spl_autoload_register( array( $this, 'spl_autoload_register' ) );
}
function spl_autoload_register( $class_name ) {
$class_path = $this->dir . '/class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
if ( file_exists( $class_path ) )
include $class_path;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment