Created
July 13, 2010 11:20
-
-
Save paulchubatyy/473743 to your computer and use it in GitHub Desktop.
Sample Autoload function for WordPress plugin
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 | |
/** | |
* Plugin autoloader. Coverts class name to path and loads it | |
* @param string $className | |
*/ | |
function autoload($className) | |
{ | |
if (class_exists($className)) | |
return; | |
if (self::$pluginAbsolutePath == NULL) | |
self::$pluginAbsolutePath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR | |
. 'foo' . DIRECTORY_SEPARATOR; | |
$medium = str_replace('bar', 'classes', strtolower($className)); | |
$path = str_replace('_', DIRECTORY_SEPARATOR, $medium); | |
// Putting altogether | |
$path = self::$pluginAbsolutePath . $path . '.php'; | |
if (file_exists($path) and is_readable($path)) | |
require_once $path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment