PluginProbe
Adminimize / 1.11.3
Adminimize v1.11.3
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.3, at inc-setup/admin-bar-items.php

125 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
48 // get all options
49 $adminimizeoptions = _mw_adminimize_get_option_value();
50
51 // add admin bar array
52 $adminimizeoptions[ $settings ] = $all_toolbar_nodes;
53
54 // update options
55 _mw_adminimize_update_option( $adminimizeoptions );
56 }
57 }
58
59 /**
60 * Remove items in Admin Bar for current role of current active user in front end area
61 * Exclude Super Admin, if active
62 * Exclude Settings page of Adminimize
63 *
64 * @since 1.8.1 01/10/2013
65 */
66 function _mw_adminimize_change_admin_bar() {
67
68 // Only for users, there logged in.
69 if ( ! is_user_logged_in() ) {
70 return;
71 }
72
73 // Exclude super admin.
74 if ( _mw_adminimize_exclude_super_admin() ) {
75 return;
76 }
77
78 // Exclude the new settings of the Admin Bar on settings page of Adminimize.
79 if ( _mw_adminimize_exclude_settings_page() ) {
80 return;
81 }
82
83 // If the admin bar is not active, filtering is not necessary.
84 if ( ! is_admin_bar_showing() ) {
85 return;
86 }
87
88 /** @var $wp_admin_bar WP_Admin_Bar */
89 global $wp_admin_bar;
90
91 // Get current user data.
92 $user = wp_get_current_user();
93 if ( ! $user->roles ) {
94 return;
95 }
96
97 // Get all roles of logged in user.
98 $user_roles = $user->roles;
99 //$user_roles = _mw_adminimize_get_all_user_roles();
100 $disabled_admin_bar_option_ = array();
101
102 $role_prefix = is_admin() ? 'mw_adminimize_disabled_admin_bar_' : 'mw_adminimize_disabled_admin_bar_frontend_';
103
104 foreach ( $user_roles as $role ) {
105 $disabled_admin_bar_option_[] = _mw_adminimize_get_option_value( $role_prefix . $role . '_items' );
106 }
107
108 // Merge multidimensional array in to one, flat.
109 $disabled_admin_bar_option_ = _mw_adminimize_array_flatten( $disabled_admin_bar_option_ );
110
111 // Support Multiple Roles for users.
112 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
113 $disabled_admin_bar_option_ = _mw_adminimize_get_duplicate( $disabled_admin_bar_option_ );
114 }
115
116 // No settings for this role, exit.
117 if ( ! $disabled_admin_bar_option_ ) {
118 return;
119 }
120
121 foreach ( (array) $disabled_admin_bar_option_ as $admin_bar_item ) {
122 $wp_admin_bar->remove_node( $admin_bar_item );
123 }
124 }
125