Dashboard widget for users (without blogs)

Is there a way to remove (or customize) the wordpress widgets for users that DONT have blogs?

When they login, they dont get the custom content widget, all they get is the wordpress RSS news widgets.

I'd like to use this page as a place that I can encourage users to grab a site and get started.

  • DavidM
    • DEV MAN’s Mascot

    Hi Kruzen,

    I think something like that can be done rather easily with something like the following:

    global $current_user;
    get_currentuserinfo();
    $primary_blog = get_usermeta( $current_user->ID, 'primary_blog' );
    
    if ( $primary_blog == '1' ){
    	//user has no blog, display no-blog content
    }
    else
    {
    	//user has a primary blog, display blog owner content
    }

    The content would be different based on whether the user has a primary blog then. How would that work for you?

    -David

  • Kruzen
    • The Incredible Code Injector

    David,

    I tried this approach by extending another dashboard plugin.. Doesn't seem to effect the the "users without blogs" category at all though.

    I was influenced by this thread in trying it this way: https://premium.wpmudev.org/forums/topic/how-to-make-a-clean-empty-dashboard-for-users

    <?php
    /*
    Plugin name: Dashboard Widgets Network Removal
    Plugin URI: http://erikshosting.com/scripts-code/remove-dashboard-widgets-wp-network/
    Description: Remove ALL Default WP Dashboard Widgets, Network Wide
    Author: Erikshosting
    Version: 1.2
    Author URI: http://erikshosting.com
    */
    
    /* Allowed
    	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    */
    function erocks_kill_all_dash_widgets() {
    	global $wp_meta_boxes;
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // quick press
    	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); //incoming links
    	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // plugins
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // recent drafts
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); //wordpress blog
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // other wordpress news
    }
    add_action( 'wp_dashboard_setup', 'erocks_kill_all_dash_widgets' );
    
    function nonadmin_customize_adminscreens() {
      	if(!current_user_can('administrator')) { // anyone not an admin
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); //wordpress blog
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // other wordpress news
    	}
    }
    add_action( 'wp_dashboard_setup', 'nonadmin_customize_adminscreens' );
    
    ?>

    I also tried these modifications to the custom function, none worked.

    function nonadmin_customize_adminscreens() {
    	global $current_user;
    	get_currentuserinfo();
    	$primary_blog = get_usermeta( $current_user->ID, 'primary_blog' );
    
      	if ( $primary_blog == '1' ){ // anyone without a blog
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); //wordpress blog
    	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // other wordpress news
    	}
    }
    add_action( 'wp_dashboard_setup', 'nonadmin_customize_adminscreens' );
    function nonadmin_customize_adminscreens() {
    	global $current_user;
    	get_currentuserinfo();
    	$primary_blog = get_usermeta( $current_user->ID, 'primary_blog' );
    
      	if ( $primary_blog == '1' ){ // anyone without a site
    		remove_meta_box('dashboard_primary', 'dashboard', 'side');   // wordpress blog
    		remove_meta_box('dashboard_secondary', 'dashboard', 'side');   // other wordpress news
    	}
    }
    add_action( 'wp_dashboard_setup', 'nonadmin_customize_adminscreens' );
    function nonadmin_customize_adminscreens() {
      	if(!current_user_can('administrator')) { // anyone not an admin
    		remove_meta_box('dashboard_primary', 'dashboard', 'side');   // wordpress blog
    		remove_meta_box('dashboard_secondary', 'dashboard', 'side');   // other wordpress news
    	}
    }
    add_action( 'wp_dashboard_setup', 'nonadmin_customize_adminscreens' );
  • DavidM
    • DEV MAN’s Mascot

    Hi Kruzen,

    I'm couldn't really comment on the code in other areas but I tried it myself in the from of a contents.php file in the Custom Content Dashboard Widget plugin as follows:

    <?php
    global $current_user;
    get_currentuserinfo();
    $primary_blog = get_usermeta( $current_user->ID, 'primary_blog' );
    if ( $primary_blog == '1' ){
    	//user has no blog, display no-blog content
    	echo "I don't have a blog!";
    }
    else
    {
    	//user has a primary blog, display blog owner content
    	echo "I have a blog!";
    }
    ?>

    And with that, it worked like a charm!

    Cheers,
    David

  • Kruzen
    • The Incredible Code Injector

    Hi David,

    I'd like to say that worked for me, but unfortunately it didn't.

    It shows the "I have a blog!" for users with blog content. but users without blog content continue to get the same "wordpress updates". and no evidence of the custom dashboard widget.

    See attached screenshots.

    I copied and pasted the code exactly as listed above and pasted it in the top of my contents.php file, I also tried purging my existing data with the same result.

  • Mason
    • DEV MAN’s Sidekick

    Hiya Kruzen,

    This sounds like you're looking for custom development to me. The support forums here are really to address any bugs/issues you have with the plugins. Is there an issue with one of our products here?

    I think what you're looking for is to customize the dashboard widgets based on user role. They may not be 'admins' of a blog, but they have to have some sort of role. Most likely you're referring to 'subscribers'. I believe this tutorial will help you accomplish what you're looking for:
    http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role

    Let me know if I've missed something though and we'll see what we can do.

    Thanks!

  • Kruzen
    • The Incredible Code Injector

    Thanks mason,

    I don't think I'm looking to customize dashboard widgets based on user role. While that would be a great feature, the problem I'm having is that this plugin does not work for subscribers. I'll check out the link and see if I can get what I need out of there.

    If it's not supposed to, I'd like to request that be added to the list.

  • DavidM
    • DEV MAN’s Mascot

    Hi Kruzen,

    I'm really not sure why that wouldn't work on your site as I've tried the same snippet with subscriber roles as well as others and it seems to do just fine, displaying the message "I don't have a blog!" if the user doesn't have a primary blog.

    If you've customized users roles or capabilities, that may affect the results.

    Also, the plugin itself works for Subscriber roles regardless of the above custom code. My guess is that if it's not working for you, it likely would have to do with your user roles and capabilities.

    Cheers,
    David

  • Kruzen
    • The Incredible Code Injector

    I haven't customized any user roles, and I've stripped the site down to no plugins enabled.

    I'd love to see a screenshot in action of an account created as I've described.

    The user in question is not a subscriber to the main site. It is a Site Admin created using the "just an account!" versus "Gimme a site!" option.

    The user is listed under the Users section under 'Network Admin' as opposed to a user/subscriber under the Network's Primary Blog.

    The widgets shows up on the dashboard for all Admin's WITH Sites, but does not show for Admin's WITHOUT sites.

    That is the issue. If you can show me the plugin working in this manner, then I'll yield. but I don't think it's working right.

  • DavidM
    • DEV MAN’s Mascot

    Hi Kruzen,

    The thing is, if the user is a Site Admin as you're saying, then the user must be have an Admin role on at least one site on the network, which doesn't follow if you've created the user with the "just an account" option.

    This particular user, does it have a role on any of the sites in your network?

    Thanks,
    David

  • Kruzen
    • The Incredible Code Injector

    Well, that's a good question. Not that I can tell.

    The user can create a site at any time, but during the registration process requested "just username for now".

    That results with this account in limbo. They can create sites, but the dashboard only shows what I posted above in the picture.

    They aren't a subscriber as they don't show up under the Users section of the top site.

    At best they are a "network subscriber" ? Maybe?

    But under their profile there is no "role" information, so I would consider them a site admin (with no sites)

  • Kruzen
    • The Incredible Code Injector

    Hi David,

    Thanks for the continued support with this. Unfortunately that doesn't solve it either, as that plugin allows you to define default roles for users registering on existing sites, it doesn't allow you to do assign a role to users with no site affiliation.

    The main problem is, under multisite registration you have these options for your network:

    Registration is disabled.
    User accounts may be registered.
    Logged in users may register new sites.
    Both sites and user accounts can be registered.

    There's no way to remove the "just gimme a login" option without pruning it out of the core.

    There's no option that says "If I am registering, I have to define a site"

    The idea was to use the dashboard widget to say "Hey, you need to create a site, go here, otherwisey ou can't do anything"

    The accounts sit in limbo otherwise. Because they aren't associated with any sites, they are just "an account on the network". If that's the problem then so be it and people will have be stuck in limbo.

    They also don't become affiliated with the primary site, because the registration process on multisite is for signing up for the network, not for registering for the blog. In fact, I'm not sure how you would even become a subscriber, to the main site of a network. Perhaps you could clarify that too if it's not too much trouble while we're on the topic. I've been trying to figure out how you can subscribe to certain sites and blogs within a network as well as for the main site, as wp-signup.php seems to be tied to generating new blogs, not registration signups for the primary site.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.