PluginProbe
Adminimize / 1.11.1
Adminimize v1.11.1
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
adminimize / inc-setup / admin-bar-items.php

admin-bar-items.php in Adminimize 1.11.1, at inc-setup/admin-bar-items.php

124 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Adminimize
4 * @subpackage Admin Bar Items
5 * @author Frank Bültge
6 */
7
8 if ( ! function_exists( 'add_action' ) ) {
9 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
10 exit;
11 }
12
13 // Get all Admin Bar items, different between front- and backend.
14 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_get_admin_bar_nodes', 99999 );
15 // Render the Admin bar new, different between front- and backend.
16 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_change_admin_bar', 99999 );
17
18 /**
19 * Get all admin bar items in back end and write in a options of Adminimize settings array
20 *
21 * @since 1.8.1 01/10/2013
22 */
23 function _mw_adminimize_get_admin_bar_nodes() {
24
25 // Only Administrator get all items.
26 if ( ! current_user_can( 'manage_options' ) ) {
27 return;
28 }
29
30 if ( _mw_adminimize_exclude_settings_page() ) {
31 return;
32 }
33
34 /** @var $wp_admin_bar WP_Admin_Bar */
35 global $wp_admin_bar;
36
37 // @see: http://codex.wordpress.org/Function_Reference/get_nodes
38 $all_toolbar_nodes = $wp_admin_bar->get_nodes();
39
40 $settings = 'mw_adminimize_admin_bar_frontend_nodes';
41 // Set string on settings for Admin Area.
42 if ( is_admin() ) {
43 $settings = 'mw_adminimize_admin_bar_nodes';
44 }
45
46 if ( $all_toolbar_nodes ) {
47 // get all options
48 $adminimizeoptions = _mw_adminimize_get_option_value();
49
50 // add admin bar array
51 $adminimizeoptions[ $settings ] = $all_toolbar_nodes;
52
53 // update options
54 _mw_adminimize_update_option( $adminimizeoptions );
55 }
56 }
57
58 /**
59 * Remove items in Admin Bar for current role of current active user in front end area
60 * Exclude Super Admin, if active
61 * Exclude Settings page of Adminimize
62 *
63 * @since 1.8.1 01/10/2013
64 */
65 function _mw_adminimize_change_admin_bar() {
66
67 // Only for users, there logged in.
68 if ( ! is_user_logged_in() ) {
69 return;
70 }
71
72 // Exclude super admin.
73 if ( _mw_adminimize_exclude_super_admin() ) {
74 return;
75 }
76
77 // Exclude the new settings of the Admin Bar on settings page of Adminimize.
78 if ( _mw_adminimize_exclude_settings_page() ) {
79 return;
80 }
81
82 // If the admin bar is not active, filtering is not necessary.
83 if ( ! is_admin_bar_showing() ) {
84 return;
85 }
86
87 /** @var $wp_admin_bar WP_Admin_Bar */
88 global $wp_admin_bar;
89
90 // Get current user data.
91 $user = wp_get_current_user();
92 if ( ! $user->roles ) {
93 return;
94 }
95
96 // Get all roles of logged in user.
97 $user_roles = $user->roles;
98 //$user_roles = _mw_adminimize_get_all_user_roles();
99 $disabled_admin_bar_option_ = array();
100
101 $role_prefix = is_admin() ? 'mw_adminimize_disabled_admin_bar_' : `mw_adminimize_disabled_admin_bar_frontend_`;
102
103 foreach( $user_roles as $role ) {
104 $disabled_admin_bar_option_[] = _mw_adminimize_get_option_value( $role_prefix . $role . '_items' );
105 }
106
107 // Merge multidimensional array in to one, flat.
108 $disabled_admin_bar_option_ = _mw_adminimize_array_flatten( $disabled_admin_bar_option_ );
109
110 // Support Multiple Roles for users.
111 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
112 $disabled_admin_bar_option_ = _mw_adminimize_get_duplicate( $disabled_admin_bar_option_ );
113 }
114
115 // No settings for this role, exit.
116 if ( ! $disabled_admin_bar_option_ ) {
117 return;
118 }
119
120 foreach ( (array) $disabled_admin_bar_option_ as $admin_bar_item ) {
121 $wp_admin_bar->remove_node( $admin_bar_item );
122 }
123 }
124