PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / admin / options.php
disable-admin-notices / admin Last commit date
ajax 5 months ago assets 5 months ago pages 4 months ago boot.php 5 months ago class-page-basic.php 5 months ago options.php 5 months ago
options.php
272 lines
1 <?php
2 /**
3 * Регистрируем поля Html формы в Clearfy на странице "Подолнительно". Если этот плагин загружен, как отдельный плагин
4 * то поля будет зарегистрированы для страницы общи�
5 настроек этого плагина.
6 *
7 * Github: https://github.com/alexkovalevv
8 *
9 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
10 * @copyright (c) 2018 Webraftic Ltd
11 * @version 1.0
12 */
13
14 // Exit if accessed directly
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Регистрируем поля Html формы с настройками плагина.
21 *
22 * Эта функция используется для общей страницы настроек текущего плагина,
23 * а также для раширения настроек в плагине Clearfy.
24 *
25 * @return array Возвращает группу зарегистрируемы�
26 опций
27 * @since 1.0
28 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
29 */
30 function wbcr_dan_get_plugin_options() {
31 $options = [];
32
33 $options[] = [
34 'type' => 'html',
35 'html' => '<div class="wbcr-factory-page-group-header">' . '<strong>' . __( 'Admin Notifications and Update Notices', 'disable-admin-notices' ) . '</strong>' . '<p>' . __( 'Manage how plugin, theme, and WordPress update notices are displayed in the admin area to reduce distractions and keep your workspace organized.', 'disable-admin-notices' ) . '</p>' . '</div>'
36 ];
37
38 $hide_admin_notices_data = [
39 [
40 'not_hide',
41 __( "Show all", 'disable-admin-notices' ),
42 __( 'Displays all admin notices and does not show the “Hide notice permanently” link.', 'disable-admin-notices' )
43 ],
44 [
45 'all',
46 __( 'Hide all', 'disable-admin-notices' ),
47 __( 'Hides all admin notices across the admin area.', 'disable-admin-notices' )
48 ],
49 [
50 'only_selected',
51 __( 'Hide selected', 'disable-admin-notices' ),
52 __( 'Displays a “Hide notice permanently” link on each notice, allowing you to hide individual notices.', 'disable-admin-notices' )
53 ],
54 [
55 'compact_panel',
56 __( 'Show compact panel', 'disable-admin-notices' ),
57 __( 'Groups all admin notices into a single compact panel with counters. Click the panel to view individual notices.', 'disable-admin-notices' )
58 ],
59 ];
60
61 $options[] = [
62 'type' => 'dropdown',
63 'name' => 'hide_admin_notices',
64 'way' => 'buttons',
65 'title' => __( 'Manage admin notices', 'disable-admin-notices' ),
66 'data' => $hide_admin_notices_data,
67 'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'green' ],
68 'hint' => __( 'Controls how plugin notices are displayed.', 'disable-admin-notices' ),
69 'default' => 'only_selected',
70 'cssClass' => [],
71 'events' => [
72 'all' => [
73 'show' => '.factory-control-hide_admin_notices_user_roles',
74 'hide' => '.factory-control-reset_notices_button'
75 ],
76 'only_selected' => [
77 'hide' => '.factory-control-hide_admin_notices_user_roles',
78 'show' => '.factory-control-reset_notices_button'
79 ],
80 'not_hide' => [
81 'hide' => '.factory-control-hide_admin_notices_user_roles, .factory-control-reset_notices_button'
82 ]
83 ]
84 ];
85
86 if ( ! wbcr_dan_is_active_clearfy_component() ) {
87 $options[] = [
88 'type' => 'checkbox',
89 'way' => 'buttons',
90 'name' => 'disable_updates_nags_for_plugins',
91 'title' => __( 'Disable plugin update notifications', 'disable-admin-notices' ),
92 'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'green' ],
93 'hint' => __( 'Disable plugin update notifications (you will not see available plugin updates)', 'disable-admin-notices' ),
94 'cssClass' => array(),
95 'default' => false
96 ];
97
98 $options[] = [
99 'type' => 'checkbox',
100 'way' => 'buttons',
101 'name' => 'disable_updates_nags_for_core',
102 'title' => __( 'Disable WordPress core update notifications', 'disable-admin-notices' ),
103 'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'green' ],
104 'hint' => __( 'Disable WordPress core update notifications (you will not see available WordPress updates)', 'disable-admin-notices' ),
105 'cssClass' => array(),
106 'default' => false
107 ];
108 }
109
110 /*$options[] = array(
111 'type' => 'dropdown',
112 'name' => 'hide_admin_notices_for',
113 'way' => 'buttons',
114 'title' => __('Hide admin notices only for', 'disable-admin-notices'),
115 'data' => array(
116 array(
117 'user',
118 __('Current user', 'disable-admin-notices')
119 ),
120 array(
121 'all_users',
122 __('All users', 'disable-admin-notices')
123 )
124 ),
125 'layout' => array('hint-type' => 'icon', 'hint-icon-color' => 'green'),
126 'hint' => __('Choose who to hide notifications for?', 'disable-admin-notices'),
127 'default' => 'user',
128 'events' => array(
129 'all' => array(
130 'show' => '.factory-control-hide_admin_notices_user_roles',
131 'hide' => '.factory-control-reset_notices_button'
132 ),
133 'only_selected' => array(
134 'hide' => '.factory-control-hide_admin_notices_user_roles',
135 'show' => '.factory-control-reset_notices_button'
136 ),
137 'not_hide' => array(
138 'hide' => '.factory-control-hide_admin_notices_user_roles, .factory-control-reset_notices_button'
139 )
140 )
141 );*/
142
143 $options[] = [
144 'type' => 'checkbox',
145 'way' => 'buttons',
146 'name' => 'show_notices_in_adminbar',
147 'title' => __( 'Show hidden notices in the admin toolbar', 'disable-admin-notices' ),
148 'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'green' ],
149 'hint' => __( 'Displays hidden admin notices in the admin bar for quick access.', 'disable-admin-notices' ),
150 'default' => false
151 ];
152
153 $options[] = [
154 'type' => 'html',
155 'html' => 'wbcr_dan_reset_notices_button'
156 ];
157
158 return $options;
159 }
160
161 function wbcr_dan_is_active_clearfy_component() {
162 if ( defined( 'WCL_PLUGIN_ACTIVE' ) && class_exists( 'WCL_Plugin' ) ) {
163 $deactivate_components = WCL_Plugin::app()->getPopulateOption( 'deactive_preinstall_components', [] );
164 if ( ! in_array( 'disable_notices', $deactivate_components ) ) {
165 return true;
166 }
167 }
168 return false;
169 }
170
171 /**
172 * Расширяем опции html формы страницы "Дополнительно" в плагине Clearfy
173 *
174 * Это необ�
175 одимо для того, чтобы не создавать отдельную страницу в плагине Clearfy, \
176 * с настройками этого плагина, потому что это у�
177 удшает юзабилити.
178 *
179 * @param array $form Массив с группой настроек, страницы "Дополнительно" в плагине Clearfy
180 * @param Wbcr_FactoryPages480_ImpressiveThemplate $page Экземпляр страницы
181 *
182 * @return mixed Отсортированный массив с группой опций
183 */
184 function wbcr_dan_additionally_form_options( $form, $page ) {
185 if ( empty( $form ) ) {
186 return $form;
187 }
188
189 $options = wbcr_dan_get_plugin_options();
190
191 foreach ( array_reverse( $options ) as $option ) {
192 array_unshift( $form[0]['items'], $option );
193 }
194
195 return $form;
196 }
197
198 add_filter( 'wbcr_clr_additionally_form_options', 'wbcr_dan_additionally_form_options', 10, 2 );
199
200 /**
201 * Реализует кнопку сброса скрыты�
202 уведомлений.
203 *
204 * Вы можете выбрать для какой группы пользователей сбросить уведомления.
205 * Эта модикация является не стандартной, поэтому мы не можете реалировать ее
206 * через фреймворк.
207 *
208 * @param @param $html_builder Wbcr_FactoryForms480_Html
209 *
210 * @since 1.0
211 *
212 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
213 */
214 function wbcr_dan_reset_notices_button( $html_builder ) {
215 global $wpdb;
216
217 $form_name = $html_builder->getFormName();
218 $reseted = false;
219
220 if ( isset( $_POST['wbcr_dan_reset_action'] ) ) {
221 check_admin_referer( $form_name, 'wbcr_dan_reset_nonce' );
222 $reset_for_users = WDN_Plugin::app()->request->post( 'wbcr_dan_reset_for_users', 'current_user', true );
223
224 if ( $reset_for_users == 'current_user' ) {
225 delete_user_meta( get_current_user_id(), WDN_Plugin::app()->getOptionName( 'hidden_notices' ) );
226 } else {
227 $meta_key = WDN_Plugin::app()->getOptionName( 'hidden_notices' );
228 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $meta_key ), array( '%s' ) );
229 }
230
231 $reseted = true;
232 }
233
234 ?>
235 <div class="form-group form-group-checkbox factory-control-reset_notices_button">
236 <label for="wbcr_clearfy_reset_notices_button" class="col-sm-4 control-label">
237 <?php echo esc_html__( 'Reset hidden notices for:', 'disable-admin-notices' ); ?>
238 <span class="factory-hint-icon factory-hint-icon-green" data-toggle="factory-tooltip" data-placement="right"
239 title=""
240 data-original-title="<?php echo esc_attr__( 'Restores all previously hidden admin notices.', 'disable-admin-notices' ); ?>">
241 <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAAUUlEQVQIHU3BsQ1AQABA0X/komIrnQHYwyhqQ1hBo9KZRKL9CBfeAwy2ri42JA4mPQ9rJ6OVt0BisFM3Po7qbEliru7m/FkY+TN64ZVxEzh4ndrMN7+Z+jXCAAAAAElFTkSuQmCC"
242 alt="">
243 </span>
244 </label>
245 <div class="control-group col-sm-8">
246 <div class="factory-checkbox factory-from-control-checkbox factory-buttons-way btn-group">
247 <form method="post">
248 <?php wp_nonce_field( $form_name, 'wbcr_dan_reset_nonce' ); ?>
249 <p>
250 <input type="radio" name="wbcr_dan_reset_for_users" value="current_user"
251 checked/> <?php echo esc_html__( 'current user', 'disable-admin-notices' ); ?>
252 </p>
253 <p>
254 <input type="radio" name="wbcr_dan_reset_for_users"
255 value="all"/> <?php echo esc_html__( 'all users', 'disable-admin-notices' ); ?>
256 </p>
257 <p>
258 <input type="submit" name="wbcr_dan_reset_action"
259 value="<?php echo esc_attr__( 'Reset Hidden Notices', 'disable-admin-notices' ); ?>"
260 class="button button-default"/>
261 </p>
262 <?php if ( $reseted ): ?>
263 <div style="color:green;margin-top:5px;"><?php echo esc_html__( 'Hidden notices are successfully reset, now you can see them again!', 'disable-admin-notices' ); ?></div>
264 <?php endif; ?>
265 </form>
266 </div>
267 </div>
268 </div>
269 <?php
270 }
271
272