Skip to content

Instantly share code, notes, and snippets.

@WordBits
Created April 23, 2018 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WordBits/c0d44f0c1e6152f36e331d045bcc7034 to your computer and use it in GitHub Desktop.
Save WordBits/c0d44f0c1e6152f36e331d045bcc7034 to your computer and use it in GitHub Desktop.
This is the plugin autoloader that I use. Of course, customize it as you see fit.
<?php
// Download this snippet as a plugin and more at: https://wordbits.io/?post_type=snippet&p=527
// Created by: jeffmatson
?>
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
function example_autoload( $classname ) {
$class = str_replace( '\\', DIRECTORY_SEPARATOR, str_replace( '_', '-', strtolower( $classname ) ) );
$file_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $class . '.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
}
}
spl_autoload_register('example_autoload');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment