[su_user field="display_name" user_id="2"]
This shortcode allows you to display user data.
Option name | Possible values | Default value |
---|---|---|
field User data field name. Custom meta field names are also allowed. | first_name (First Name) last_name (Last Name) nickname (Nickname) description (Description) locale (Locale) display_name (Display name) ID (ID) user_login (Login) user_nicename (Nice name) user_url (URL) user_registered (Registered) user_status (Status) | display_name |
default This text will be shown if data is not found | Any text value | – none – |
before This content will be shown before the value | Any text value | – none – |
after This content will be shown after the value | Any text value | – none – |
user_id You can specify custom user ID. Leave this field empty to use an ID of the current user | Any text value | – none – |
filter You can apply custom filter to the retrieved value. Enter here function name. Your function must accept one argument and return modified value. Name of your function must include word filter. Example function: function my_custom_filter( $value ) {return 'Value is: ' . $value;} | Any text value | – none – |
Since version 5.12.8 the plugin only allows you to display a set of specific user fields (see the Options table above for the full list). Any fields that are not whitelisted will trigger the “field is not allowed” error.
This mechanism was introduced to improve the plugin security, since the shortcode can be used, for example, by a contributor user to access sensitive information about any user of the site.
The list of allowed fields can be extended with the su/config/user_fields
filter. To whitelist a specific field, add the code below to the end of the functions.php file of active theme. Please be careful, since the added field can be used by other writers on your site.
add_filter( 'su/config/user_fields', function( $fields ) {
// The field 'user_registered' will be whitelisted
// and the 'User Registration Date' string will be used in the Insert Shortcode window
$fields['user_registered'] = 'User Registration Date';
return $fields;
} );