define_constants(); $this->init_addon(); } public function define_constants() { define( 'ABLOCKS_COOKIE_CONSENT_VERSION', '1.0' ); define( 'ABLOCKS_COOKIE_CONSENT_ADDON_NAME', $this->addon_name ); define( 'ABLOCKS_COOKIE_CONSENT_SETTINGS_NAME', 'ablocks_cookie_consent' ); define( 'ABLOCKS_COOKIE_CONSENT_DIR_PATH', ABLOCKS_ADDONS_DIR_PATH . 'cookie-consent/' ); } public function init_addon() { add_action( "ablocks/addons/activated_{$this->addon_name}", [ $this, 'addon_activation_hook' ] ); if ( ! \ABlocks\Helper::get_addon_active_status( $this->addon_name ) ) { return; } // The admin screen and the recording endpoint are always available; the // gating and the banner only exist on the front end. Ajax::init(); Rest::init(); Record::init(); // Outside the front-end block below: a form can be submitted through the // REST controller or through admin-ajax, and only one of those counts as // the front end. FormConsent::init(); if ( ! is_admin() ) { ConsentMode::init(); Tags::init(); Frontend::init(); // Gating asks whether this request is a feed, and a conditional // query tag has no answer before the query has run. Registering on // `wp` still lands ahead of `template_redirect` and of any script // being printed, so nothing is missed by waiting. add_action( 'wp', function () { Gating::init(); Buffer::init(); } ); } Admin::init(); } public static function init() { static $instance = false; if ( ! $instance ) { $instance = new self(); } return $instance; } /** * Create the consent record table the first time the addon is switched on. * Doing it here rather than in the plugin installer keeps the table out of * sites that never enable the feature. */ public function addon_activation_hook() { Database::create_table(); } }