Skip to content

Instantly share code, notes, and snippets.

@tareq1988
Created January 31, 2014 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tareq1988/8739970 to your computer and use it in GitHub Desktop.
Save tareq1988/8739970 to your computer and use it in GitHub Desktop.
Autoloader
<?php
/**
* Autoload class files on demand
*
* `Dokan_Installer` becomes => installer.php
* `Dokan_Template_Report` becomes => template-report.php
*
* @param string $class requested class name
*/
function dokan_autoload( $class ) {
if ( stripos( $class, 'Dokan_' ) !== false ) {
$class_name = str_replace( array('Dokan_', '_'), array('', '-'), $class);
$file_path = __DIR__ . '/classes/' . strtolower( $class_name ) . '.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
}
}
}
spl_autoload_register( 'dokan_autoload' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment