autoloader( string $class )

Description #

Callback function for auto loading class on demand.

Parameters #

  • $class
    string (Required) Name of class.

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: loader.php

function autoloader( $class ) {
	if ( false === strpos( $class, 'AnsPress\\' ) ) {
		return;
	}

	// Replace AnsPress\Pro\ and change to lowercase to fix WPCS warning.
	$class    = strtolower( str_replace( 'AnsPress\\', '', $class ) );
	$filename = ANSPRESS_DIR . str_replace( '_', '-', str_replace( '\\', '/', $class ) ) . '.php';

	// Check if file exists before including.
	if ( file_exists( $filename ) ) {
		require_once $filename;

		// Check class exists.
		if ( class_exists( $class ) ) {
			return true;
		}
	}

	return false;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment