'41004', 'slug' => 'adqiro-ad-blocker-detector', 'premium_slug' => 'adqiro-ad-blocker-detector-pro', 'type' => 'plugin', 'public_key' => 'pk_7f1a93762a965ff40890e95d03583', 'is_premium' => false, 'premium_suffix' => 'Pro', 'has_addons' => false, 'has_paid_plans' => true, 'is_org_compliant' => true, 'menu' => array( 'slug' => 'adqiro-ad-blocker-detector', 'support' => false, ), 'is_live' => true, ) ); } return $adqiro_fs; } adqiro_fs(); do_action( 'adqiro_fs_loaded' ); } if ( function_exists( 'adqiro_fs' ) ) { adqiro_fs()->set_basename( false, __FILE__ ); adqiro_fs()->add_filter( 'plugin_icon', static function ( $default_icon = false ) { $icon = __DIR__ . '/assets/plugin-logo.png'; return ( is_readable( $icon ) ? $icon : $default_icon ); } ); } final class Adqiro_Plugin { const VERSION = '3.1.1'; const OPTION = 'adqiro_settings'; const SLUG = 'adqiro-ad-blocker-detector'; const MAX_TITLE_LENGTH = 160; const MAX_MESSAGE_LENGTH = 1000; const MAX_BUTTON_LENGTH = 120; const MAX_EXCLUSIONS = 40; /** * Initialize hooks. */ public function __construct() { add_action( 'wp_enqueue_scripts', array($this, 'enqueue_frontend') ); add_action( 'wp_footer', array($this, 'render_overlay') ); add_action( 'admin_menu', array($this, 'admin_menu') ); add_action( 'admin_init', array($this, 'register_settings') ); add_action( 'admin_enqueue_scripts', array($this, 'admin_assets') ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'action_links') ); } /** * Core settings only. Premium-only keys are added by the premium module. * * @return array */ public function defaults() { return array( 'enabled' => 1, 'title' => 'Please disable your ad blocker', 'message' => 'Ads help support this website. Please allow ads for this site and reload the page to continue.', 'button' => 'I disabled it — reload page', 'allow_logged_in_admins' => 1, 'excluded_paths' => '', ); } /** * Get normalized settings. * * @return array */ public function get_settings() { $stored = get_option( self::OPTION, array() ); if ( !is_array( $stored ) ) { $stored = array(); } $settings = wp_parse_args( $stored, $this->defaults() ); $settings['enabled'] = ( !empty( $settings['enabled'] ) ? 1 : 0 ); $settings['allow_logged_in_admins'] = ( !empty( $settings['allow_logged_in_admins'] ) ? 1 : 0 ); $settings['title'] = $this->limit_text( $settings['title'], self::MAX_TITLE_LENGTH ); $settings['message'] = $this->limit_textarea( $settings['message'], self::MAX_MESSAGE_LENGTH ); $settings['button'] = $this->limit_text( $settings['button'], self::MAX_BUTTON_LENGTH ); $settings['excluded_paths'] = $this->sanitize_excluded_paths( $settings['excluded_paths'] ); /** * Allow premium code or third-party extensions to add normalized settings. */ return apply_filters( 'adqiro_settings', $settings, $stored, $this ); } /** * Add plugin list links. * * @param array $links Existing links. * @return array */ public function action_links( $links ) { $settings_url = admin_url( 'admin.php?page=' . self::SLUG ); array_unshift( $links, '' . esc_html__( 'Settings', 'adqiro-ad-blocker-detector' ) . '' ); $pro_active = (bool) apply_filters( 'adqiro_is_pro_active', false ); if ( function_exists( 'adqiro_fs' ) && !$pro_active ) { $links[] = '' . esc_html__( 'Upgrade to Pro', 'adqiro-ad-blocker-detector' ) . ''; } return $links; } /** * Whether the detector should run for the current request. * * @param array|null $settings Settings override. * @return bool */ public function should_run( $settings = null ) { if ( is_admin() || wp_doing_ajax() || is_feed() ) { return false; } $settings = ( is_array( $settings ) ? $settings : $this->get_settings() ); if ( empty( $settings['enabled'] ) ) { return false; } if ( !empty( $settings['allow_logged_in_admins'] ) && current_user_can( 'manage_options' ) ) { return false; } if ( $this->is_current_path_excluded( $settings['excluded_paths'] ) ) { return false; } return true; } /** * Enqueue public assets. */ public function enqueue_frontend() { $settings = $this->get_settings(); if ( !$this->should_run( $settings ) ) { return; } $base_url = plugin_dir_url( __FILE__ ); wp_enqueue_style( 'adqiro-frontend', $base_url . 'assets/frontend.css', array(), self::VERSION ); $runtime_dependencies = apply_filters( 'adqiro_runtime_dependencies', array(), $settings, $this ); if ( !is_array( $runtime_dependencies ) ) { $runtime_dependencies = array(); } wp_enqueue_script( 'adqiro-runtime', $base_url . 'assets/frontend.js', array_values( array_unique( array_map( 'sanitize_key', $runtime_dependencies ) ) ), self::VERSION, true ); $config = array( 'englishTitle' => $settings['title'], 'englishMessage' => $settings['message'], 'englishButton' => $settings['button'], 'controlProbe' => $base_url . 'assets/neutral-probe.js', 'adProbes' => array( array( 'url' => $base_url . 'assets/ad_banner.js', 'global' => '__ADQIRO_AD1__', ), array( 'url' => $base_url . 'assets/ads/banner.js', 'global' => '__ADQIRO_AD2__', ), array( 'url' => $base_url . 'assets/advertisement.js', 'global' => '__ADQIRO_AD3__', ), array( 'url' => $base_url . 'assets/pagead.js', 'global' => '__ADQIRO_AD4__', ) ), 'controlGlobal' => '__ADQIRO_CONTROL__', ); /** * Premium code can extend runtime behavior. The free package contains no * implementation of premium features. */ $config = apply_filters( 'adqiro_frontend_config', $config, $settings, $this ); wp_localize_script( 'adqiro-runtime', 'ADQIRO_DATA', $config ); /** Allow premium code to enqueue the selected premium theme. */ do_action( 'adqiro_enqueue_frontend', $settings, $this ); } /** * Render the blocker dialog. */ public function render_overlay() { $settings = $this->get_settings(); if ( !$this->should_run( $settings ) ) { return; } $theme = apply_filters( 'adqiro_theme', 'classic-light', $settings, $this ); $theme = sanitize_html_class( $theme ); if ( '' === $theme ) { $theme = 'classic-light'; } $style_vars = array('--adqiro-overlay:rgba(226,232,240,.72)'); $style_vars = apply_filters( 'adqiro_overlay_style_vars', $style_vars, $settings, $this ); $style_vars = array_filter( (array) $style_vars, static function ( $value ) { return is_string( $value ) && preg_match( '/^--adqiro-[a-z0-9-]+:[^;]{1,120}$/i', $value ); } ); $inline_style = implode( ';', $style_vars ); if ( '' !== $inline_style ) { $inline_style .= ';'; } $overlay_classes = array('adqiro-overlay', 'adqiro-theme-' . $theme); $overlay_classes = apply_filters( 'adqiro_overlay_classes', $overlay_classes, $settings, $this ); $overlay_classes = array_map( 'sanitize_html_class', (array) $overlay_classes ); $overlay_classes = array_values( array_filter( array_unique( $overlay_classes ) ) ); $allow_continue = (bool) apply_filters( 'adqiro_allow_continue', true, $settings, $this ); ?> */ private function available_languages() { $languages = array( 'en' => array( 'label' => 'English', 'flag' => '🇺🇸', ), 'ru' => array( 'label' => 'Русский', 'flag' => '🇷🇺', ), ); $languages = apply_filters( 'adqiro_available_languages', $languages, $this ); return ( is_array( $languages ) ? $languages : array( 'en' => array( 'label' => 'English', 'flag' => '🇺🇸', ), 'ru' => array( 'label' => 'Русский', 'flag' => '🇷🇺', ), ) ); } /** * Render one language button. * * @param string $code Language code. * @param string $label Label. * @param string $flag Flag emoji. */ private function render_language_button( $code, $label, $flag ) { ?>
'array', 'sanitize_callback' => array($this, 'sanitize'), 'default' => array(), ) ); } /** * Sanitize the core settings. Premium module adds its own values via filter. * * @param mixed $input Raw input. * @return array */ public function sanitize( $input ) { if ( !current_user_can( 'manage_options' ) ) { return $this->get_settings(); } if ( !is_array( $input ) ) { $input = array(); } $clean = array( 'enabled' => ( !empty( $input['enabled'] ) ? 1 : 0 ), 'title' => $this->limit_text( ( isset( $input['title'] ) ? $input['title'] : '' ), self::MAX_TITLE_LENGTH ), 'message' => $this->limit_textarea( ( isset( $input['message'] ) ? $input['message'] : '' ), self::MAX_MESSAGE_LENGTH ), 'button' => $this->limit_text( ( isset( $input['button'] ) ? $input['button'] : '' ), self::MAX_BUTTON_LENGTH ), 'allow_logged_in_admins' => ( !empty( $input['allow_logged_in_admins'] ) ? 1 : 0 ), 'excluded_paths' => $this->sanitize_excluded_paths( ( isset( $input['excluded_paths'] ) ? $input['excluded_paths'] : '' ) ), ); /** Premium package can sanitize and append premium-only settings here. */ $clean = apply_filters( 'adqiro_sanitize_settings', $clean, $input, $this ); // Preserve extension-owned keys when their module is temporarily inactive. $existing = get_option( self::OPTION, array() ); if ( is_array( $existing ) ) { foreach ( $existing as $key => $value ) { if ( !array_key_exists( $key, $clean ) && !array_key_exists( $key, $this->defaults() ) ) { $clean[$key] = $value; } } } return $clean; } /** * Load settings-page assets. * * @param string $hook Admin page hook. */ public function admin_assets( $hook ) { if ( 'toplevel_page_' . self::SLUG !== $hook ) { return; } $base_url = plugin_dir_url( __FILE__ ); wp_enqueue_style( 'adqiro-admin', $base_url . 'assets/admin.css', array(), self::VERSION ); wp_enqueue_script( 'adqiro-admin', $base_url . 'assets/admin.js', array(), self::VERSION, true ); do_action( 'adqiro_admin_assets', $this ); } /** * Render settings screen. Free UI is fully functional and contains no locked * premium controls. Premium controls are injected only by the premium package. */ public function settings_page() { if ( !current_user_can( 'manage_options' ) ) { return; } $settings = $this->get_settings(); $pro_active = (bool) apply_filters( 'adqiro_is_pro_active', false ); ?>

admin_switch_row( 'enabled', __( 'Enable ad-blocker detection', 'adqiro-ad-blocker-detector' ), __( 'Show the notice when multiple detection signals indicate that ads are being blocked.', 'adqiro-ad-blocker-detector' ), $settings['enabled'] ); ?> admin_switch_row( 'allow_logged_in_admins', __( 'Bypass for administrators', 'adqiro-ad-blocker-detector' ), __( 'Do not show the notice while you are logged in with administrator permissions.', 'adqiro-ad-blocker-detector' ), $settings['allow_logged_in_admins'] ); ?>

= self::MAX_EXCLUSIONS ) { break; } } return implode( "\n", array_keys( $clean ) ); } /** * Check whether the current front-end request matches an excluded prefix. * * @param string $excluded_paths Newline-delimited path prefixes. * @return bool */ private function is_current_path_excluded( $excluded_paths ) { if ( '' === trim( (string) $excluded_paths ) ) { return false; } $request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '/' ); $request_path = wp_parse_url( $request_uri, PHP_URL_PATH ); if ( !is_string( $request_path ) || '' === $request_path ) { $request_path = '/'; } $patterns = preg_split( '/\\r\\n|\\r|\\n/', $excluded_paths ); if ( !is_array( $patterns ) ) { return false; } foreach ( $patterns as $pattern ) { $pattern = trim( $pattern ); if ( '' !== $pattern && 0 === strpos( $request_path, $pattern ) ) { return true; } } return false; } } $adqiro_plugin = new Adqiro_Plugin(); // The Freemius preprocessor removes this entire block from the generated free package. if ( function_exists( 'adqiro_fs' ) && adqiro_fs()->can_use_premium_code__premium_only() ) { require_once __DIR__ . '/includes/class-adqiro-pro__premium_only.php'; Adqiro_Pro::boot( $adqiro_plugin ); } /** * Remove plugin-owned options after Freemius has recorded an uninstall event. */ function adqiro_after_uninstall_cleanup() { delete_option( Adqiro_Plugin::OPTION ); } if ( function_exists( 'adqiro_fs' ) ) { adqiro_fs()->add_action( 'after_uninstall', 'adqiro_after_uninstall_cleanup' ); }