This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Display user shortcode | |
Plugin URI: https://vitorials.net/ | |
Description: Display name and avatar of the logged in users | |
Version: 1.0 Author: Alex Kovalenko | |
Author URI: https://vitorials.net/ | |
Text Domain: Display user shortcode | |
Domain Path: /languages | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check for function with the same name | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
if ( ! function_exists( 'alex_vitorials_get_user_unique_name' ) ) { | |
function alex_vitorials_get_user_unique_name(){ | |
if ( ! is_user_logged_in() ) { | |
return; | |
} | |
else { | |
$user = wp_get_current_user(); | |
$avatar = get_avatar( $user->ID, 40 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function alex_vitorials_get_user_unique_name(){ | |
if ( ! is_user_logged_in() ) : ?> | |
<?php return; ?> | |
<?php else: ?> | |
<?php $user = wp_get_current_user(); | |
$avatar = get_avatar( $user->ID, 40 ); | |
$user_nicename = '<span>'; | |
$user_nicename .= get_userdata( $user->ID )->user_nicename; | |
$user_nicename .= '</span>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$avatar = get_avatar( $user->ID, 40 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode( 'user-ID', 'alex_vitorials_get_user_unique_name' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function alex_vitorials_get_user_unique_name(){ | |
if ( ! is_user_logged_in() ) { // check whether our user is logged in or not return; } | |
// if not, return nothing | |
else { $user = wp_get_current_user(); | |
$user_nicename = get_userdata( $user->ID )->user_nicename; | |
return $user_nicename; } // return users nickname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// display name and avatar | |
function alex_vitorials_get_user_unique_name(){ | |
// check whether our user is logged in or not | |
if ( ! is_user_logged_in() ) { return; } // if not, return nothing | |
else { //our code would go here } // return something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// display name and avatar | |
function alex_vitorials_get_user_unique_name(){ } |
NewerOlder