Skip to content

Instantly share code, notes, and snippets.

@tradesouthwest
Created February 25, 2019 23:51
Show Gist options
  • Save tradesouthwest/11eda7954d05093899b79ed963001a93 to your computer and use it in GitHub Desktop.
Save tradesouthwest/11eda7954d05093899b79ed963001a93 to your computer and use it in GitHub Desktop.
Only show nickname if not admin in a wordPress plugin
<?php
/**
* Only show nickname if not admin
*
* @since 1.0.0
*
* TODO option to toggle
*/
function vertycal_maybe_show_nickname( $author )
{
$author = wp_get_current_user();
if( current_user_can('administrator') )
{ $hrdscls = 'vrctl-hidden'; }
else { $hrdscls = 'vrtcl-block'; }
ob_start();
echo '<h4>' . esc_html__( 'Account: ', 'vertycal' )
. '<span class="' . esc_attr( $hrdscls ) . '">' . $author->nickname . '</span>' . '</h4>';
$output = ob_get_clean();
return $output;
}
//usage (inline): echo vertycal_maybe_show_nickname( $author );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment