PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.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.9.1, at inc-setup/admin-bar-items.php

207 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 * @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 //add_action( 'wp_before_admin_bar_render', '_mw_adminimize_get_admin_bar_nodes', 9999 );
14 add_action( 'admin_bar_menu', '_mw_adminimize_get_admin_bar_nodes', 99999 );
15 /**
16 * Get all admin bar items in back end and write in a options of Adminimize settings array
17 *
18 * @since 1.8.1 01/10/2013
19 *
20 * @param $wp_admin_bar
21 */
22 function _mw_adminimize_get_admin_bar_nodes( $wp_admin_bar ) {
23
24 if ( ! is_admin() ) {
25 return;
26 }
27
28 if ( _mw_adminimize_exclude_settings_page() ) {
29 return;
30 }
31
32 // @see: http://codex.wordpress.org/Function_Reference/get_nodes
33 $all_toolbar_nodes = $wp_admin_bar->get_nodes();
34
35 if ( $all_toolbar_nodes ) {
36 // get all options
37 $adminimizeoptions = _mw_adminimize_get_option_value();
38
39 // add admin bar array
40 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = $all_toolbar_nodes;
41
42 // update options
43 _mw_adminimize_update_option( $adminimizeoptions );
44 }
45 }
46
47 //add_action( 'wp_before_admin_bar_render', '_mw_adminimize_get_admin_bar_frontend_nodes', 9999 );
48 add_action( 'admin_bar_menu', '_mw_adminimize_get_admin_bar_frontend_nodes', 99999 );
49 /**
50 * Get admin bar items from frontend view.
51 *
52 * @since 2015-07-03
53 *
54 * @param $wp_admin_bar
55 *
56 * @return null
57 */
58 function _mw_adminimize_get_admin_bar_frontend_nodes( $wp_admin_bar ) {
59
60 if ( ! is_user_logged_in() ) {
61 return;
62 }
63
64 if ( is_admin() ) {
65 return;
66 }
67
68 // Only the right capability allow to get all items and update settings.
69 if ( ! current_user_can( 'manage_options' ) ) {
70 return;
71 }
72 // @see: http://codex.wordpress.org/Function_Reference/get_nodes
73 $all_toolbar_nodes = $wp_admin_bar->get_nodes();
74
75 if ( $all_toolbar_nodes ) {
76 // get all options
77 $adminimizeoptions = _mw_adminimize_get_option_value();
78
79 // add admin bar array
80 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = $all_toolbar_nodes;
81
82 // update options
83 _mw_adminimize_update_option( $adminimizeoptions );
84 }
85 }
86
87 add_action( 'admin_bar_menu', '_mw_adminimize_change_admin_bar', 99999 );
88 /**
89 * Remove items in Admin Bar for current role of current active user in back end area
90 * Exclude Super Admin, if active
91 * Exclude Settings page of Adminimize
92 *
93 * @since 1.8.1 01/10/2013
94 *
95 * @param $wp_admin_bar
96 *
97 * @return null
98 */
99 function _mw_adminimize_change_admin_bar( $wp_admin_bar ) {
100
101 // works only for back end admin bar
102 if ( ! is_admin() ) {
103 return;
104 }
105
106 if ( _mw_adminimize_exclude_settings_page() ) {
107 return;
108 }
109
110 // Exclude super admin
111 if ( _mw_adminimize_exclude_super_admin() ) {
112 return;
113 }
114
115 $user_roles = _mw_adminimize_get_all_user_roles();
116 $disabled_admin_bar_option_ = array();
117
118 foreach ( $user_roles as $role ) {
119
120 $disabled_admin_bar_option_[ $role ] = _mw_adminimize_get_option_value(
121 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
122 );
123 }
124
125 foreach ( $user_roles as $role ) {
126
127 if ( ! isset( $disabled_admin_bar_option_[ $role ][ '0' ] ) ) {
128 $disabled_admin_bar_option_[ $role ][ '0' ] = '';
129 }
130 }
131
132 foreach ( $user_roles as $role ) {
133 $user = wp_get_current_user();
134
135 if ( is_array( $user->roles )
136 && in_array( $role, $user->roles )
137 && _mw_adminimize_current_user_has_role( $role )
138 && is_array( $disabled_admin_bar_option_[ $role ] )
139 ) {
140
141 foreach ( $disabled_admin_bar_option_[ $role ] as $admin_bar_item ) {
142 $wp_admin_bar->remove_node( $admin_bar_item );
143 }
144
145 } // end if user roles
146 }
147
148 }
149
150 add_action( 'admin_bar_menu', '_mw_adminimize_change_admin_bar_frontend', 99999 );
151 /**
152 * Remove items in Admin Bar for current role of current active user in front end area
153 * Exclude Super Admin, if active
154 * Exclude Settings page of Adminimize
155 *
156 * @since 1.8.1 01/10/2013
157 *
158 * @param $wp_admin_bar
159 *
160 * @return null
161 */
162 function _mw_adminimize_change_admin_bar_frontend( $wp_admin_bar ) {
163
164 // works only for back end admin bar
165 if ( is_admin() ) {
166 return;
167 }
168
169 // Exclude super admin
170 if ( _mw_adminimize_exclude_super_admin() ) {
171 return;
172 }
173
174 $user_roles = _mw_adminimize_get_all_user_roles();
175 $disabled_admin_bar_frontend_option_ = '';
176
177 foreach ( $user_roles as $role ) {
178
179 $disabled_admin_bar_frontend_option_[ $role ] = _mw_adminimize_get_option_value(
180 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items'
181 );
182 }
183
184 foreach ( $user_roles as $role ) {
185
186 if ( ! isset( $disabled_admin_bar_frontend_option_[ $role ][ '0' ] ) ) {
187 $disabled_admin_bar_frontend_option_[ $role ][ '0' ] = '';
188 }
189 }
190
191 foreach ( $user_roles as $role ) {
192 $user = wp_get_current_user();
193
194 if ( is_array( $user->roles )
195 && in_array( $role, $user->roles )
196 && _mw_adminimize_current_user_has_role( $role )
197 && is_array( $disabled_admin_bar_frontend_option_[ $role ] )
198 ) {
199
200 foreach ( $disabled_admin_bar_frontend_option_[ $role ] as $admin_bar_item ) {
201 $wp_admin_bar->remove_node( $admin_bar_item );
202 }
203
204 } // end if user roles
205 }
206
207 }