• fondalashay

    (@fondalashay)


    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?

    Thanks!!

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.

    Thread Starter fondalashay

    (@fondalashay)

    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?:
    /wp-admin/includes/dashboard.php

    function example_remove_dashboard_widgets() {
            global $wp_meta_boxes;
            unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
            unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
            unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
            unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
            unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
            unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
            unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
            unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    }
    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
    		unset(
    			$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'] ,
    			$wp_meta_boxes['dashboard'][$pos['plugins']]['core']['dashboard_plugins']
    		);
    		unset( $pos );
    		// Create a comma seperated string out of the leftover widgets - for debug
    		$leftovers =
    			implode( ', ' ,
    				array_merge(
    					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..

    Thread Starter fondalashay

    (@fondalashay)

    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?

    Thread Starter fondalashay

    (@fondalashay)

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

    https://www.ads-software.com/support/topic/313494?replies=6#post-1240219
    https://codex.www.ads-software.com/Function_Reference/get_currentuserinfo

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

    What about..

    <?php
    if ( is_user_logged_in() ) {
    	$userRole = ($current_user->data->wp_capabilities);
    	$role = key($userRole);
    	unset($userRole);
    	switch($role) {
    		case 'subscriber':
    		case 'anotherole':
    			// DO ADD ACTION STUFF HERE..
    		break;
    		default:
    		break;
    	}
    }
    ?>

    Does that help?

    Thread Starter fondalashay

    (@fondalashay)

    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.