Exemplo n.º 1
0
/**
 * Remove items in Admin Bar for current role of current active user in front end area
 * Exclude Super Admin, if active
 * Exclude Settings page of Adminimize
 *
 * @since   1.8.1  01/10/2013
 */
function _mw_adminimize_change_admin_bar()
{
    // Only for users, there logged in.
    if (!is_user_logged_in()) {
        return;
    }
    // Exclude super admin.
    if (_mw_adminimize_exclude_super_admin()) {
        return;
    }
    // Exclude the new settings of the Admin Bar on settings page of Adminimize.
    if (_mw_adminimize_exclude_settings_page()) {
        return;
    }
    // If the admin bar is not active, filtering is not necessary.
    if (!is_admin_bar_showing()) {
        return;
    }
    /** @var $wp_admin_bar WP_Admin_Bar */
    global $wp_admin_bar;
    // Get current user data.
    $user = wp_get_current_user();
    if (!$user->roles) {
        return;
    }
    // Get all roles of logged in user.
    $user_roles = $user->roles;
    //$user_roles = _mw_adminimize_get_all_user_roles();
    $disabled_admin_bar_option_ = array();
    // Get Backend Admin Bar settings for the current user role.
    if (is_admin()) {
        foreach ($user_roles as $role) {
            $disabled_admin_bar_option_[$role] = (array) _mw_adminimize_get_option_value('mw_adminimize_disabled_admin_bar_' . $role . '_items');
        }
    } else {
        // Get Frontend Admin Bar settings for the current user role.
        foreach ($user_roles as $role) {
            $disabled_admin_bar_option_[$role] = (array) _mw_adminimize_get_option_value('mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items');
        }
    }
    // Merge multidimensional array in to one, flat.
    $disabled_admin_bar_option_ = array_reduce($disabled_admin_bar_option_, 'array_merge', array());
    // Support Multiple Roles for users.
    if (_mw_adminimize_get_option_value('mw_adminimize_multiple_roles') && 1 < count($user->roles)) {
        $disabled_admin_bar_option_ = _mw_adminimize_get_duplicate($disabled_admin_bar_option_);
    }
    // No settings for this role, exit.
    if (!$disabled_admin_bar_option_) {
        return;
    }
    foreach ($disabled_admin_bar_option_ as $admin_bar_item) {
        $wp_admin_bar->remove_node($admin_bar_item);
    }
}
Exemplo n.º 2
0
/**
 * Set global options in backend in all areas.
 */
function _mw_adminimize_set_global_option()
{
    // exclude super admin
    if (_mw_adminimize_exclude_super_admin()) {
        return NULL;
    }
    // Leave the settings screen from Adminimize to see all areas on settings.
    if (_mw_adminimize_exclude_settings_page()) {
        return;
    }
    $user_roles = _mw_adminimize_get_all_user_roles();
    $_mw_adminimize_admin_head = '';
    $disabled_global_option = array();
    $disabled_global_option_ = array();
    $user = wp_get_current_user();
    // Get settings for each role.
    foreach ($user_roles as $role) {
        $disabled_global_option_[$role] = (array) _mw_adminimize_get_option_value('mw_adminimize_disabled_global_option_' . $role . '_items');
    }
    // Write global options in an var.
    foreach ($user_roles as $role) {
        if (in_array($role, $user->roles, FALSE) && _mw_adminimize_current_user_has_role($role)) {
            // Create array about all items with all affected roles, important for multiple roles.
            foreach ($disabled_global_option_[$role] as $global_item) {
                $disabled_global_option[] = $global_item;
            }
        }
    }
    // Support Multiple Roles for users.
    if (_mw_adminimize_get_option_value('mw_adminimize_multiple_roles') && 1 < count($user->roles)) {
        $disabled_global_option = _mw_adminimize_get_duplicate($disabled_global_option);
    }
    $global_options = implode(', ', $disabled_global_option);
    if (0 === strpos($global_options, '#your-profile .form-table fieldset')) {
        global $_wp_admin_css_colors;
        $_wp_admin_css_colors = 0;
    }
    $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
    $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
    if ('' !== $global_options) {
        echo $_mw_adminimize_admin_head;
    }
}
Exemplo n.º 3
0
/**
 * Remove Admin Bar
 *
 * @return null|void
 */
function _mw_adminimize_remove_admin_bar()
{
    // exclude super admin
    if (_mw_adminimize_exclude_super_admin()) {
        return;
    }
    // Leave the settings screen from Adminimize to see all areas on settings.
    if (_mw_adminimize_exclude_settings_page()) {
        return;
    }
    $user_roles = _mw_adminimize_get_all_user_roles();
    $disabled_global_option_ = array();
    foreach ($user_roles as $role) {
        $disabled_global_option_[$role] = (array) _mw_adminimize_get_option_value('mw_adminimize_disabled_global_option_' . $role . '_items');
    }
    $mw_global_options = array();
    $user = wp_get_current_user();
    foreach ($user_roles as $role) {
        if (in_array($role, $user->roles, FALSE) && _mw_adminimize_current_user_has_role($role)) {
            // Create array about all items with all affected roles, important for multiple roles.
            foreach ($disabled_global_option_[$role] as $global_item) {
                $mw_global_options[] = $global_item;
            }
        }
    }
    // Support Multiple Roles for users.
    if (_mw_adminimize_get_option_value('mw_adminimize_multiple_roles') && 1 < count($user->roles)) {
        $mw_global_options = _mw_adminimize_get_duplicate($mw_global_options);
    }
    $remove_adminbar = FALSE;
    // Check for admin bar selector to set to remove the Admin Bar.
    if (_mw_adminimize_recursive_in_array('.show-admin-bar', $mw_global_options)) {
        $remove_adminbar = TRUE;
    }
    if ($remove_adminbar) {
        if (!is_admin_bar_showing()) {
            return FALSE;
        }
        add_filter('show_admin_bar', '__return_false');
        add_filter('wp_admin_bar_class', '__return_false');
        add_filter('show_wp_pointer_admin_bar', '__return_false');
        wp_deregister_script('admin-bar');
        wp_deregister_style('admin-bar');
        remove_action('init', '_wp_admin_bar_init');
        remove_action('wp_footer', 'wp_admin_bar_render', 1000);
        remove_action('admin_footer', 'wp_admin_bar_render', 1000);
        // maybe also: 'wp_head'
        foreach (array('wp_head', 'admin_head') as $hook) {
            add_action($hook, create_function('', "echo '<style>body.admin-bar, body.admin-bar #wpcontent, body.admin-bar #adminmenu {\n\t\t\t\t\t\t\t padding-top: 0 !important;\n\t\t\t\t\t\t}\n\t\t\t\t\t\thtml.wp-toolbar {\n\t\t\t\t\t\t\tpadding-top: 0 !important;\n\t\t\t\t\t\t}</style>';"));
        }
        add_action('in_admin_header', '_mw_adminimize_restore_links');
    }
    // end if $remove_adminbar TRUE
}