PluginProbe
Unnotifier — disable admin notices individually / trunk
Unnotifier — disable admin notices individually vtrunk
1.2.10 1.2.9 trunk 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.6 1.2.7 1.2.8
unnotifier / unnotifier.php

unnotifier.php in Unnotifier — disable admin notices individually trunk, at unnotifier.php

159 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Unnotifier — disable admin notices individually
4 * Plugin URI: https://wp-aifactory.com/unnotifier-disable-admin-notices-wordpress-plugin/
5 * Description: Unnotifier disable admin notices individually with options to hide all notices, hide selected notices, or show all notices. Each notice gets a "hide forever" button for individual control.
6 * Version: 1.2.10
7 * Author: Alex Kovalev
8 * Author URI: https://wp-aifactory.com
9 * Text Domain: unnotifier
10 * Domain Path: /languages
11 * Requires at least: 5.0
12 * Tested up to: 7.1
13 * Requires PHP: 7.4
14 * Tested up to PHP: 8.4
15 * License: GPL v2 or later
16 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
17 */
18
19 // Prevent direct access
20 use UNNO\Admin\Settings;
21 use UNNO\Admin\ReviewNoticeManager;
22 use UNNO\Admin\CrossPromoManager;
23 use UNNO\Data\Options;
24
25 if (!defined('ABSPATH')) {
26 exit;
27 }
28
29 // Define plugin constants
30 define('UNNO_VERSION', '1.2.10');
31 define('UNNO_PLUGIN_FILE', __FILE__);
32 define('UNNO_PLUGIN_DIR', plugin_dir_path(__FILE__));
33 define('UNNO_PLUGIN_URL', plugin_dir_url(__FILE__));
34 define('UNNO_PLUGIN_BASENAME', plugin_basename(__FILE__));
35
36 // Debug constant for review notice (set to true to force show notice for testing)
37 if (!defined('UNNO_REVIEW_NOTICE_DEBUG')) {
38 define('UNNO_REVIEW_NOTICE_DEBUG', false);
39 }
40
41 // Debug constant for the AdsDestroyer promotion.
42 if (!defined('UNNO_PROMO_DEBUG')) {
43 define('UNNO_PROMO_DEBUG', false);
44 }
45
46 // PSR-4 Autoloader for UNNO namespace
47 spl_autoload_register(function ($class) {
48 // Only handle classes in UNNO namespace
49 if (strpos($class, 'UNNO\\') !== 0) {
50 return;
51 }
52
53 // Convert namespace to file path according to PSR-4
54 $class_path = str_replace('UNNO\\', '', $class);
55 $class_path = str_replace('\\', DIRECTORY_SEPARATOR, $class_path);
56
57 // Build the full file path
58 $file = UNNO_PLUGIN_DIR . 'src' . DIRECTORY_SEPARATOR . $class_path . '.php';
59
60 // Load the file if it exists
61 if (file_exists($file)) {
62 require_once $file;
63 }
64 });
65
66 add_action('init', function () {
67 load_textdomain('unnotifier', UNNO_PLUGIN_DIR . 'languages/' . get_locale() . '.mo');
68
69 Options::instance();
70 Settings::init();
71
72 // Initialize review notice manager
73 $review_notice_manager = new ReviewNoticeManager();
74 $review_notice_manager->init();
75
76 // Initialize AdsDestroyer cross-promotion.
77 $cross_promo_manager = new CrossPromoManager();
78 $cross_promo_manager->init();
79 });
80
81 // Enqueue admin scripts and styles
82 add_action('admin_enqueue_scripts', function ($hook) {
83 // Load CSS on all admin pages where notices appear
84 if (strpos($hook, 'admin') !== false) {
85 // Enqueue admin CSS
86 wp_enqueue_style(
87 'unnotifier-admin',
88 UNNO_PLUGIN_URL . 'assets/css/admin.css',
89 [],
90 UNNO_VERSION
91 );
92 }
93
94 // Common AJAX localization data
95 $ajax_localization = [
96 'ajax_url' => admin_url('admin-ajax.php'),
97 'nonce' => wp_create_nonce('unno_ajax_nonce'),
98 'hide_text' => __('Hide notice', 'unnotifier'),
99 'hide_me_text' => __('Hide for me', 'unnotifier'),
100 'hide_all_text' => __('Hide for all', 'unnotifier'),
101 'restoring_text' => __('Restoring...', 'unnotifier'),
102 'restore_error_text' => __('Failed to restore notice. Please try again.', 'unnotifier'),
103 'restore_success_text' => __('Notice restored successfully.', 'unnotifier'),
104 'debug' => Options::instance()->get('debug', false)
105 ];
106
107 // Load JS on all admin pages where notices appear
108 if (strpos($hook, 'admin') !== false) {
109 // Enqueue admin JS
110 wp_enqueue_script(
111 'unnotifier-admin',
112 UNNO_PLUGIN_URL . 'assets/js/admin.js',
113 ['jquery'],
114 UNNO_VERSION,
115 true
116 );
117
118 // Localize script with AJAX data
119 wp_localize_script('unnotifier-admin', 'unno_ajax', $ajax_localization);
120 }
121
122 // Load settings-specific JS only on settings page
123 if ($hook === 'settings_page_unnotifier') {
124 wp_enqueue_script(
125 'unnotifier-admin-settings',
126 UNNO_PLUGIN_URL . 'assets/js/admin-settings.js',
127 ['jquery'],
128 UNNO_VERSION,
129 true
130 );
131
132 // Localize settings script with AJAX data
133 wp_localize_script('unnotifier-admin-settings', 'unno_ajax', $ajax_localization);
134 }
135 });
136
137 \UNNO\Core\Notices::instance();
138
139 // Wrapper functions for activation/deactivation hooks
140 if (!function_exists('unno_activate_hook')) {
141 function unno_activate_hook()
142 {
143 Options::instance()->set_defaults();
144
145 // Set activation time for review notice if not already set
146 if (!get_option('unno_activation_time')) {
147 update_option('unno_activation_time', time());
148 }
149 }
150 }
151 if (!function_exists('unno_deactivate_hook')) {
152 function unno_deactivate_hook()
153 {
154
155 }
156 }
157 register_activation_hook(__FILE__, 'unno_activate_hook');
158 register_deactivation_hook(__FILE__, 'unno_deactivate_hook');
159