base_directory = trailingslashit( $base_directory ); } /** * Registers the autoloader. * * @return void */ public function register() { spl_autoload_register( array( $this, 'load' ) ); } /** * Loads a class when it belongs to the plugin namespace. * * @param string $class_name Fully qualified class name. * @return void */ public function load( $class_name ) { if ( 0 !== strpos( $class_name, $this->prefix ) ) { return; } $relative_class = substr( $class_name, strlen( $this->prefix ) ); $class_parts = explode( '\\', $relative_class ); $short_name = array_pop( $class_parts ); $is_interface = 'Interface' === substr( $short_name, -9 ); if ( $is_interface ) { $short_name = substr( $short_name, 0, -9 ); } if ( $is_interface ) { $file_name = preg_replace( '/(?base_directory . $directory . $file_name; if ( is_readable( $file ) ) { require_once $file; } } }