Created
April 23, 2018 03:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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