function _mw_adminimize_dashboard_setup()
{
    $adminimizeoptions = _mw_adminimize_get_option_value();
    $widgets = _mw_adminimize_get_dashboard_widgets();
    $adminimizeoptions['mw_adminimize_dashboard_widgets'] = $widgets;
    _mw_adminimize_update_option($adminimizeoptions);
    // exclude super admin
    if (_mw_adminimize_exclude_super_admin()) {
        return NULL;
    }
    $user_roles = _mw_adminimize_get_all_user_roles();
    foreach ($user_roles as $role) {
        $disabled_dashboard_option_[$role] = _mw_adminimize_get_option_value('mw_adminimize_disabled_dashboard_option_' . $role . '_items');
    }
    foreach ($user_roles as $role) {
        if (!isset($disabled_dashboard_option_[$role]['0'])) {
            $disabled_dashboard_option_[$role]['0'] = '';
        }
    }
    foreach ($user_roles as $role) {
        $user = wp_get_current_user();
        if (is_array($user->roles) && in_array($role, $user->roles)) {
            if (_mw_adminimize_current_user_has_role($role) && is_array($disabled_dashboard_option_[$role])) {
                foreach ($disabled_dashboard_option_[$role] as $widget) {
                    if (isset($widgets[$widget]['context'])) {
                        remove_meta_box($widget, 'dashboard', $widgets[$widget]['context']);
                    }
                }
            }
        }
    }
}
Exemple #2
0
/**
 * 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);
    }
}
Exemple #3
0
/**
 * Write dashboard widgets in settings.
 *
 * @return bool
 */
function _mw_adminimize_update_dashboard_widgets()
{
    // Only manage options users have the chance to update the settings.
    if (!current_user_can('manage_options')) {
        return FALSE;
    }
    $adminimizeoptions = _mw_adminimize_get_option_value();
    $adminimizeoptions['mw_adminimize_dashboard_widgets'] = _mw_adminimize_get_dashboard_widgets();
    return _mw_adminimize_update_option($adminimizeoptions);
}
function _mw_adminimize_get_all_meta_boxes($post_type, $priority, $post)
{
    global $wp_meta_boxes;
    if (!empty($wp_meta_boxes[$post_type])) {
        // get all options
        $adminimizeoptions = _mw_adminimize_get_option_value();
        // add meta box array for post type
        $adminimizeoptions['mw_adminimize_meta_boxes_' . $post_type] = $wp_meta_boxes[$post_type];
        // update options
        _mw_adminimize_update_option($adminimizeoptions);
    }
}
/**
 * Get admin bar items from frontend view.
 *
 * @since 2015-07-03
 *
 * @param $wp_admin_bar
 *
 * @return null
 */
function _mw_adminimize_get_admin_bar_frontend_nodes($wp_admin_bar)
{
    if (!is_user_logged_in()) {
        return;
    }
    if (is_admin()) {
        return;
    }
    // Only the right capability allow to get all items and update settings.
    if (!current_user_can('manage_options')) {
        return;
    }
    // @see: http://codex.wordpress.org/Function_Reference/get_nodes
    $all_toolbar_nodes = $wp_admin_bar->get_nodes();
    if ($all_toolbar_nodes) {
        // get all options
        $adminimizeoptions = _mw_adminimize_get_option_value();
        // add admin bar array
        $adminimizeoptions['mw_adminimize_admin_bar_frontend_nodes'] = $all_toolbar_nodes;
        // update options
        _mw_adminimize_update_option($adminimizeoptions);
    }
}
Exemple #6
0
/**
 * Remove sidebars for different roles
 *
 * @return  void
 */
function _mw_adminimize_unregister_sidebars()
{
    // Get settings.
    $adminimizeoptions = _mw_adminimize_get_option_value();
    // Get settings.
    _mw_adminimize_update_option($adminimizeoptions);
    // exclude super admin
    if (_mw_adminimize_exclude_super_admin()) {
        return NULL;
    }
    $user_roles = _mw_adminimize_get_all_user_roles();
    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'] = '';
        }
    }
    foreach ($user_roles as $role) {
        $user = wp_get_current_user();
        if (is_array($user->roles) && in_array($role, $user->roles)) {
            if (_mw_adminimize_current_user_has_role($role) && is_array($disabled_widget_option_[$role])) {
                foreach ($disabled_widget_option_[$role] as $sidebar) {
                    unregister_sidebar($sidebar);
                }
            }
        }
        // end if user roles
    }
}
Exemple #7
0
/**
 * Process a settings import from a json file
 */
function _mw_adminimize_import_json()
{
    if (empty($_POST['_mw_adminimize_action']) || '_mw_adminimize_import' !== $_POST['_mw_adminimize_action']) {
        return;
    }
    if (!wp_verify_nonce($_POST['mw_adminimize_import_nonce'], 'mw_adminimize_import_nonce')) {
        return;
    }
    if (!current_user_can('manage_options')) {
        return;
    }
    $extension = pathinfo($_FILES['import_file']['name'], PATHINFO_EXTENSION);
    if ($extension !== 'json') {
        wp_die(esc_attr__('Please upload a valid .json file'));
    }
    $import_file = $_FILES['import_file']['tmp_name'];
    if (empty($import_file)) {
        wp_die(esc_attr__('Please upload a file to import'));
    }
    // Retrieve the settings from the file and convert the json object to an array.
    $settings = (array) json_decode(file_get_contents($import_file));
    unlink($import_file);
    _mw_adminimize_update_option($settings);
}