learndash_usermeta_shortcode_field_value_display
Filters the value displayed for a user meta field within a LearnDash shortcode before rendering it.
add_filter( 'learndash_usermeta_shortcode_field_value_display', $callback, 10, 3 );
Description
Filters the display value for user meta fields shown via the `[uo_usermeta]` shortcode. Developers can modify the output value, access shortcode attributes, and the list of available user meta fields. Useful for customizing how user data is presented in certificates or other output.
Usage
add_filter( 'learndash_usermeta_shortcode_field_value_display', 'your_function_name', 10, 3 );
Parameters
-
$value(mixed) - This parameter holds the current value being displayed for the usermeta field, which can be modified by the filter.
-
$atts(mixed) - This parameter holds the current value of the user meta field being displayed by the shortcode.
-
$usermeta_available_fields(mixed) - This parameter contains an array of attributes passed to the `uo_usermeta` shortcode, including the 'field' and 'user_id'.
Return Value
The filtered value.
Examples
add_filter(
'learndash_usermeta_shortcode_field_value_display',
'my_learndash_custom_usermeta_display',
10,
3
);
/**
* Filters the display value of a user meta field for the `uo_usermeta` shortcode.
* This example appends "(custom)" to the displayed value if the field is 'user_email'.
*
* @param mixed $value The original value of the user meta field.
* @param array $atts The attributes passed to the `uo_usermeta` shortcode.
* @param array $usermeta_available_fields An array of available user meta fields.
*
* @return mixed The modified or original value for display.
*/
function my_learndash_custom_usermeta_display( $value, $atts, $usermeta_available_fields ) {
// Check if the field being displayed is 'user_email'
if ( isset( $atts['field'] ) && 'user_email' === $atts['field'] ) {
// Append a custom string to the email address for display
$value = $value . ' (custom)';
}
// Return the (potentially modified) value
return $value;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/includes/tcpdf-certificate-code.php:1120
public static function simplified_usermeta_shortcode( $atts ) {
// Set defaults for attributes
$atts = shortcode_atts(
array(
'field' => 'user_login', // Default field
'user_id' => get_current_user_id(), // Default to current user
),
$atts,
'uo_usermeta'
);
// Fetch user data
$user_data = get_userdata( (int) $atts['user_id'] );
$value = '';
if ( $user_data && isset( $user_data->{$atts['field']} ) ) {
// Return the value of the specified field
$value = $user_data->{$atts['field']};
}
$usermeta_available_fields = array( $atts['field'] => $atts['field'] );
// Use the same filter in `usermeta` shortcode for backwards compatibility
return apply_filters( 'learndash_usermeta_shortcode_field_value_display', $value, $atts, $usermeta_available_fields );
}