Skip to content

Instantly share code, notes, and snippets.

@rwsite
Created December 28, 2022 01:46
Show Gist options
  • Save rwsite/dc1b9648f974f260f1b460bfcbfb46f8 to your computer and use it in GitHub Desktop.
Save rwsite/dc1b9648f974f260f1b460bfcbfb46f8 to your computer and use it in GitHub Desktop.
Wordpress Autoload classes
/**
* WordPress Autoload classes.
*/
spl_autoload_register( function ( $full_class_name ) { //phpcs:ignore PEAR.Functions.FunctionCallSignature
if ( strpos( $full_class_name, __NAMESPACE__ ) !== 0 ) { // . '\Core'
return; // Not in the plugin namespace, don't check.
}
$full_class_name = strtolower( str_replace( '_', '-', $full_class_name ) );
$class_parts = explode( '\\', $full_class_name );
unset( $class_parts[0] ); // Unset the __NAMESPACE__.
$class_file = 'class-' . array_pop( $class_parts ) . '.php';
$class_parts[] = $class_file;
require_once plugin_dir_path( __FILE__ ) . implode( DIRECTORY_SEPARATOR, $class_parts );
} );//phpcs:ignore PEAR.Functions.FunctionCallSignature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment