abstracts
9 months ago
admin
6 months ago
ads
6 months ago
compatibility
9 months ago
crons
1 year ago
frontend
11 months ago
groups
1 year ago
importers
1 year ago
installation
1 year ago
interfaces
1 year ago
placements
1 year ago
rest
1 year ago
traits
1 year ago
utilities
6 months ago
array_ad_conditions.php
1 year ago
cap_map.php
3 years ago
class-assets-registry.php
1 year ago
class-autoloader.php
1 year ago
class-constants.php
1 year ago
class-entities.php
6 months ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
8 months ago
class-post-data.php
10 months ago
class-shortcodes.php
6 months ago
class-upgrades.php
1 year ago
class-widget.php
11 months ago
default-hooks.php
1 year ago
functions-ad.php
1 year ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 year ago
functions-placement.php
1 year ago
functions.php
1 year ago
index.php
2 years ago
load_modules.php
2 years ago
class-plugin.php
341 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\Ads\Ads; |
| 13 | use AdvancedAds\Groups\Groups; |
| 14 | use Advanced_Ads_Admin_Licenses; |
| 15 | use AdvancedAds\Installation\Install; |
| 16 | use AdvancedAds\Placements\Placements; |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | /** |
| 21 | * Plugin. |
| 22 | * |
| 23 | * Containers: |
| 24 | * |
| 25 | * @property Shortcodes $shortcodes Shortcodes handler. |
| 26 | * @property Assets_Registry $registry Assets registry. |
| 27 | * @property Framework\JSON $json JSON handler. |
| 28 | * @property Admin\Admin_Menu $screens Admin screens. |
| 29 | * @property Frontend\Ad_Renderer $renderer Ads renderer. |
| 30 | * @property Frontend\Manager $frontend Frontend manager. |
| 31 | * @property Importers\Manager $importers Importers manager. |
| 32 | */ |
| 33 | class Plugin extends Framework\Loader { |
| 34 | |
| 35 | use Traits\Extras; |
| 36 | |
| 37 | /** |
| 38 | * The ads container |
| 39 | * |
| 40 | * @var Ads |
| 41 | */ |
| 42 | public $ads = null; |
| 43 | |
| 44 | /** |
| 45 | * The groups container |
| 46 | * |
| 47 | * @var Groups |
| 48 | */ |
| 49 | public $groups = null; |
| 50 | |
| 51 | /** |
| 52 | * The placements container |
| 53 | * |
| 54 | * @var Placements |
| 55 | */ |
| 56 | public $placements = null; |
| 57 | |
| 58 | /** |
| 59 | * Modules manager |
| 60 | * |
| 61 | * @var Modules |
| 62 | */ |
| 63 | public $modules = null; |
| 64 | |
| 65 | /** |
| 66 | * Main instance |
| 67 | * |
| 68 | * Ensure only one instance is loaded or can be loaded. |
| 69 | * |
| 70 | * @return Plugin |
| 71 | */ |
| 72 | public static function get(): Plugin { |
| 73 | static $instance; |
| 74 | |
| 75 | if ( null === $instance ) { |
| 76 | $instance = new Plugin(); |
| 77 | $instance->setup(); |
| 78 | } |
| 79 | |
| 80 | return $instance; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get plugin version |
| 85 | * |
| 86 | * @return string |
| 87 | */ |
| 88 | public function get_version(): string { |
| 89 | return ADVADS_VERSION; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Bootstrap plugin. |
| 94 | * |
| 95 | * @return void |
| 96 | */ |
| 97 | private function setup(): void { |
| 98 | $this->define_constants(); |
| 99 | $this->includes_functions(); |
| 100 | $this->includes(); |
| 101 | $this->includes_rest(); |
| 102 | $this->includes_admin(); |
| 103 | $this->includes_frontend(); |
| 104 | $this->includes_deprecated(); |
| 105 | |
| 106 | /** |
| 107 | * Old loading strategy |
| 108 | * |
| 109 | * TODO: need to remove it in future. |
| 110 | */ |
| 111 | // Public-Facing and Core Functionality. |
| 112 | \Advanced_Ads::get_instance(); |
| 113 | \Advanced_Ads_ModuleLoader::loadModules( ADVADS_ABSPATH . 'modules/' ); // enable modules, requires base class. |
| 114 | |
| 115 | if ( is_admin() ) { |
| 116 | Advanced_Ads_Admin_Licenses::get_instance(); |
| 117 | } |
| 118 | |
| 119 | add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], -1 ); |
| 120 | add_action( 'widgets_init', [ $this, 'register_widgets' ] ); |
| 121 | |
| 122 | // Load it all. |
| 123 | $this->ads->initialize(); |
| 124 | $this->groups->initialize(); |
| 125 | $this->placements->initialize(); |
| 126 | $this->modules->initialize(); |
| 127 | $this->load(); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Register the Advanced Ads classic Widget |
| 132 | * |
| 133 | * @return void |
| 134 | */ |
| 135 | public function register_widgets(): void { |
| 136 | register_widget( '\AdvancedAds\Widget' ); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * When WordPress has loaded all plugins, trigger the `advanced-ads-loaded` hook. |
| 141 | * |
| 142 | * @since 1.47.0 |
| 143 | * |
| 144 | * @return void |
| 145 | */ |
| 146 | public function on_plugins_loaded(): void { |
| 147 | /** |
| 148 | * Action trigger after loading finished. |
| 149 | * |
| 150 | * @since 1.47.0 |
| 151 | */ |
| 152 | do_action( 'advanced-ads-loaded' ); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Define Advanced Ads constant |
| 157 | * |
| 158 | * @return void |
| 159 | */ |
| 160 | private function define_constants(): void { |
| 161 | $this->define( 'ADVADS_ABSPATH', dirname( ADVADS_FILE ) . '/' ); |
| 162 | $this->define( 'ADVADS_PLUGIN_BASENAME', plugin_basename( ADVADS_FILE ) ); |
| 163 | $this->define( 'ADVADS_BASE_URL', plugin_dir_url( ADVADS_FILE ) ); |
| 164 | $this->define( 'ADVADS_SLUG', 'advanced-ads' ); |
| 165 | // name for group & option in settings. |
| 166 | $this->define( 'ADVADS_SETTINGS_ADBLOCKER', 'advanced-ads-adblocker' ); |
| 167 | |
| 168 | // Deprecated Constants. |
| 169 | /** |
| 170 | * ADVADS_BASE |
| 171 | * |
| 172 | * @deprecated 1.47.0 use ADVADS_PLUGIN_BASENAME now. |
| 173 | */ |
| 174 | define( 'ADVADS_BASE', ADVADS_PLUGIN_BASENAME ); |
| 175 | |
| 176 | /** |
| 177 | * ADVADS_BASE_PATH |
| 178 | * |
| 179 | * @deprecated 1.47.0 use ADVADS_ABSPATH now. |
| 180 | */ |
| 181 | define( 'ADVADS_BASE_PATH', ADVADS_ABSPATH ); |
| 182 | |
| 183 | /** |
| 184 | * ADVADS_BASE_DIR |
| 185 | * |
| 186 | * @deprecated 1.47.0 Avoid global declaration of the constant used exclusively in `load_text_domain` function; use localized declaration instead. |
| 187 | */ |
| 188 | define( 'ADVADS_BASE_DIR', dirname( ADVADS_PLUGIN_BASENAME ) ); |
| 189 | |
| 190 | /** |
| 191 | * ADVADS_URL |
| 192 | * |
| 193 | * @deprecated 1.47.0 Deprecating the constant in favor of using the direct URL to circumvent costly `esc_url` function; please update code accordingly. |
| 194 | */ |
| 195 | define( 'ADVADS_URL', 'https://wpadvancedads.com/' ); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Includes core files used in admin and on the frontend. |
| 200 | * |
| 201 | * @return void |
| 202 | */ |
| 203 | private function includes(): void { |
| 204 | $this->ads = new Ads(); |
| 205 | $this->groups = new Groups(); |
| 206 | $this->placements = new Placements(); |
| 207 | $this->modules = new Modules(); |
| 208 | |
| 209 | // Common. |
| 210 | $this->register_initializer( Install::class ); |
| 211 | $this->register_integration( Entities::class ); |
| 212 | $this->register_integration( Assets_Registry::class, 'registry' ); |
| 213 | $this->register_integration( Framework\JSON::class, 'json', [ 'advancedAds' ] ); |
| 214 | $this->register_integration( Compatibility\Compatibility::class ); |
| 215 | $this->register_integration( Compatibility\AAWP::class ); |
| 216 | $this->register_integration( Compatibility\Peepso::class ); |
| 217 | $this->register_integration( Post_Data::class ); |
| 218 | $this->register_integration( Crons\Ads::class ); |
| 219 | $this->register_integration( Shortcodes::class, 'shortcodes' ); |
| 220 | $this->register_integration( Frontend\Debug_Ads::class ); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Includes files used on the frontend. |
| 225 | * |
| 226 | * @return void |
| 227 | */ |
| 228 | private function includes_frontend(): void { |
| 229 | // Early bail!! |
| 230 | if ( is_admin() ) { |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | $this->register_integration( Frontend\Ad_Renderer::class, 'renderer' ); |
| 235 | $this->register_integration( Frontend\Manager::class, 'frontend' ); |
| 236 | $this->register_integration( Frontend\Scripts::class ); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Includes files used in admin. |
| 241 | * |
| 242 | * @return void |
| 243 | */ |
| 244 | private function includes_admin(): void { |
| 245 | // Early bail!! |
| 246 | if ( ! is_admin() ) { |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | $this->register_integration( Compatibility\Capability_Manager::class ); |
| 251 | $this->register_initializer( Upgrades::class ); |
| 252 | $this->register_integration( Admin\Action_Links::class ); |
| 253 | $this->register_integration( Admin\Admin_Menu::class, 'screens' ); |
| 254 | $this->register_integration( Admin\Admin_Notices::class ); |
| 255 | $this->register_integration( Admin\Assets::class ); |
| 256 | $this->register_integration( Admin\Header::class ); |
| 257 | $this->register_integration( Admin\Marketing::class ); |
| 258 | $this->register_integration( Admin\Metabox_Ad::class ); |
| 259 | $this->register_integration( Admin\Metabox_Ad_Settings::class ); |
| 260 | $this->register_integration( Admin\Post_Types::class ); |
| 261 | $this->register_integration( Admin\Screen_Options::class ); |
| 262 | $this->register_integration( Admin\Shortcode_Creator::class ); |
| 263 | $this->register_integration( Admin\TinyMCE::class ); |
| 264 | $this->register_integration( Admin\WordPress_Dashboard::class ); |
| 265 | $this->register_integration( Admin\Quick_Bulk_Edit::class ); |
| 266 | $this->register_integration( Admin\Page_Quick_Edit::class ); |
| 267 | $this->register_integration( Admin\Placement_Quick_Edit::class ); |
| 268 | $this->register_integration( Importers\Manager::class, 'importers' ); |
| 269 | $this->register_integration( Admin\AJAX::class ); |
| 270 | $this->register_integration( Admin\Version_Control::class ); |
| 271 | $this->register_integration( Admin\Upgrades::class ); |
| 272 | $this->register_integration( Admin\Authors::class ); |
| 273 | $this->register_integration( Admin\Settings::class ); |
| 274 | $this->register_integration( Admin\Misc::class ); |
| 275 | $this->register_integration( Admin\Post_List::class ); |
| 276 | $this->register_integration( Admin\Placement\Bulk_Edit::class ); |
| 277 | $this->register_integration( Admin\Addon_Updater::class ); |
| 278 | |
| 279 | if ( ! wp_doing_ajax() ) { |
| 280 | $this->register_integration( Admin\List_Filters::class, 'list_filters' ); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Includes rest api files used in admin and on the frontend. |
| 286 | * |
| 287 | * @return void |
| 288 | */ |
| 289 | private function includes_rest(): void { |
| 290 | $this->register_route( Rest\Groups::class ); |
| 291 | $this->register_route( Rest\Page_Quick_Edit::class ); |
| 292 | $this->register_route( Rest\Placements::class ); |
| 293 | $this->register_route( Rest\OnBoarding::class ); |
| 294 | $this->register_route( Rest\Utilities::class ); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Includes the necessary functions files. |
| 299 | * |
| 300 | * @return void |
| 301 | */ |
| 302 | private function includes_functions(): void { |
| 303 | require_once ADVADS_ABSPATH . 'includes/functions.php'; |
| 304 | require_once ADVADS_ABSPATH . 'includes/functions-core.php'; |
| 305 | require_once ADVADS_ABSPATH . 'includes/functions-conditional.php'; |
| 306 | require_once ADVADS_ABSPATH . 'includes/functions-ad.php'; |
| 307 | require_once ADVADS_ABSPATH . 'includes/functions-group.php'; |
| 308 | require_once ADVADS_ABSPATH . 'includes/functions-placement.php'; |
| 309 | require_once ADVADS_ABSPATH . 'includes/cap_map.php'; |
| 310 | require_once ADVADS_ABSPATH . 'includes/default-hooks.php'; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Includes deprecated files. |
| 315 | * |
| 316 | * @return void |
| 317 | */ |
| 318 | private function includes_deprecated(): void { |
| 319 | require_once ADVADS_ABSPATH . 'deprecated/ad_group.php'; |
| 320 | require_once ADVADS_ABSPATH . 'deprecated/ad_placements.php'; |
| 321 | require_once ADVADS_ABSPATH . 'deprecated/Ad_Repository.php'; |
| 322 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_abstract.php'; |
| 323 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_content.php'; |
| 324 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_dummy.php'; |
| 325 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_group.php'; |
| 326 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_image.php'; |
| 327 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_plain.php'; |
| 328 | require_once ADVADS_ABSPATH . 'deprecated/ad-ajax.php'; |
| 329 | require_once ADVADS_ABSPATH . 'deprecated/ad-debug.php'; |
| 330 | require_once ADVADS_ABSPATH . 'deprecated/ad-expiration.php'; |
| 331 | require_once ADVADS_ABSPATH . 'deprecated/ad-model.php'; |
| 332 | require_once ADVADS_ABSPATH . 'deprecated/ad-select.php'; |
| 333 | require_once ADVADS_ABSPATH . 'deprecated/ad.php'; |
| 334 | require_once ADVADS_ABSPATH . 'deprecated/deprecated-functions.php'; |
| 335 | require_once ADVADS_ABSPATH . 'deprecated/gadsense-dummy.php'; |
| 336 | require_once ADVADS_ABSPATH . 'deprecated/Group_Repository.php'; |
| 337 | require_once ADVADS_ABSPATH . 'deprecated/class-admin.php'; |
| 338 | require_once ADVADS_ABSPATH . 'deprecated/class-advanced-ads-plugin.php'; |
| 339 | } |
| 340 | } |
| 341 |