abstracts
1 year ago
admin
1 year ago
ads
1 year ago
compatibility
1 year ago
crons
1 year ago
frontend
1 year 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
1 year 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
1 year ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
1 year ago
class-post-data.php
1 year ago
class-shortcodes.php
1 year ago
class-upgrades.php
1 year ago
class-widget.php
1 year 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
349 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( 'init', [ $this, 'load_textdomain' ] ); |
| 120 | add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], -1 ); |
| 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 | * When WordPress has loaded all plugins, trigger the `advanced-ads-loaded` hook. |
| 132 | * |
| 133 | * @since 1.47.0 |
| 134 | * |
| 135 | * @return void |
| 136 | */ |
| 137 | public function on_plugins_loaded(): void { |
| 138 | /** |
| 139 | * Action trigger after loading finished. |
| 140 | * |
| 141 | * @since 1.47.0 |
| 142 | */ |
| 143 | do_action( 'advanced-ads-loaded' ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Load the plugin text domain for translation. |
| 148 | * |
| 149 | * @return void |
| 150 | */ |
| 151 | public function load_textdomain(): void { |
| 152 | $locale = get_user_locale(); |
| 153 | $locale = apply_filters( 'plugin_locale', $locale, 'advanced-ads' ); |
| 154 | |
| 155 | unload_textdomain( 'advanced-ads' ); |
| 156 | if ( false === load_textdomain( 'advanced-ads', WP_LANG_DIR . '/plugins/advanced-ads-' . $locale . '.mo' ) ) { |
| 157 | load_textdomain( 'advanced-ads', WP_LANG_DIR . '/advanced-ads/advanced-ads-' . $locale . '.mo' ); |
| 158 | } |
| 159 | |
| 160 | load_plugin_textdomain( 'advanced-ads', false, dirname( ADVADS_PLUGIN_BASENAME ) . '/languages' ); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Define Advanced Ads constant |
| 165 | * |
| 166 | * @return void |
| 167 | */ |
| 168 | private function define_constants(): void { |
| 169 | $this->define( 'ADVADS_ABSPATH', dirname( ADVADS_FILE ) . '/' ); |
| 170 | $this->define( 'ADVADS_PLUGIN_BASENAME', plugin_basename( ADVADS_FILE ) ); |
| 171 | $this->define( 'ADVADS_BASE_URL', plugin_dir_url( ADVADS_FILE ) ); |
| 172 | $this->define( 'ADVADS_SLUG', 'advanced-ads' ); |
| 173 | // name for group & option in settings. |
| 174 | $this->define( 'ADVADS_SETTINGS_ADBLOCKER', 'advanced-ads-adblocker' ); |
| 175 | |
| 176 | // Deprecated Constants. |
| 177 | /** |
| 178 | * ADVADS_BASE |
| 179 | * |
| 180 | * @deprecated 1.47.0 use ADVADS_PLUGIN_BASENAME now. |
| 181 | */ |
| 182 | define( 'ADVADS_BASE', ADVADS_PLUGIN_BASENAME ); |
| 183 | |
| 184 | /** |
| 185 | * ADVADS_BASE_PATH |
| 186 | * |
| 187 | * @deprecated 1.47.0 use ADVADS_ABSPATH now. |
| 188 | */ |
| 189 | define( 'ADVADS_BASE_PATH', ADVADS_ABSPATH ); |
| 190 | |
| 191 | /** |
| 192 | * ADVADS_BASE_DIR |
| 193 | * |
| 194 | * @deprecated 1.47.0 Avoid global declaration of the constant used exclusively in `load_text_domain` function; use localized declaration instead. |
| 195 | */ |
| 196 | define( 'ADVADS_BASE_DIR', dirname( ADVADS_PLUGIN_BASENAME ) ); |
| 197 | |
| 198 | /** |
| 199 | * ADVADS_URL |
| 200 | * |
| 201 | * @deprecated 1.47.0 Deprecating the constant in favor of using the direct URL to circumvent costly `esc_url` function; please update code accordingly. |
| 202 | */ |
| 203 | define( 'ADVADS_URL', 'https://wpadvancedads.com/' ); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Includes core files used in admin and on the frontend. |
| 208 | * |
| 209 | * @return void |
| 210 | */ |
| 211 | private function includes(): void { |
| 212 | $this->ads = new Ads(); |
| 213 | $this->groups = new Groups(); |
| 214 | $this->placements = new Placements(); |
| 215 | $this->modules = new Modules(); |
| 216 | |
| 217 | // Common. |
| 218 | $this->register_initializer( Install::class ); |
| 219 | $this->register_integration( Entities::class ); |
| 220 | $this->register_integration( Assets_Registry::class, 'registry' ); |
| 221 | $this->register_integration( Framework\JSON::class, 'json', [ 'advancedAds' ] ); |
| 222 | $this->register_integration( Compatibility\Compatibility::class ); |
| 223 | $this->register_integration( Compatibility\AAWP::class ); |
| 224 | $this->register_integration( Compatibility\Peepso::class ); |
| 225 | $this->register_integration( Post_Data::class ); |
| 226 | $this->register_integration( Crons\Ads::class ); |
| 227 | $this->register_integration( Shortcodes::class, 'shortcodes' ); |
| 228 | $this->register_integration( Frontend\Debug_Ads::class ); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Includes files used on the frontend. |
| 233 | * |
| 234 | * @return void |
| 235 | */ |
| 236 | private function includes_frontend(): void { |
| 237 | // Early bail!! |
| 238 | if ( is_admin() ) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | $this->register_integration( Frontend\Ad_Renderer::class, 'renderer' ); |
| 243 | $this->register_integration( Frontend\Manager::class, 'frontend' ); |
| 244 | $this->register_integration( Frontend\Scripts::class ); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Includes files used in admin. |
| 249 | * |
| 250 | * @return void |
| 251 | */ |
| 252 | private function includes_admin(): void { |
| 253 | // Early bail!! |
| 254 | if ( ! is_admin() ) { |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | $this->register_integration( Compatibility\Capability_Manager::class ); |
| 259 | $this->register_initializer( Upgrades::class ); |
| 260 | $this->register_integration( Admin\Action_Links::class ); |
| 261 | $this->register_integration( Admin\Admin_Menu::class, 'screens' ); |
| 262 | $this->register_integration( Admin\Admin_Notices::class ); |
| 263 | $this->register_integration( Admin\Assets::class ); |
| 264 | $this->register_integration( Admin\Header::class ); |
| 265 | $this->register_integration( Admin\Marketing::class ); |
| 266 | $this->register_integration( Admin\Metabox_Ad::class ); |
| 267 | $this->register_integration( Admin\Metabox_Ad_Settings::class ); |
| 268 | $this->register_integration( Admin\Post_Types::class ); |
| 269 | $this->register_integration( Admin\Screen_Options::class ); |
| 270 | $this->register_integration( Admin\Shortcode_Creator::class ); |
| 271 | $this->register_integration( Admin\TinyMCE::class ); |
| 272 | $this->register_integration( Admin\WordPress_Dashboard::class ); |
| 273 | $this->register_integration( Admin\Quick_Bulk_Edit::class ); |
| 274 | $this->register_integration( Admin\Page_Quick_Edit::class ); |
| 275 | $this->register_integration( Admin\Placement_Quick_Edit::class ); |
| 276 | $this->register_integration( Importers\Manager::class, 'importers' ); |
| 277 | $this->register_integration( Admin\AJAX::class ); |
| 278 | $this->register_integration( Admin\Version_Control::class ); |
| 279 | $this->register_integration( Admin\Upgrades::class ); |
| 280 | $this->register_integration( Admin\Authors::class ); |
| 281 | $this->register_integration( Admin\Settings::class ); |
| 282 | $this->register_integration( Admin\Misc::class ); |
| 283 | $this->register_integration( Admin\Post_List::class ); |
| 284 | $this->register_integration( Admin\Placement\Bulk_Edit::class ); |
| 285 | |
| 286 | if ( ! wp_doing_ajax() ) { |
| 287 | $this->register_integration( Admin\List_Filters::class, 'list_filters' ); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Includes rest api files used in admin and on the frontend. |
| 293 | * |
| 294 | * @return void |
| 295 | */ |
| 296 | private function includes_rest(): void { |
| 297 | $this->register_route( Rest\Groups::class ); |
| 298 | $this->register_route( Rest\Quick_Edit::class ); |
| 299 | $this->register_route( Rest\Page_Quick_Edit::class ); |
| 300 | $this->register_route( Rest\Placements::class ); |
| 301 | $this->register_route( Rest\OnBoarding::class ); |
| 302 | $this->register_route( Rest\Utilities::class ); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Includes the necessary functions files. |
| 307 | * |
| 308 | * @return void |
| 309 | */ |
| 310 | private function includes_functions(): void { |
| 311 | require_once ADVADS_ABSPATH . 'includes/functions.php'; |
| 312 | require_once ADVADS_ABSPATH . 'includes/functions-core.php'; |
| 313 | require_once ADVADS_ABSPATH . 'includes/functions-conditional.php'; |
| 314 | require_once ADVADS_ABSPATH . 'includes/functions-ad.php'; |
| 315 | require_once ADVADS_ABSPATH . 'includes/functions-group.php'; |
| 316 | require_once ADVADS_ABSPATH . 'includes/functions-placement.php'; |
| 317 | require_once ADVADS_ABSPATH . 'includes/cap_map.php'; |
| 318 | require_once ADVADS_ABSPATH . 'includes/default-hooks.php'; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Includes deprecated files. |
| 323 | * |
| 324 | * @return void |
| 325 | */ |
| 326 | private function includes_deprecated(): void { |
| 327 | require_once ADVADS_ABSPATH . 'deprecated/ad_group.php'; |
| 328 | require_once ADVADS_ABSPATH . 'deprecated/ad_placements.php'; |
| 329 | require_once ADVADS_ABSPATH . 'deprecated/Ad_Repository.php'; |
| 330 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_abstract.php'; |
| 331 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_content.php'; |
| 332 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_dummy.php'; |
| 333 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_group.php'; |
| 334 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_image.php'; |
| 335 | require_once ADVADS_ABSPATH . 'deprecated/ad_type_plain.php'; |
| 336 | require_once ADVADS_ABSPATH . 'deprecated/ad-ajax.php'; |
| 337 | require_once ADVADS_ABSPATH . 'deprecated/ad-debug.php'; |
| 338 | require_once ADVADS_ABSPATH . 'deprecated/ad-expiration.php'; |
| 339 | require_once ADVADS_ABSPATH . 'deprecated/ad-model.php'; |
| 340 | require_once ADVADS_ABSPATH . 'deprecated/ad-select.php'; |
| 341 | require_once ADVADS_ABSPATH . 'deprecated/ad.php'; |
| 342 | require_once ADVADS_ABSPATH . 'deprecated/deprecated-functions.php'; |
| 343 | require_once ADVADS_ABSPATH . 'deprecated/gadsense-dummy.php'; |
| 344 | require_once ADVADS_ABSPATH . 'deprecated/Group_Repository.php'; |
| 345 | require_once ADVADS_ABSPATH . 'deprecated/class-admin.php'; |
| 346 | require_once ADVADS_ABSPATH . 'deprecated/class-advanced-ads-plugin.php'; |
| 347 | } |
| 348 | } |
| 349 |