* @since 1.47.0 */ namespace AdvancedAds; defined( 'ABSPATH' ) || exit; /** * Autoloader. */ class Autoloader { /** * Hold autoloader. * * @var mixed */ private $autoloader; /** * Main instance * * Ensure only one instance is loaded or can be loaded. * * @return Autoloader */ public static function get(): Autoloader { static $instance; if ( null === $instance ) { $instance = new Autoloader(); } return $instance; } /** * Get hold autoloader. * * @return mixed */ public function get_autoloader() { return $this->autoloader; } /** * Get plugin directory. * * @return string */ public function get_directory(): string { return dirname( ADVADS_FILE ); } /** * Runs this initializer. * * @return void */ public function initialize(): void { $locate = $this->locate(); if ( ! $locate ) { add_action( 'admin_notices', [ $this, 'missing_autoloader' ] ); return; } $this->autoloader = require $locate; $this->register_wordpress(); } /** * Locate the autoload file * * This function searches for the autoload file in the packages directory and vendor directory. * * @return bool|string */ private function locate() { $directory = $this->get_directory(); $packages = $directory . '/packages/autoload.php'; $vendors = $directory . '/vendor/autoload.php'; $is_debug = $this->is_debug() || 'local' === $this->get_environment_type(); if ( is_readable( $packages ) && ( ! $is_debug || ! is_readable( $vendors ) ) ) { return $packages; } if ( is_readable( $vendors ) ) { return $vendors; } return false; } /** * Add WordPress classes to map * * @return void */ private function register_wordpress(): void { $this->autoloader->addClassmap( [ 'WP_List_Table' => ABSPATH . 'wp-admin/includes/class-wp-list-table.php', 'WP_Terms_List_Table' => ABSPATH . 'wp-admin/includes/class-wp-terms-list-table.php', ] ); } /** * If the autoloader is missing, add an admin notice. * * @return void */ protected function missing_autoloader(): void { ?>
', '' ); ?>