User meta shortcodes

Contributors: Richard Vencu

Tags: user, user-meta, shortcode

Requires at least: 2.7

Tested up to: 3.5

Stable tag: 0.3.1

Use user meta as shortcode in post content without edit your theme files.

== Description ==

USAGE:

use {userinfo field="fieldname"} or {authorinfo field="fieldname"} shortcodes in your post content to show the „fieldname” meta value from the user-meta for the current logged-in user or for the post author without editing your theme files.

EXAMPLES:

{userinfo field="last_name"}

returns the last name of the current logged-in user. If no user is logged in then the value is empty string

List of some of the available meta field names: ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, display_name, first_name, last_name, nickname, description, user_level, admin_color (Theme of your admin page. Default is fresh.), closedpostboxes_page, nickname, primary_blog, rich_editing, source_domain

{authorinfo field="last_name"}

returns the last name of the current post/page author.

{authorinfo field="ID"}

returns the user ID of the current post/page author.

List of some of the available meta field names: user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name, nickname, first_name, last_name, description, jabber, aim, yim, user_level, user_firstname, user_lastname, user_description, rich_editing, comment_shortcuts, admin_color, plugins_per_page, plugins_last_view, ID

If you add custom user meta via additional plugins, then the meta should be available for the above shortcodes

== Installation ==

0. Download the plugin here: User-meta-shortcodes
1. Upload `user-meta-shortcodes` folder to the `/wp-content/plugins/` directory

2. Activate the plugin through the ‘Plugins’ menu in WordPress

== Screenshots ==

not applicable

== Frequently Asked Questions ==

Q. Can I use another user besides current user or post author?

A. It would be added in future versions of the plugin

