User Meta Manager
[resolved] Shortcodes for displaying built-in meta (5 posts)

  1. Vaughan
    Posted 3 years ago #

    Thanks for a great plugin. Apologies for the basic question, have checked through the forums here and tried various possibilities.

    I am hoping to use UMM to replace the current plugin I have that uses shortcodes to display user meta in posts/pages. UMM does this great with custom meta but I've been unable to get it to display the majority of built-in/default meta except for first_name and last_name.

    Can UMM display fields such as user_email, user_url, user_registered, display_name, user_nicename, user_level etc? For me, these just display as blank.

    Otherwise, a very robust and powerful plugin - keep up the great work!


  2. President McCheese
    Plugin Author

    Posted 2 years ago #


    Presently there is not a short code for displaying core user meta data. However, I will consider this for the upcoming version.
    Thanks for the input.


  3. Vaughan
    Posted 2 years ago #

    Thanks Jason - it would be great to have an all-in-one user meta plugin. And yours is the most full-featured of all the ones out there so far.

  4. acub
    Posted 2 years ago #

    You don't need a plugin for that. I made this function. Of course, I could wrap it up and make a simple plugin out of it, but I've never been a fan of the plugin support hassle.
    Add this to functions.php in your theme's folder:

    add_shortcode('gutt-u', 'gutt_get_user_attribute');
    function gutt_get_user_attribute($atts = array()) {
    	global $current_user;
    	extract( shortcode_atts( array(
    		'id' => $current_user->ID,
    		'login' => '',
    		'email' => '',
    		'slug' => '',
    		'field' => 'display_name'
    		), $atts) );
    	if ($login || $email || $slug) {
    		if ($login) $gatt_user = get_user_by('login', $login);
    		elseif ($email) $gatt_user = get_user_by('email', $email);
    		else $gatt_user = get_user_by('slug', $slug);
    	elseif ($id > 0) $gatt_user = get_user_by('id', $id);
    	else return;
    	if (in_array($field, array( 'ID', 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_regitered', 'display_name')))
    			return $gatt_user->$field;
    		else return $gatt_user->__get($field);

    How it works: Use [gutt-u] with id, login, email, slug and field parameters.

    id - id of the user you want to retrieve data for; defaults to current user and function doesn't return anything if id (or login, or email, or slug) is missing and current user is not logged in;

    login - login (user_login) of the user you want to retrieve data for; overrides id, email and slug;

    email - email of the user you want to retrieve data for; overrides id and slug;

    slug - slug (user_nicename) of the user you want to retrieve data for; overrides id;

    field - the field you want to retrieve from the user; defaults to display_name. It can be any default WP field or any user meta field as long as it exists, except user_password (I chose not to include it, but can be added to the fields array if needed).

    [gutt-u] => returns display_name of current user.
    [gutt-u field=id] => returns ID of current user.
    [gutt-u email=mail@domain.com field=some_user_meta_field] => returns the some_user_meta_field of the user registered with mail@domain.com.
    [gutt-u slug=acub field=user_registered] => returns the date of registration for the user with user_nicename = "acub"

    I doubt sanitization is needed. From the few tests I've made, if no user is found or if the field doesn't exist, it just returns nothing.

    @Jason, feel free to put my code to good use if you find it useful. Thank you for a robust plugin.

  5. President McCheese
    Plugin Author

    Posted 2 years ago #

    @ acub, This feature is already added to User Meta Manager version 3.0.3, but thanks for posting your solution anyway!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • User Meta Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic