Support » Fixing WordPress » hide elements on subscriber dashboard

  • Hello!

    I am wanting to have more control over my subscribers dashboard. I do not want to hide it as some find it useful. But i would like to have only recent comments and the forum(simple:forum) boxes show up.

    Now it looks like this. I am needing it to look like this!

    So basically how can i take away wordpress news, right now, and incoming links?


Viewing 8 replies - 1 through 8 (of 8 total)
  • Start here. I pasted code that should remove dashboard widgets. You just need to add an if so that the code only runs when someone is a subscriber and doesn’t run for, say, the administrator.

    hello! with this code i have 2 questions.
    1 – not sure how or where to add the “if” you mentioned
    2 – just wanted to make sure that i would add it here?:

    function example_remove_dashboard_widgets() {
            global $wp_meta_boxes;
    add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );

    No don’t touch core files..

    Your theme’s functions.php would be the most simple approach..

    I would like to point out one minor flaw with the above code. Code assumes the widgets are still in their default positions, if a user has moved any, then the above will miss the moved boxes.

    I use some code much like the above to remove unwanted meta boxes (widgets really), but i run a simple check to determine where they are first..

    For the sake of saving time, i’m just going to paste the areas i’m talking about from my file, fondalashay you need not pay attention here, this is more for the jedi 😉 …

    // Determines where particular meta boxes are, side or normal
    		$pos = array();
    		$pos['rss'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'] ) ) ? 'normal' : 'side';
    		$pos['incoming'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_incoming_links'] ) ) ? 'normal' : 'side';
    		$pos['comments'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_comments'] ) ) ? 'normal' : 'side';
    		$pos['drafts'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts'] ) ) ? 'normal' : 'side';
    		$pos['dev_blog'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] ) ) ? 'normal' : 'side';
    		$pos['plugins'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_plugins'] ) ) ? 'normal' : 'side';
    		$pos['quickpress'] = ( !isset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] ) ) ? 'normal' : 'side';
    		// Unset the unwanted widgets using the above array to target the necessary positions
    			$wp_meta_boxes['dashboard'][$pos['rss']]['core']['dashboard_secondary'] ,
    			$wp_meta_boxes['dashboard'][$pos['incoming']]['core']['dashboard_incoming_links'] ,
    			$wp_meta_boxes['dashboard'][$pos['comments']]['core']['dashboard_recent_comments'] ,
    			$wp_meta_boxes['dashboard'][$pos['drafts']]['core']['dashboard_recent_drafts'] ,
    			$wp_meta_boxes['dashboard'][$pos['dev_blog']]['core']['dashboard_primary'] ,
    		unset( $pos );
    		// Create a comma seperated string out of the leftover widgets - for debug
    		$leftovers =
    			implode( ', ' ,
    					array_keys( $wp_meta_boxes['dashboard']['side']['core'] ) ,
    					array_keys( $wp_meta_boxes['dashboard']['normal']['core'] )
    		// Print the leftover widget titles/references
    		// print $leftovers;

    Used isset because it’s much faster then array_key_exists (which is what i initially used).

    Of course this is not a catch all, i’m sure, but it will determine a side or normal position and unset appropriately this way..

    thanks t31os_! functions.php sounds much safer !!

    the code you posted did not remove the elements. 🙁

    however the code i posted did, but it did for all users. would you know how the “if” function worked so it only removes the elements for subscribers?

    I only posted a section of code, it was for demostration only..

    You’d proberly want to nest the add_action in some form of user level check.

    if( someusercheck ) {
      add_action ...etc...

    Is that what you’re asking? How to check what role a user has?

    yes that is what i am asking. I am not sure what to write to make it select the subscriber only?

    No right way to do it, i tend to favor the method i’ve shown in the first link above..

    What about..

    if ( is_user_logged_in() ) {
    	$userRole = ($current_user->data->wp_capabilities);
    	$role = key($userRole);
    	switch($role) {
    		case 'subscriber':
    		case 'anotherole':

    Does that help?

    hello! i am not seeming to get it to work

    i added it to my functions.php but it disabled login/logout somehow – and ideas?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘hide elements on subscriber dashboard’ is closed to new replies.