Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himanshuahuja96/4ebbee668fc994ea2c3514854cdb1792 to your computer and use it in GitHub Desktop.
Save himanshuahuja96/4ebbee668fc994ea2c3514854cdb1792 to your computer and use it in GitHub Desktop.
Ultimate Member - User meta shortcodes
/**
* Returns a user meta value
* Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
* meta_key is the field name that you've set in the UM form builder
* You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
*/
function um_user_shortcode( $atts ) {
$atts = extract( shortcode_atts( array(
'user_id' => get_current_user_id(),
'meta_key' => '',
), $atts ) );
if ( empty( $meta_key ) ) return;
if( empty( $user_id ) ) $user_id = get_current_user_id();
$meta_value = get_user_meta( $user_id, $meta_key, true );
if( is_serialized( $meta_value ) ){
$meta_value = unserialize( $meta_value );
}
if( is_array( $meta_value ) ){
$meta_value = implode(",",$meta_value );
}
return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
}
add_shortcode( 'um_user', 'um_user_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment