Author Data in WordPress

For the author data this $authordata global variable is use to stores information and details about the author of the post being displayed, For example the author name and you can use this global variable for the this purpose to display the author’s name in the post:

<?php
global $authordata;
echo ‘Author: ‘ .$authordata->display_name;
?>

when setup_postdata() is called during the_post() function call in the Loop  then the $authordata variable is created. It means that the global variable $authordata will not be created until the Loop has run for the first time.
This global variable has another problem that the global values do not
get passed through hook filters, it means that if you installed any pluginfor  override it’s functionality it would not be run or give the exact result.
For accessing or fetch the author metadata will you preferred method for accessing the author metadata, means that for getting the post data, it use the available WordPress template tags.
Let’s suppose, you would use this code for display the author’s display name in the displayed post:

<?php
echo ‘Author: ‘ .get_the_author_meta( ‘display_name’ );
?>

For retrieving all the metadata related to the author of the content that are in post the get_the_author_meta() and the_author_meta() functions are available for it. There is no need to pass the user ID parameter if this template tag is used inside the Loop. The user ID is required to determine what author metadata to retrieve if used outside of the Loop. User Data The $current_user global variable stores information on the currently logged-in user. This is the account that you are currently logged in to WordPress with. Following is an example showing how to display the logged-in user’s display name:

<?php
global $current_user;
echo $current_user->display_name;
?>

If you want to display a welcome message to your users this is a useful technique if you use in your site. You should to know that the the display name will default to the user’s username. If you want to display a welcome message to any user that is logged in in your site then you could use this code:

<?php
global $current_user;
if ( $current_user->display_name ) {
echo ‘Welcome ‘ .$current_user->display_name;
}
?>