WP_REST_Server::CREATABLE, 'callback' => [ self::class, 'handle_adblock_status' ], 'permission_callback' => '__return_true', 'args' => [ 'is_blocked' => [ 'required' => true, 'type' => 'boolean', ], ], ] ); } /** * Enqueues the necessary scripts for the adblocker counter. * * @return void */ public static function enqueue_scripts(): void { Assets::get()->enqueue_script( 'adblocker-check' ); Assets::get()->enqueue_script( 'advertisement' ); wp_enqueue_script( 'adpresso-adblocker-counter', FrontendAssetOptimizer::url( 'modules/adblocker-counter/assets/js/adblocker-counter.js' ), [ 'adpresso-adblocker-check', 'adpresso-advertisement' ], '1.0', true ); wp_localize_script( 'adpresso-adblocker-counter', 'adpresso_adblocker_counter_config', [ 'rest_url' => esc_url_raw( rest_url( 'adpresso/v1/adblock-count' ) ), ] ); } /** * Handles the REST request to count adblocker status. * * @param WP_REST_Request $request * * @return WP_REST_Response */ public static function handle_adblock_status( WP_REST_Request $request ): WP_REST_Response { $CrawlerDetect = new CrawlerDetect(); if ( $CrawlerDetect->isCrawler() ) { return rest_ensure_response( 'Bot skipped.' ); } $is_blocked = $request->get_param( 'is_blocked' ); $option = $is_blocked ? self::OPTION_BLOCKER : self::OPTION_NON_BLOCKER; $count = (int) Settings::get_direct_option( $option, 0 ); Settings::update_direct_option( $option, ++$count, 'absint' ); return rest_ensure_response( 'Counted.' ); } /** * Displays the adblocker counter statistics in the admin area. * * @return void */ public static function show_adblocker_counter_stats(): void { $blocked = Settings::get_direct_option( self::OPTION_BLOCKER, 0 ); $unblocked = Settings::get_direct_option( self::OPTION_NON_BLOCKER, 0 ); $total = $blocked + $unblocked; $percentage = $total > 0 ? round( ( $blocked / $total ) * 100, 2 ) : 0; ?>
without AdBlocker', 'adpresso' ) ); ?>
with AdBlocker', 'adpresso' ) ); ?>
%