Skip to content

Instantly share code, notes, and snippets.

@markopostma
Created February 17, 2016 19:07
Show Gist options
  • Select an option

  • Save markopostma/d787e2067f273ad54351 to your computer and use it in GitHub Desktop.

Select an option

Save markopostma/d787e2067f273ad54351 to your computer and use it in GitHub Desktop.
Autoloader for wordpress
function autoload_classes( $class ) {
$class_name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', $class)), '_');
$filename = dirname(__DIR__)."/includes/classes/" . $class_name . ".php";
if ( file_exists($filename) ) {
require_once $filename;
}
}
function autoload_custom_post_types( $class ) {
$filename = dirname(__DIR__)."/includes/custom-post-types/" . $class . ".php";
if ( file_exists($filename) ) {
require_once $filename;
}
}
function autoload_lib( $class ) {
$filename = dirname(__DIR__)."/includes/library/" . $class . ".php";
if ( file_exists($filename) ) {
require_once $filename;
}
}
spl_autoload_register( 'autoload_custom_post_types' );
spl_autoload_register( 'autoload_lib' );
spl_autoload_register( 'autoload_classes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment