Custom User Field in Dashboard Widget

I checked justin tadlocks custom profile field tutorial and wanted to add the field in the custom dashboard widget but it seems it’s not working. I want to show all the user information in this widget.

All that I want to do is add the custom information from the profile field to this dashboard widget and it seems to be not working.

Read More

My aim here to to get all author information and show it on this dashboard. Any ideas how to achieve this task?

function example_dashboard_widget_function() {
// Display whatever it is you want to show
the_author_meta();
 } 

// Create the function use in the action hook
function example_add_dashboard_widgets() {
wp_add_dashboard_widget('example_dashboard_widget', 'User Profile',    'example_dashboard_widget_function');
}
// Hoook into the 'wp_dashboard_setup' action to register our otherfunctions
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

Related posts

Leave a Reply

1 comment

  1. There’s get_the_author_meta() for such a task. (get_* functions normally don’t echo/print the output – hence the name).

    // Both values are *optional*
    get_the_author_meta( $field, $user_id );
    

    Normally it’s only meant to be used inside a loop to get the data of the posts author, therefore it internally uses global $authordata;.

    But, you can also throw in the data of the current user, as user data is always the same (same tables, same data).

    global $current_user;
    
    // Test to see what you get:
    echo '<pre>'.var_export( $current_user, true ).'</pre>';
    
    get_the_author_meta( '', $current_user->ID );
    
    // OR: simply, without the global
    get_the_author_meta( '', get_current_user_id() );
    

    Now the only thing left is to call the meta for each field, using get_user_meta(), which is pretty much equal (for this task) to get_the_author_meta();.

    $user_meta = get_user_meta( get_current_user_id() );
    // OR: Use the function, where get_user_meta() is the API wrapper for
    $user_meta = get_meta_data( 'user', get_current_user_id(), '', true );
    

    Then just loop through it:

    foreach ( $user_meta as $meta_data )
        echo '<pre>'.var_export( $meta_data, true ).'</pre>';