Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cómo obtener datos de un usuario de WordPress
Plugin Name: MemberPerks
Description: Ofrece beneficios a tus usuarios más leales
Author: David Perálvarez
Version: 1.0.0
Author URI:
// Create the shortcode
add_shortcode( 'show_member_level', 'mp_show_member_level');
// Get the member level
function mp_show_member_level(){
// Get current user's ID
$memberID = get_current_user_id();
if( $memberID != 0 ):
// Get member's info
$memberInfo = get_userdata($memberID);
$memberName = $memberInfo->first_name;
$memberName = $memberInfo->user_login;
// Registration date
$memberRegistered = $memberInfo->user_registered;
$registrationDate = new DateTime($memberRegistered);
// Current Date
$currentDate = new DateTime("now", new DateTimeZone('Europe/Madrid'));
$memberLevel = $registrationDate->diff($currentDate)->m + ($registrationDate->diff($currentDate)->y*12) + 1;
<p class="mp-member-level">
<?php echo $memberName; ?>
tu <strong>nivel de perturbación en la fuerza es de
<?php echo $memberLevel; ?></strong>,
pronto te explicaré de qué va esto :)
$output = ob_get_contents();
return $output;
return; // User is not logged in
// Include styles
add_action( 'wp_enqueue_scripts', 'mp_add_styles' );
function mp_add_styles(){
wp_register_style( 'mp-styles', plugin_dir_url(__FILE__) . 'assets/css/mp-styles.css' );
wp_enqueue_style( 'mp-styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.