/**
 * Get all admin bar items in back end and write in a options of Adminimize settings array
 *
 * @since    1.8.1  01/10/2013
 */
function _mw_adminimize_get_admin_bar_nodes()
{
    // Only Administrator get all items.
    if (!current_user_can('manage_options')) {
        return;
    }
    if (_mw_adminimize_exclude_settings_page()) {
        return;
    }
    /** @var $wp_admin_bar WP_Admin_Bar */
    global $wp_admin_bar;
    // @see: http://codex.wordpress.org/Function_Reference/get_nodes
    $all_toolbar_nodes = $wp_admin_bar->get_nodes();
    $settings = 'mw_adminimize_admin_bar_frontend_nodes';
    // Set string on settings for Admin Area.
    if (is_admin()) {
        $settings = 'mw_adminimize_admin_bar_nodes';
    }
    if ($all_toolbar_nodes) {
        // get all options
        $adminimizeoptions = _mw_adminimize_get_option_value();
        // add admin bar array
        $adminimizeoptions[$settings] = $all_toolbar_nodes;
        // update options
        _mw_adminimize_update_option($adminimizeoptions);
    }
}
Esempio n. 2
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);
    }
}
Esempio n. 3
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;
    }
    /** @var $wp_admin_bar WP_Admin_Bar */
    global $wp_admin_bar;
    // Get current user data.
    $user = wp_get_current_user();
    if (!$user->roles[0]) {
        return;
    }
    $user_role = $user->roles[0];
    // Get Backend Admin Bar settings for the current user role.
    if (is_admin()) {
        $disabled_admin_bar_option_[$user_role] = _mw_adminimize_get_option_value('mw_adminimize_disabled_admin_bar_' . $user_role . '_items');
    } else {
        // Get Frontend Admin Bar settings for the current user role.
        $disabled_admin_bar_option_[$user_role] = (array) _mw_adminimize_get_option_value('mw_adminimize_disabled_admin_bar_frontend_' . $user_role . '_items');
    }
    // No settings for this role, exit.
    if (!$disabled_admin_bar_option_[$user_role]) {
        return;
    }
    foreach ($disabled_admin_bar_option_[$user_role] as $admin_bar_item) {
        $wp_admin_bar->remove_node($admin_bar_item);
    }
}
Esempio n. 4
0
/**
 * Remove items in Admin Bar for current role of current active user in back end area
 * Exclude Super Admin, if active
 * Exclude Settings page of Adminimize
 *
 * @since   1.8.1  01/10/2013
 *
 * @param $wp_admin_bar
 *
 * @return null
 */
function _mw_adminimize_change_admin_bar($wp_admin_bar)
{
    // works only for back end admin bar
    if (!is_admin()) {
        return;
    }
    if (_mw_adminimize_exclude_settings_page()) {
        return;
    }
    // Exclude super admin
    if (_mw_adminimize_exclude_super_admin()) {
        return;
    }
    $user_roles = _mw_adminimize_get_all_user_roles();
    $disabled_admin_bar_option_ = array();
    foreach ($user_roles as $role) {
        $disabled_admin_bar_option_[$role] = _mw_adminimize_get_option_value('mw_adminimize_disabled_admin_bar_' . $role . '_items');
    }
    foreach ($user_roles as $role) {
        if (!isset($disabled_admin_bar_option_[$role]['0'])) {
            $disabled_admin_bar_option_[$role]['0'] = '';
        }
    }
    foreach ($user_roles as $role) {
        $user = wp_get_current_user();
        if (is_array($user->roles) && in_array($role, $user->roles) && _mw_adminimize_current_user_has_role($role) && is_array($disabled_admin_bar_option_[$role])) {
            foreach ($disabled_admin_bar_option_[$role] as $admin_bar_item) {
                $wp_admin_bar->remove_node($admin_bar_item);
            }
        }
        // end if user roles
    }
}
Esempio n. 5
0
/**
 * Get setting value for each options key.
 *
 * @param string|bool $key
 *
 * @return array
 */
function _mw_adminimize_get_option_value($key = FALSE)
{
    $adminimizeoptions = FALSE;
    if (!_mw_adminimize_exclude_settings_page()) {
        $adminimizeoptions = wp_cache_get('mw_adminimize');
    }
    if (FALSE === $adminimizeoptions) {
        // check for use on multisite
        if (_mw_adminimize_is_active_on_multisite()) {
            $adminimizeoptions = (array) get_site_option('mw_adminimize', array());
        } else {
            $adminimizeoptions = (array) get_option('mw_adminimize', array());
        }
        wp_cache_set('mw_adminimize', $adminimizeoptions);
    }
    if (!$key) {
        return $adminimizeoptions;
    }
    return array_key_exists($key, $adminimizeoptions) ? $adminimizeoptions[$key] : NULL;
}
Esempio n. 6
0
/**
 * Remove areas in Widget Settings
 */
function _mw_adminimize_set_widget_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 = '';
    foreach ($user_roles as $role) {
        $disabled_widget_option_[$role] = _mw_adminimize_get_option_value('mw_adminimize_disabled_widget_option_' . $role . '_items');
    }
    foreach ($user_roles as $role) {
        if (!isset($disabled_widget_option_[$role]['0'])) {
            $disabled_widget_option_[$role]['0'] = '';
        }
    }
    $widget_options = '';
    // new 1.7.8
    foreach ($user_roles as $role) {
        $user = wp_get_current_user();
        if (is_array($user->roles) && in_array($role, $user->roles, FALSE)) {
            if (_mw_adminimize_current_user_has_role($role) && isset($disabled_widget_option_[$role]) && is_array($disabled_widget_option_[$role])) {
                $widget_options = implode(',', $disabled_widget_option_[$role]);
            }
        }
    }
    //remove_meta_box( $id, 'nav-menus', 'side' );
    $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
    $_mw_adminimize_admin_head .= '<style type="text/css">' . $widget_options . ' {display: none !important;}</style>' . "\n";
    if ($widget_options) {
        echo $_mw_adminimize_admin_head;
    }
}
/**
 * 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();
    foreach ($user_roles as $role) {
        $disabled_global_option_[$role] = _mw_adminimize_get_option_value('mw_adminimize_disabled_global_option_' . $role . '_items');
    }
    foreach ($user_roles as $role) {
        if (!isset($disabled_global_option_[$role]['0'])) {
            $disabled_global_option_[$role]['0'] = '';
        }
    }
    $user = wp_get_current_user();
    $remove_adminbar = FALSE;
    // new 1.7.8
    foreach ($user_roles as $role) {
        if (is_array($user->roles) && in_array($role, $user->roles, FALSE)) {
            if (_mw_adminimize_current_user_has_role($role) && isset($disabled_global_option_[$role]) && is_array($disabled_global_option_[$role]) && _mw_adminimize_recursive_in_array('.show-admin-bar', $disabled_global_option_[$role])) {
                $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
}
Esempio n. 8
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
}