Skip to content

Instantly share code, notes, and snippets.

@AlphaAlec
Created March 12, 2014 20:04

Revisions

  1. AlphaAlec renamed this gist Mar 12, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. AlphaAlec renamed this gist Mar 12, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. AlphaAlec created this gist Mar 12, 2014.
    70 changes: 70 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    function change_role_name() {
    global $wp_roles;

    if ( ! isset( $wp_roles ) )
    $wp_roles = new WP_Roles();

    //You can list all currently available roles like this...
    //$roles = $wp_roles->get_names();
    //print_r($roles);

    //You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"...
    $wp_roles->roles['administrator']['name'] = 'Special Admin';
    $wp_roles->role_names['administrator'] = 'Special Admin';
    }
    add_action('init', 'change_role_name');

    //Add a new role
    add_action('init', 'cloneRole');

    function cloneRole()
    {
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
    $wp_roles = new WP_Roles();

    $adm = $wp_roles->get_role('administrator');
    //Adding a 'new_role' with all admin caps
    $wp_roles->add_role('new_role', 'Administrator', $adm->capabilities);
    }



    function remove_menus () {
    if(is_user_logged_in() && current_user_can('new_role')) {
    global $menu;
    //$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Contact'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
    $restricted = array(__('Comments'), __('Plugins'), __('Tools'), __('Custom Fields'), __('Themes'));
    end ($menu);
    while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    }


    }
    }
    add_action('admin_menu', 'remove_menus');

    function remove_acf() {
    if(is_user_logged_in() && current_user_can('new_role')) {
    remove_menu_page('edit.php?post_type=acf');

    remove_submenu_page( 'themes.php','theme-editor.php');
    remove_submenu_page( 'themes.php','customize.php');
    remove_submenu_page( 'themes.php','custom-background');

    global $submenu;
    unset($submenu['index.php'][10]);
    return $submenu;
    }
    }
    add_action('admin_menu','remove_acf',999);

    function remove_admin_bar_links() {
    if(is_user_logged_in() && current_user_can('new_role')) {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('updates');
    }
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );