Posted on March 1, 2015
/** * Autoloads files when requested * * @since 1.0.0 * @param string $class_name Name of the class being requested */ function my_class_file_autoloader( $class_name ) { /** * If the class being requested does not start with our prefix, * we know it's not one in our project */ if ( 0 !== strpos( $class_name, 'My_' ) ) { return; } $file_name = str_replace( array( 'My_', '_' ), // Prefix | Underscores array( '', '-' ), // Remove | Replace with hyphens strtolower( $class_name ) // lowercase ); // Compile our path from the current location $file = dirname( __FILE__ ) . '/includes/'. $file_name .'.php'; // If a file is found if ( file_exists( $file ) ) { // Then load it up! require( $file ); } }
Recent Comments