register_hooks(); // Warning if not enabled if (get_option('_ad_block_guard_enable') !== 'yes') { // Show admin notice $this->ad_block_guard_admin_notice( __('AdBlock Guard is currently disabled globally. Enable it under [General Options]. Overlays can be enabled and disabled per Role as needed.', 'ad-block-guard'), 'warning' ); } else { // make sure atleast one detection method is chosen if (empty(get_option('_ad_block_guard_fast_detection')) && empty(get_option('_ad_block_guard_network_detection')) && empty(get_option('_ad_block_guard_remote_detection'))) { $this->ad_block_guard_admin_notice( __('You must enable atleast one detection method in [General Options] or detection can never occur.', 'ad-block-guard'),'error'); } } } private function register_hooks() { // Enqueue admin scripts and styles add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); } public function enqueue_admin_scripts() { $screen = get_current_screen(); if ($screen && strpos($screen->id, 'ad_block_guard_settings') !== false) { // Enqueue the main admin JS script wp_enqueue_script( 'ad_block_guard_admin_js_linking', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/admin-linking.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); // Enqueue the main admin JS script wp_enqueue_script( 'ad_block_guard_admin_js', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/admin.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); // Enqueue the main admin JS script wp_enqueue_script( 'ad_block_guard_admin_js_notices', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/admin-notices.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); // Enqueue the validation admin JS script with a unique handle wp_enqueue_script( 'ad_block_guard_admin_validation_js', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/admin-validation.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); // Load Thickbox add_thickbox(); // Demo removal of header and navigation for demo wp_enqueue_script( 'ad_block_guard_admin_js_demo', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/demo.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); // check versions of plugin if (LicenseChecker::getInstance()->isLicenseValid()) $this->enableVersion(); if (AD_BLOCK_GUARD_IS_FREE && (!defined('AD_BLOCK_GUARD_IS_PRO'))) { // Enqueue the admin JS script for the free version wp_enqueue_script( 'ad_block_guard_free_js', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/js/free.js', ['wp-i18n'], // Dependencies AD_BLOCK_GUARD_VERSION, true ); } } // Localize the script with translatable string wp_localize_script('ad_block_guard_admin_js', 'customAdminData', array( 'proFeatureMessage' => __('This is a pro feature', 'ad-block-guard') )); // Add Css wp_enqueue_style( 'ad_block_guard_admin_css', AD_BLOCK_GUARD_PLUGIN_URL . 'assets/css/admin.css', [], AD_BLOCK_GUARD_VERSION ); } public function ad_block_guard_admin_notice($message, $type = 'warning', $dismissible = false) { add_action('admin_notices', function () use ($message, $type, $dismissible) { // Ensure the type is one of the allowed values $allowed_types = ['warning', 'error', 'info', 'success']; if (!in_array($type, $allowed_types)) { $type = 'warning'; // Default to 'warning' if an invalid type is provided } // Capitalize the first letter of the type for display $type_display = ucfirst($type); // Check if we are on one of the plugin's admin pages $screen = get_current_screen(); // Determine the class based on whether the notice is dismissible $class = $dismissible ? 'is-dismissible' : ''; if ($screen && isset($screen->id) && ( $screen->id === 'toplevel_page_ad_block_guard_settings' // || $screen->id === 'ad-block-guard-settings_page_ad_block_guard_license_key' || $screen->id === 'ad-block-guard-settings_page_ad_block_guard_demo_page' || $screen->id === 'ad-block-guard-settings_page_ad_block_guard_review' || $screen->id === 'ad-block-guard-settings_page_ad_block_guard_help' )) { // Output the notice with the message echo sprintf( '

%3$s: %4$s

', esc_attr($type), esc_html($class), esc_html($type_display), wp_kses_post($message) ); } }); } private function enableVersion() { if (!defined('AD_BLOCK_GUARD_IS_PRO')) define( 'AD_BLOCK_GUARD_IS_PRO', true); } }