Contributors: Richard Vencu
Tags: user, user-meta, shortcode
Requires at least: 2.7
Tested up to: 3.0-RC1
Stable tag: 0.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
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.
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’);
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
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.
Hi
I would just like to add the following:
Hi [firstname]
Is there an easy way?
The shortcode is for any kind of user information. To achieve what you look for you need to write:
Hi [userinfo field="first_name"]