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