Created
December 28, 2022 01:46
-
-
Save rwsite/dc1b9648f974f260f1b460bfcbfb46f8 to your computer and use it in GitHub Desktop.
Wordpress Autoload classes
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
/** | |
* 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