hooks(); } return self::$instance; } /** * @return string */ public function get_id(): string { return 'adblocker_counter'; } /** * Register hooks. */ private function hooks(): void { add_filter( 'adpresso_adblocker_tab_sections', [ $this, 'add_section' ] ); add_filter( 'adpresso_adblocker_tab_options', [ $this, 'add_options' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] ); } /** * Adds a section to the Adblocker tab. * * @param $sections * * @return array */ public function add_section( $sections ): array { $sections['adblocker-counter'] = [ 'title' => __( 'AdBlocker Counter', 'adpresso' ), 'description' => '', 'controlled_by' => '', 'initially_open' => true, ]; return $sections; } /** * Adds options to the Adblocker tab. * * @param $options * * @return array */ public function add_options( $options ): array { $options[ 'enable_module_' . $this->get_id() ] = [ 'type' => 'toggle', 'label' => __( 'Enable AdBlocker Counter', 'adpresso' ), 'description' => __( 'Monitor the share of your visitors with an active ad blocker.', 'adpresso' ), 'default' => 0, 'section' => 'adblocker-counter', ]; return $options; } /** * Enqueue the admin scripts for the ads.txt module. * * @return void */ public static function enqueue_admin_scripts(): void { $params = Params::get(); $page = $params->getKey( 'page' ); $tab = $params->getKey( 'tab' ); if ( $page !== 'adpresso' || $tab !== 'adblocker' ) { return; } wp_enqueue_script( 'adpresso-adblocker-counter', ADPRESSO_BASE_URL . 'modules/adblocker-counter/assets/js/backend.js', [ 'adpresso-accordion-fields' ], ADPRESSO_VERSION, true ); } }