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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-admin-interface.php
admin-site-enhancements / classes Last commit date
class-activation.php 3 years ago class-admin-interface.php 3 years ago class-common-methods.php 3 years ago class-content-management.php 3 years ago class-custom-code.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-login-logout.php 3 years ago class-optimizations.php 3 years ago class-security.php 3 years ago class-settings-fields-render.php 3 years ago class-settings-sanitization.php 3 years ago class-settings-sections-fields.php 3 years ago class-utilities.php 3 years ago
class-admin-interface.php
495 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 use WP_Admin_Bar ;
6 /**
7 * Class related to Admin Interface features
8 *
9 * @since 1.2.0
10 */
11 class Admin_Interface
12 {
13 /**
14 * Wrapper for admin notices being output on admin screens
15 *
16 * @since 1.2.0
17 */
18 public function admin_notices_wrapper()
19 {
20 echo '<div class="asenha-admin-notices-drawer" style="display:none;"><h2>Admin Notices</h2></div>' ;
21 }
22
23 /**
24 * Admin bar menu item for the hidden admin notices
25 *
26 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/
27 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/
28 * @since 1.2.0
29 */
30 public function admin_notices_menu( WP_Admin_Bar $wp_admin_bar )
31 {
32 $wp_admin_bar->add_menu( array(
33 'id' => 'asenha-hide-admin-notices',
34 'parent' => 'top-secondary',
35 'grou' => null,
36 'title' => 'Notices<span class="asenha-admin-notices-counter" style="opacity:0;">0</span>',
37 'meta' => array(
38 'class' => 'asenha-admin-notices-menu',
39 'title' => 'Click to view hidden admin notices',
40 ),
41 ) );
42 }
43
44 /**
45 * Inline CSS for the admin bar notices menu
46 *
47 * @since 1.2.0
48 */
49 public function admin_notices_menu_inline_css()
50 {
51 wp_add_inline_style( 'admin-bar', '
52
53 #wpadminbar .asenha-admin-notices-counter {
54 box-sizing: border-box;
55 margin: 1px 0 -1px 6px ;
56 padding: 2px 6px 3px 5px;
57 min-width: 18px;
58 height: 18px;
59 border-radius: 50%;
60 background-color: #ca4a1f;
61 color: #fff;
62 font-size: 11px;
63 line-height: 1.6;
64 text-align: center;
65 }
66
67 ' );
68 }
69
70 /**
71 * Hide admin bar on the frontend for the user roles selected
72 *
73 * @since 1.3.0
74 */
75 public function hide_admin_bar_for_roles()
76 {
77 $options = get_option( ASENHA_SLUG_U );
78 $hide_admin_bar = $options['hide_admin_bar'];
79 $for_roles = $options['hide_admin_bar_for'];
80 $current_user = wp_get_current_user();
81 $current_user_roles = (array) $current_user->roles;
82 // single dimensional array of role slugs
83 // User has no role, i.e. logged-out
84
85 if ( count( $current_user_roles ) == 0 ) {
86 return false;
87 // hide admin bar
88 }
89
90 // User has role(s). Do further checks.
91
92 if ( isset( $for_roles ) && count( $for_roles ) > 0 ) {
93 // Assemble single-dimensional array of roles for which admin bar would be hidden
94 $roles_admin_bar_hidden = array();
95 foreach ( $for_roles as $role_slug => $admin_bar_hidden ) {
96 if ( $admin_bar_hidden ) {
97 $roles_admin_bar_hidden[] = $role_slug;
98 }
99 }
100 // Check if any of the current user roles is one for which admin bar should be hidden
101 foreach ( $current_user_roles as $role ) {
102
103 if ( in_array( $role, $roles_admin_bar_hidden ) ) {
104 return false;
105 // hide admin bar
106 }
107
108 }
109 }
110
111 return true;
112 // show admin bar
113 }
114
115 /**
116 * Get dashboard widgets
117 *
118 * @since 4.2.0
119 */
120 public function get_dashboard_widgets()
121 {
122 global $wp_meta_boxes ;
123 $dashboard_widgets = array();
124
125 if ( !isset( $wp_meta_boxes['dashboard'] ) ) {
126 $extra_options = get_option( 'admin_site_enhancements_extra', array() );
127
128 if ( !array_key_exists( 'dashboard_widgets', $extra_options ) ) {
129 require_once ABSPATH . '/wp-admin/includes/dashboard.php';
130 set_current_screen( 'dashboard' );
131 wp_dashboard_setup();
132 }
133
134 }
135
136 if ( isset( $wp_meta_boxes['dashboard'] ) ) {
137 foreach ( $wp_meta_boxes['dashboard'] as $context => $priorities ) {
138 foreach ( $priorities as $priority => $widgets ) {
139 foreach ( $widgets as $widget_id => $data ) {
140 $widget_title = ( isset( $data['title'] ) ? wp_strip_all_tags( preg_replace( '/ <span.*span>/im', '', $data['title'] ) ) : 'Undetectable' );
141 $dashboard_widgets[$widget_id] = array(
142 'id' => $widget_id,
143 'title' => $widget_title,
144 'context' => $context,
145 'priority' => $priority,
146 );
147 }
148 }
149 }
150 }
151 $dashboard_widgets = wp_list_sort(
152 $dashboard_widgets,
153 'title',
154 'ASC',
155 true
156 );
157 return $dashboard_widgets;
158 }
159
160 /**
161 * Disable dashboard widgets
162 *
163 * @since 4.2.0
164 */
165 public function disable_dashboard_widgets()
166 {
167 global $wp_meta_boxes ;
168 // Get list of disabled widgets
169 $options = get_option( ASENHA_SLUG_U, array() );
170 $disabled_dashboard_widgets = $options['disabled_dashboard_widgets'];
171 // Store default widgets in extra options. This will be referenced from settings field.
172 $dashboard_widgets = $this->get_dashboard_widgets();
173 $extra_options = get_option( 'admin_site_enhancements_extra', array() );
174 $extra_options['dashboard_widgets'] = $dashboard_widgets;
175 update_option( 'admin_site_enhancements_extra', $extra_options );
176 // Disable widgets
177 if ( is_array( $disabled_dashboard_widgets ) || is_object( $disabled_dashboard_widgets ) ) {
178 foreach ( $disabled_dashboard_widgets as $disabled_widget_id_context_priority => $is_disabled ) {
179 // e.g. dashboard_activity__normal__core => true/false
180
181 if ( $is_disabled ) {
182 $disabled_widget = explode( '__', $disabled_widget_id_context_priority );
183 $widget_id = $disabled_widget[0];
184 $widget_context = $disabled_widget[1];
185 $widget_priority = $disabled_widget[2];
186 // remove_meta_box( $widget_id, get_current_screen()->base, $widget_context );
187 unset( $wp_meta_boxes['dashboard'][$widget_context][$widget_priority][$widget_id] );
188 }
189
190 }
191 }
192 }
193
194 /**
195 * Modify admin bar menu for Admin Interface >> Hide or Modify Elements feature
196 *
197 * @param $wp_admin_bar object The admin bar.
198 * @since 1.9.0
199 */
200 public function modify_admin_bar_menu( $wp_admin_bar )
201 {
202 $options = get_option( ASENHA_SLUG_U, array() );
203 // Hide WP Logo Menu
204
205 if ( array_key_exists( 'hide_ab_wp_logo_menu', $options ) && $options['hide_ab_wp_logo_menu'] ) {
206 remove_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
207 // priority needs to match default value. Use QM to reference.
208 }
209
210 // Hide Customize Menu
211
212 if ( array_key_exists( 'hide_ab_customize_menu', $options ) && $options['hide_ab_customize_menu'] ) {
213 remove_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 );
214 // priority needs to match default value. Use QM to reference.
215 }
216
217 // Hide Updates Counter/Link
218
219 if ( array_key_exists( 'hide_ab_updates_menu', $options ) && $options['hide_ab_updates_menu'] ) {
220 remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 );
221 // priority needs to match default value. Use QM to reference.
222 }
223
224 // Hide Comments Counter/Link
225
226 if ( array_key_exists( 'hide_ab_comments_menu', $options ) && $options['hide_ab_comments_menu'] ) {
227 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
228 // priority needs to match default value. Use QM to reference.
229 }
230
231 // Hide New Content Menu
232
233 if ( array_key_exists( 'hide_ab_new_content_menu', $options ) && $options['hide_ab_new_content_menu'] ) {
234 remove_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 );
235 // priority needs to match default value. Use QM to reference.
236 }
237
238 // Hide 'Howdy' text
239
240 if ( array_key_exists( 'hide_ab_howdy', $options ) && $options['hide_ab_howdy'] ) {
241 // Remove the whole my account sectino and later rebuild it
242 remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 );
243 $current_user = wp_get_current_user();
244 $user_id = get_current_user_id();
245 $profile_url = get_edit_profile_url( $user_id );
246 $avatar = get_avatar( $user_id, 26 );
247 // size 26x26 pixels
248 $display_name = $current_user->display_name;
249 $class = 'with-avatar';
250 $wp_admin_bar->add_menu( array(
251 'id' => 'my-account',
252 'parent' => 'top-secondary',
253 'title' => $display_name . $avatar,
254 'href' => $profile_url,
255 'meta' => array(
256 'class' => $class,
257 ),
258 ) );
259 }
260
261 }
262
263 /**
264 * Set custom admin menu width
265 *
266 * @since 5.2.0
267 */
268 public function set_custom_menu_width()
269 {
270 $options = get_option( ASENHA_SLUG_U, array() );
271 $custom_width = $options['admin_menu_width'];
272 $wp_version = get_bloginfo( 'version' );
273
274 if ( version_compare( $wp_version, '5', '>' ) ) {
275 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v5-greater.php';
276 } elseif ( version_compare( $wp_version, '4', '>=' ) ) {
277 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v4-greater.php';
278 } else {
279 }
280
281 }
282
283 /**
284 * Render custom menu order
285 *
286 * @param $menu_order array an ordered array of menu items
287 * @link https://developer.wordpress.org/reference/hooks/menu_order/
288 * @since 2.0.0
289 */
290 public function render_custom_menu_order( $menu_order )
291 {
292 global $menu ;
293 $options = get_option( ASENHA_SLUG_U );
294 // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values.
295 $current_menu_order = array();
296 foreach ( $menu as $menu_key => $menu_info ) {
297
298 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
299 $menu_item_id = $menu_info[2];
300 } else {
301 $menu_item_id = $menu_info[5];
302 }
303
304 $current_menu_order[] = array( $menu_item_id, $menu_info[2] );
305 }
306 // Get custom menu order
307 $custom_menu_order = $options['custom_menu_order'];
308 // comma separated
309 $custom_menu_order = explode( ",", $custom_menu_order );
310 // array of menu ID, e.g. menu-dashboard
311 // Return menu order for rendering
312 $rendered_menu_order = array();
313 // Render menu based on items saved in custom menu order
314 foreach ( $custom_menu_order as $custom_menu_item_id ) {
315 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
316 if ( $custom_menu_item_id == $current_menu_item[0] ) {
317 $rendered_menu_order[] = $current_menu_item[1];
318 }
319 }
320 }
321 // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item
322 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
323 if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) {
324 $rendered_menu_order[] = $current_menu_item[1];
325 }
326 }
327 return $rendered_menu_order;
328 }
329
330 /**
331 * Apply custom menu item titles
332 *
333 * @since 2.9.0
334 */
335 public function apply_custom_menu_item_titles()
336 {
337 global $menu ;
338 $options = get_option( ASENHA_SLUG_U );
339 // Get custom menu item titles
340 $custom_menu_titles = $options['custom_menu_titles'];
341 $custom_menu_titles = explode( ',', $custom_menu_titles );
342 foreach ( $menu as $menu_key => $menu_info ) {
343
344 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
345 $menu_item_id = $menu_info[2];
346 } else {
347 $menu_item_id = $menu_info[5];
348 }
349
350 // Get defaul/custom menu item title
351 foreach ( $custom_menu_titles as $custom_menu_title ) {
352 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
353 $custom_menu_title = explode( '__', $custom_menu_title );
354
355 if ( $custom_menu_title[0] == $menu_item_id ) {
356 $menu_item_title = $custom_menu_title[1];
357 // e.g. Code Snippets
358 break;
359 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
360 } else {
361 $menu_item_title = $menu_info[0];
362 }
363
364 }
365 $menu[$menu_key][0] = $menu_item_title;
366 }
367 }
368
369 /**
370 * Hide menu items by adding a class to hide them (part of WP Core's common.css)
371 *
372 * @since 2.0.0
373 */
374 public function hide_menu_items()
375 {
376 global $menu ;
377 $common_methods = new Common_Methods();
378 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
379 // indexed array
380 foreach ( $menu as $menu_key => $menu_info ) {
381
382 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
383 $menu_item_id = $menu_info[2];
384 } else {
385 $menu_item_id = $menu_info[5];
386 }
387
388 // Append 'hidden' class to hide menu item until toggled
389 if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) {
390 $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu';
391 }
392 }
393 }
394
395 /**
396 * Add toggle to show hidden menu items
397 *
398 * @since 2.0.0
399 */
400 public function add_hidden_menu_toggle()
401 {
402 global $current_user ;
403 // Get menu items hidden by toggle
404 $common_methods = new Common_Methods();
405 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
406 // Get user capabilities the "Show All/Less" toggle should be shown for
407 $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for();
408 // Get current user's capabilities from the user's role(s)
409 $current_user_capabilities = '';
410 $current_user_roles = $current_user->roles;
411 // indexed array of role slugs
412 foreach ( $current_user_roles as $current_user_role ) {
413 $current_user_role_capabilities = get_role( $current_user_role )->capabilities;
414 $current_user_role_capabilities = array_keys( $current_user_role_capabilities );
415 // indexed array
416 $current_user_role_capabilities = implode( ",", $current_user_role_capabilities );
417 $current_user_capabilities .= $current_user_role_capabilities;
418 }
419 $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) );
420 // Maybe show "Show All/Less" toggle
421 $show_toggle_menu = false;
422 foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) {
423
424 if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) {
425 $show_toggle_menu = true;
426 break;
427 }
428
429 }
430
431 if ( !empty($menu_hidden_by_toggle) && $show_toggle_menu ) {
432 add_menu_page(
433 'Show All',
434 'Show All',
435 'read',
436 'asenha_show_hidden_menu',
437 function () {
438 return false;
439 },
440 "dashicons-arrow-down-alt2",
441 300
442 );
443 add_menu_page(
444 'Show Less',
445 'Show Less',
446 'read',
447 'asenha_hide_hidden_menu',
448 function () {
449 return false;
450 },
451 "dashicons-arrow-up-alt2",
452 301
453 );
454 }
455
456 }
457
458 /**
459 * Script to toggle hidden menu itesm
460 *
461 * @since 2.0.0
462 */
463 public function enqueue_toggle_hidden_menu_script()
464 {
465 // Get menu items hidden by toggle
466 $common_methods = new Common_Methods();
467 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
468 if ( !empty($menu_hidden_by_toggle) ) {
469 // Script to set behaviour and actions of the sortable menu
470 wp_enqueue_script(
471 'asenha-toggle-hidden-menu',
472 ASENHA_URL . 'assets/js/toggle-hidden-menu.js',
473 array(),
474 ASENHA_VERSION,
475 false
476 );
477 }
478 }
479
480 /**
481 * Hide the Help tab and drawer
482 *
483 * @since 4.5.0
484 */
485 public function hide_help_drawer()
486 {
487
488 if ( is_admin() ) {
489 $screen = get_current_screen();
490 $screen->remove_help_tabs();
491 }
492
493 }
494
495 }