Forked from champsupertramp/Ultimate Member - User meta shortcodes
Created
October 25, 2022 12:33
-
-
Save lorens247/817b3bc0f312cc104ccc401e28d29b23 to your computer and use it in GitHub Desktop.
Ultimate Member - User meta shortcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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