Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here's what I have so far as my notification, but I can't find any information around how to input the user's name, role and site name within those sections. You can see where they are supposed to go. Any help would be much appreciated as I've been stumped for a few days now...

function my_network_notice(){
    global $pagenow;  
  if ( $pagenow == 'index.php') {
             echo '<div id="secondaryBox">
                    <div id="author">
                        <img src="/wp-content/themes/dewslyWeb/img/btn-articles-admin.png" width="40px" height="40px" />
                        <h5>[DISPLAYNAMEHERE]</h5>
                        <h6>[USERROLEHERE], [SITENAMEHERE]</h6>
                    </div>
                </div>
}
    }
    add_action('admin_notices', 'my_network_notice');
share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

You can use the bloginfo( 'name' ) function to display the site name. Information about the current logged in user can be retrieved using the get_currentuserinfo() function.

Here is the fixed code:

function my_network_notice(){
    global $pagenow, $currentuser;
    get_currentuserinfo();
    if ( $pagenow == 'index.php') : ?>
        <div id="secondaryBox">
            <div id="author">
                <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/btn-articles-admin.png" width="40px" height="40px" />
                <h5><?php echo esc_html( $current_user->display_name ); ?></h5>
                <h6><?php echo esc_html( translate_user_role( $current_user->roles[0] ) ); ?>, <?php bloginfo( 'name' ); ?></h6>
            </div>
        </div>
    <?php endif;
}
add_action( 'admin_notices', 'my_network_notice' );

However, at the moment you're just outputting the data straight to the dashboard. It would be better to create a dashboard widget (like the Right Now or Recent Drafts dashboard widgets):

/* display the dashboard widget output */
function wpse_77452_dashboard_widget_output() {
    global $currentuser;
    get_currentuserinfo(); ?>
    <div id="secondaryBox">
            <div id="author">
                <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/btn-articles-admin.png" width="40px" height="40px" />
                <h5><?php echo esc_html( $current_user->display_name ); ?></h5>
                <h6><?php echo esc_html( $current_user->roles[0] ); ?>, <?php bloginfo( 'name' ); ?></h6>
            </div>
        </div>
    <?php
} 


/* add the dashboard widget */
function wpse_77452_add_dashboard_widgets() {
    wp_add_dashboard_widget(
        'network_notice', // ID of widget
        'Important Information', // title of widget
        'wpse_77452_dashboard_widget_output' // function used to display widget
    );  
}

add_action( 'wp_dashboard_setup', 'add_notice_dashboard_widgets' );
share|improve this answer
    
So I've tried to implement your solution and had to make a tweak to change $currentuser to $current_user, but even with that, I'm not able to get the user's display name or role to display. I have the site name good-to-go, but the user specific stuff isn't coming through still. Have any other thoughts? –  Jake Lisby Dec 28 '12 at 23:35
    
Disregard, this is working now... :) –  Jake Lisby Dec 28 '12 at 23:42
add comment

First you need to get the current user data (Logged in). http://codex.wordpress.org/Function_Reference/get_currentuserinfo

The you need to get_blogs_of_user.. I only display one now for you. If you want all you need a foreach loop for that. See in codex.

function my_network_notice(){
    global $pagenow, $current_user; 
    get_currentuserinfo(); 

    $blogs = get_blogs_of_user( $current_user->ID );

    if ( $pagenow == 'index.php') {
        echo 
        '<div id="secondaryBox">
            <div id="author">
                <img src="/wp-content/themes/dewslyWeb/img/btn-articles-admin.png" width="40px" height="40px" />
                <h5>'. $current_user->display_name .'</h5>
                <h6>'. ucfirst( $current_user->roles[0] ) .', '. $blogs[1]->blogname .'</h6>
            </div>
        </div>';
    }
}
add_action('admin_notices', 'my_network_notice');
share|improve this answer
add comment

You should wait for 'load-index.php' and not add the function to all admin_notices. The rest is simple:

add_action( 'load-index.php', 'wpse_77448_user_notice' );

function wpse_77448_user_notice()
{
    if ( 'load-index.php' === current_filter() )
        return add_action( 'admin_notices', __FUNCTION__ );

    $user = wp_get_current_user();
    printf( '<pre>
Name: %1$s
Role: %2$s
Site: %3$s</pre>',
        esc_html( $user->data->display_name ),
        // see http://wordpress.stackexchange.com/a/58921/73 for translation
        esc_html( translate_user_role( ucfirst( $user->roles[0] ) ) ),
        get_bloginfo( 'name' )
    );
}

Caveat: One user can have multiple roles. $user->roles[0] is a dirty hack, you should check the length of this array.

share|improve this answer
    
+1 very nice code, @toscho –  bungeshea Dec 27 '12 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.