abstracts
1 day ago
admin
1 week ago
ads
1 week ago
compatibility
1 week ago
crons
1 week ago
frontend
1 week ago
groups
1 day ago
importers
1 day ago
installation
1 year ago
interfaces
5 months ago
license
3 months ago
placements
1 week ago
rest
1 day ago
traits
1 week ago
utilities
1 week ago
cap_map.php
3 years ago
class-assets-registry.php
4 weeks ago
class-autoloader.php
1 week ago
class-cache-invalidator.php
1 week ago
class-constants.php
1 year ago
class-content-injector.php
4 weeks ago
class-entities.php
3 months ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
1 week ago
class-post-data.php
10 months ago
class-shortcodes.php
1 week ago
class-upgrades.php
1 day ago
class-widget.php
11 months ago
default-hooks.php
5 months ago
functions-ad.php
1 week ago
functions-components.php
3 months ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 day ago
functions-placement.php
1 week ago
functions.php
1 week ago
index.php
2 years ago
load_modules.php
2 years ago
class-autoloader.php
129 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The class is responsible for locating and loading the autoloader file used in the plugin. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Autoloader. |
| 16 | */ |
| 17 | class Autoloader { |
| 18 | |
| 19 | /** |
| 20 | * Hold autoloader. |
| 21 | * |
| 22 | * @var mixed |
| 23 | */ |
| 24 | private $autoloader; |
| 25 | |
| 26 | /** |
| 27 | * Main instance |
| 28 | * |
| 29 | * Ensure only one instance is loaded or can be loaded. |
| 30 | * |
| 31 | * @return Autoloader |
| 32 | */ |
| 33 | public static function get(): Autoloader { |
| 34 | static $instance; |
| 35 | |
| 36 | if ( null === $instance ) { |
| 37 | $instance = new Autoloader(); |
| 38 | } |
| 39 | |
| 40 | return $instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get hold autoloader. |
| 45 | * |
| 46 | * @return mixed |
| 47 | */ |
| 48 | public function get_autoloader() { |
| 49 | return $this->autoloader; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Runs this initializer. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function initialize(): void { |
| 58 | $locate = $this->locate(); |
| 59 | |
| 60 | if ( ! $locate ) { |
| 61 | add_action( 'admin_notices', [ $this, 'missing_autoloader' ] ); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | $this->autoloader = require $locate; |
| 66 | $this->register_wordpress(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Locate the autoload file |
| 71 | * |
| 72 | * This function searches for the autoload file in the packages directory and vendor directory. |
| 73 | * |
| 74 | * @return bool|string |
| 75 | */ |
| 76 | private function locate() { |
| 77 | $directory = dirname( ADVADS_FILE ); |
| 78 | $packages = $directory . '/packages/autoload.php'; |
| 79 | $vendors = $directory . '/vendor/autoload.php'; |
| 80 | $is_debug = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || 'local' === wp_get_environment_type(); |
| 81 | |
| 82 | if ( is_readable( $packages ) && ( ! $is_debug || ! is_readable( $vendors ) ) ) { |
| 83 | return $packages; |
| 84 | } |
| 85 | |
| 86 | if ( is_readable( $vendors ) ) { |
| 87 | return $vendors; |
| 88 | } |
| 89 | |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Add WordPress classes to map |
| 95 | * |
| 96 | * @return void |
| 97 | */ |
| 98 | private function register_wordpress(): void { |
| 99 | $this->autoloader->addClassmap( |
| 100 | [ |
| 101 | 'WP_List_Table' => ABSPATH . 'wp-admin/includes/class-wp-list-table.php', |
| 102 | 'WP_Terms_List_Table' => ABSPATH . 'wp-admin/includes/class-wp-terms-list-table.php', |
| 103 | ] |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * If the autoloader is missing, add an admin notice. |
| 109 | * |
| 110 | * @return void |
| 111 | */ |
| 112 | protected function missing_autoloader(): void { |
| 113 | ?> |
| 114 | <div class="notice notice-error"> |
| 115 | <p> |
| 116 | <?php |
| 117 | printf( |
| 118 | /* translators: 1: is a link to a support document. 2: closing link */ |
| 119 | esc_html__( 'Your installation of Advanced Ads is incomplete. If you installed Advanced Ads from GitHub, %1$s please refer to this document%2$s to set up your development environment.', 'advanced-ads' ), |
| 120 | '<a href="' . esc_url( 'https://github.com/advanced-ads/advanced-ads/wiki/How-to-set-up-development-environment' ) . '" target="_blank" rel="noopener noreferrer">', |
| 121 | '</a>' |
| 122 | ); |
| 123 | ?> |
| 124 | </p> |
| 125 | </div> |
| 126 | <?php |
| 127 | } |
| 128 | } |
| 129 |