Hello. I am currently working on a local test project that includes a custom toolbar at the top of the page. This toolbar shows different content depending on if the user is logged-in or out. Currently, I have this toolbar working perfectly, but all the code that I’ve used to create it is in a header.php file. Ideally, I would like to move this information into a custom WordPress plugin so that it is portable and uses shortcodes to display content.
I have checked the WordPress Codex and Developer information, have taken some online courses on creating plugins, and Googled to find as much information as I can to accomplish my goal.
I am fine with writing the vast majority of the code needed to create this plugin, but can you help me understand how to access
WP_Userdata in a plugin using
wp_get_current_user(), and in a way that will be secure?
Here is what I have that is working in the header.php file:
// Current User Information
$current_user = wp_get_current_user();
$current_user_display_name = $current_user->display_name;
$current_user_id = $current_user->ID;
* example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
<div id="toolbar-container" style="top: 0px;">
<ul class="col-sm-6 col-md-6 col-lg-5 nav navbar-nav navbar-right user-topbar">
<li class="dropdown pull-right">
<span class="welcome-text">Welcome, </span>
<a href="#" class="dropdown-toggle welcome-dropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo $current_user_display_name; ?><span class="caret"></span></a>
<li role="separator" class="divider"></li>
If I could just get help on the right track that would be great! Thank you!