33 comments

  1. It would be nice to have a option to disable the span tag that is also returned. I would like to use this plugin to fill in a custom contact form, but the span tag gets inserted into the value attribute.

  2. Hi Shawn,

    I am not particularly proud of this plugin, just wanted to check how it works to make one.

    I have a better suggestion, you can drop this code into your theme functions.php file, the span element is taken out now:

    function userInfoSc ($attributes) {

    global $user_info, $user_ID;

    $fieldname = $attributes[‘field’];

    get_currentuserinfo();

    $user_info = get_userdata($user_ID);

    return $user_info->$fieldname;

    }

    add_shortcode(‘userinfo’,’userInfoSc’);

    function authorInfoSc ($attributes) {

    $fieldname = $attributes[‘field’];

    $author_info = get_the_author_meta($fieldname);

    return $author_info;

    }

    add_shortcode(‘authorinfo’,’authorInfoSc’);

  3. hi …

    Do you know if there is any way to perform conditional checks on the userinfo returned by the shortcode ?

    [userinfo field=”English” if=”true”]you speak english[/userinfo]
    [userinfo field=”English” if=”false”]you don’t speak english[/userinfo]

    or something like that ?

    Thanks 🙂

  4. Actually it would be possible but it needs some coding. The main issue is where would you store the specific information such as the language of the user.

    1. The shortcode is for any kind of user information. To achieve what you look for you need to write:

      Hi [userinfo field=”first_name”]

  5. Hi,

    I love the plugin. I have one question though whcih hope you can help. I have added extra fields on the user profile to display images. When I use the shortcodes tehy display the url to the images rather than the images themselves. Is there a way to make it do display the image rather than the URL?
    I am using the following plugin to add the fields http://teachingyou.net/wordpress/add-and-remove-wordpress-user-profile-fields/
    Thank you in advance and for this little great plugin 🙂
    Tassos

    1. I think it is quite complicated to figure out if the field is an image or anything else.

      I suggest you try to insert direct HTML code into your meta field like

      < img src="" / >

      then make sure the src parameter points to an existing image…

  6. Hi,
    great plugin, thanks a lot for developing.

    I have a problem (I think is realted to the span issue in the first comment)

    I am trying to use a shortcode in a URL in my post to link a user to their content.

    For example

    http://example.com/farms/user/%5Buserinfo field=”user_login”]

    However this will not render right. It looks like the span tag is cuasing an issue from what I can see.

    I tried your code above in the functions.php file but it brought down the site, would not load.

    Any suggestions on how to get this shortcode to work within the URL?

    Thanks in advance

    1. Hi, I solved this issue with a new version, please check to update within few hours.

      I also made a test page for it here Test

  7. Suggestion.
    Why not include the parameter to show user gravatar?
    I’m pretty sure it’ll be useful. My quick search on google showed that currently there’s no plugin or shortocode to show gravatar for login users.

  8. hello,
    I currently use user meta to create a user registration form front for members; Now I would like to display in front all users and their data by retrieving shorcodes as a kind of address book, do you think it’s possible?

    thanks

  9. I have deployed your WordPress plugin, User meta shortcodes, as an integral part of an ambitious project, which I presently coordinates. A project, which I dubbed, encouraging the re-evoking of self-organizing networks and supportive systems within modern societies. I would love to acknowledge and recognize your contribution to the present success of the project.

    Will you please send me an email address, where I could send an explanation email, which outline and provide more details on the what, how and why of the project and the implication of your involvement by recognition.

    Many thanks

    Jan

  10. Just wanted to say that in response to your comment that you ‘aren’t proud’ of this plugin, I think it is a great plugin. Extremely useful. I would be proud of it! Can’t wait for more of your plugins!

    1. Thank you, Stu. You are too kind. Fact is I am managing my wife’s dental clinic now and I face WordPress development almost every day for the clinic internet presence. I will try to incorporate my best ideas into plugins useful for all people.

  11. Is the anyway to remove the need quotation marks from the shortcode.

    for example instead of [userinfo field=”user_email”] use [userinfo field=user_email]

    The quote marks tend to break links when trying to use the users data for sending data to other areas of the site… for example.

    in my profile page i have some link that i want to use like subcribe to my newsletters

    as you can see, having the quotes will break the link.

    basically im trying to keep my mebers from having to retype their info on the phplist form when the click on the link to subscribe. its no big deal to have to retype their own info, but why make them do it when i already have their info and can just prepopulate it for them uing a baic POST/GET call.

    1. I have been struggling myself with quotation marks. I think if value contains any space you should use marks (try both ” and ‘ ).

      I noticed quotation marks are needed or not depending on the PHP installation of the website so I cannot predict when or why the plugin works one way or another.

  12. hi Rihard
    would be possible to get a complete list of the meta field names and what additional plugins to add?
    I also retrieve the address and some fields added with „user Cimy extra field”
    thanks
    Maurizio

  13. Hi! I love your plugin. ONe question… is possible to add this short code in the email? I mean.. am using Contact Form 7 and i would like to send the first name and last name from the database in the email contact form 7. Do you think is possible? Thank in advance.

    1. I have no idea. The shortcode should be processed at server, so when the email is going out the replacement with data should be already done.

      This is a question to address to other plugins makers, just ask: can I process shortcodes inside your ??? field?

  14. Hi
    Great plugin!
    Is there anyway i can change how the user_registered tag is displayed?
    Now its

    2013-01-13 21:10

    Could i make it just go

    13-01-2013 ?

    Best regards
    Nicolai

  15. Richard I just had to leave you a comment to say this plugin is the best user meta shortcode plugin out there! I have played around with a few different plugins, free and premium, and hands down yours beats them all!

    I had been looking for a plugin which just works, straight out of the box, without having to make any tweaks/edits. Most of the plugins I tried were OK, but they were very bloated or needed multiple steps to achieve the simplest of little things. Or they had problems and would not work well inside of the other plugins I was using.

    With your plugin, I just looked at the sample shortcodes on the wordpress page and it was good to go! Worked like a charm!

    Thank you for making a brilliant plugin and giving it away for free! Wishing you and your family all the best! God bless!

    1. So it is true, sometimes the simplest things in life tend to be the best. I am happy my work was fit to help you

  16. Notice: Undefined variable: default in /www/wdc2015/wp-content/plugins/user-meta-shortcodes/user-meta-shortcodes.php on line 103

    I’m finding the plugin very useful, but I’m getting an error. it’s almost 1 am my time been working for 16 hours I can no longer read code. Can you please help?

  17. I love the concept of this plugin, it is exactly what I am looking for.

    I am having trouble getting the shortcode to display the data I am asking for. I am testing [userinfo field=”last_name”]{{empty}}[/userinfo] and it outputs . There is a valid Last Name that I have verified in the database. Currently I am the admin and sole user. Is me being an admin an issue?

    Obviously the plugin works for many people, I must be missing something on my end.

    I am using WP 4.1.1

    Thanks!

    1. If you try only [userinfo field=”last_name”] what happens? Make sure you use proper ” characters

  18. This plugin is fantastic. Is there any way to return an „otheruser” by their email instead of „login”? (if so, then this perfect!)
    e.g.
    [otheruserinfo field=”avatar” email=”user@example.com”]

    1. Well, no, at least not yet. But thank you for the idea, I will soon produce a new version to add this feature.

Leave a comment

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *