abstracts
2 years ago
admin
1 year ago
database
2 years ago
groups
2 years ago
installation
1 year ago
interfaces
2 years ago
traits
2 years ago
utilities
2 years ago
array_ad_conditions.php
3 years ago
cap_map.php
3 years ago
class-assets-registry.php
1 year ago
class-autoloader.php
2 years ago
class-entities.php
2 years ago
class-plugin.php
1 year ago
functions.php
3 years ago
index.php
2 years ago
load_modules.php
2 years ago
class-plugin.php
164 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The plugin bootstrap. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds; |
| 11 | |
| 12 | use AdvancedAds\Admin; |
| 13 | use AdvancedAds\Groups; |
| 14 | use AdvancedAds\Framework; |
| 15 | use AdvancedAds\Framework\Loader; |
| 16 | use AdvancedAds\Installation\Install; |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | /** |
| 21 | * Plugin. |
| 22 | */ |
| 23 | class Plugin extends Loader { |
| 24 | |
| 25 | /** |
| 26 | * Main instance |
| 27 | * |
| 28 | * Ensure only one instance is loaded or can be loaded. |
| 29 | * |
| 30 | * @return Plugin |
| 31 | */ |
| 32 | public static function get(): Plugin { |
| 33 | static $instance; |
| 34 | |
| 35 | if ( null === $instance ) { |
| 36 | $instance = new Plugin(); |
| 37 | $instance->setup(); |
| 38 | } |
| 39 | |
| 40 | return $instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get plugin version |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function get_version(): string { |
| 49 | return ADVADS_VERSION; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Bootstrap plugin. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | private function setup(): void { |
| 58 | $this->define_constants(); |
| 59 | $this->includes(); |
| 60 | |
| 61 | /** |
| 62 | * Old loading strategy |
| 63 | * |
| 64 | * TODO: need to remove it in future. |
| 65 | */ |
| 66 | |
| 67 | // Load public functions (might be used by modules, other plugins or theme). |
| 68 | require_once ADVADS_ABSPATH . 'includes/functions.php'; |
| 69 | require_once ADVADS_ABSPATH . 'includes/cap_map.php'; |
| 70 | |
| 71 | // Public-Facing and Core Functionality. |
| 72 | \Advanced_Ads::get_instance(); |
| 73 | \Advanced_Ads_ModuleLoader::loadModules( ADVADS_ABSPATH . 'modules/' ); // enable modules, requires base class. |
| 74 | |
| 75 | // Dashboard and Administrative Functionality. |
| 76 | if ( is_admin() ) { |
| 77 | \Advanced_Ads_Admin::get_instance(); |
| 78 | } |
| 79 | |
| 80 | add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], -1 ); |
| 81 | $this->load(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * When WordPress has loaded all plugins, trigger the `advanced-ads-loaded` hook. |
| 86 | * |
| 87 | * @since 1.47.0 |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | public function on_plugins_loaded(): void { |
| 92 | /** |
| 93 | * Action trigger after loading finished. |
| 94 | * |
| 95 | * @since 1.47.0 |
| 96 | */ |
| 97 | do_action( 'advanced-ads-loaded' ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Define Advanced Ads constant |
| 102 | * |
| 103 | * @return void |
| 104 | */ |
| 105 | private function define_constants(): void { |
| 106 | $this->define( 'ADVADS_ABSPATH', dirname( ADVADS_FILE ) . '/' ); |
| 107 | $this->define( 'ADVADS_PLUGIN_BASENAME', plugin_basename( ADVADS_FILE ) ); |
| 108 | $this->define( 'ADVADS_BASE_URL', plugin_dir_url( ADVADS_FILE ) ); |
| 109 | $this->define( 'ADVADS_SLUG', 'advanced-ads' ); |
| 110 | |
| 111 | // Deprecated Constants. |
| 112 | /** |
| 113 | * ADVADS_BASE |
| 114 | * |
| 115 | * @deprecated 1.47.0 use ADVADS_PLUGIN_BASENAME now. |
| 116 | */ |
| 117 | define( 'ADVADS_BASE', ADVADS_PLUGIN_BASENAME ); |
| 118 | |
| 119 | /** |
| 120 | * ADVADS_BASE_PATH |
| 121 | * |
| 122 | * @deprecated 1.47.0 use ADVADS_ABSPATH now. |
| 123 | */ |
| 124 | define( 'ADVADS_BASE_PATH', ADVADS_ABSPATH ); |
| 125 | |
| 126 | /** |
| 127 | * ADVADS_BASE_DIR |
| 128 | * |
| 129 | * @deprecated 1.47.0 Avoid global declaration of the constant used exclusively in `load_text_domain` function; use localized declaration instead. |
| 130 | */ |
| 131 | define( 'ADVADS_BASE_DIR', dirname( ADVADS_PLUGIN_BASENAME ) ); |
| 132 | |
| 133 | /** |
| 134 | * ADVADS_URL |
| 135 | * |
| 136 | * @deprecated 1.47.0 Deprecating the constant in favor of using the direct URL to circumvent costly `esc_url` function; please update code accordingly. |
| 137 | */ |
| 138 | define( 'ADVADS_URL', 'https://wpadvancedads.com/' ); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Includes core files used in admin and on the frontend. |
| 143 | * |
| 144 | * @return void |
| 145 | */ |
| 146 | private function includes(): void { |
| 147 | $this->register_initializer( Install::class ); |
| 148 | $this->register_integration( Entities::class ); |
| 149 | $this->register_integration( Assets_Registry::class ); |
| 150 | $this->register_integration( Framework\JSON::class, 'json', [ 'advancedAds' ] ); |
| 151 | $this->register_integration( Groups\Manager::class, 'group_manager' ); |
| 152 | |
| 153 | // Only in admin area. |
| 154 | if ( is_admin() ) { |
| 155 | $this->register_integration( Admin\Action_Links::class ); |
| 156 | $this->register_integration( Admin\Assets::class ); |
| 157 | $this->register_integration( Admin\Header::class ); |
| 158 | $this->register_integration( Admin\TinyMCE::class ); |
| 159 | $this->register_integration( Admin\Admin_Menu::class ); |
| 160 | $this->register_integration( Admin\Page_Quick_Edit::class ); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 |