Last active
December 8, 2024 04:32
-
-
Save champsupertramp/a1ed201cb05ff68bcecac4c7cd5b004b 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' ); |
I will try this your suggestion and revert. Thanks.
I inserted the code snippet in my functions.php file as you can see here -- https://prnt.sc/7PmdDPBzGpnY
Then I added the shortcode [um_user user_id="" meta_key="first_name" ]
and [um_user user_id="" meta_key="user_email" ]
on a page, as you can see here--- https://prnt.sc/qbI-fSS9MND0
Unfortunately, no user information is seen on the frontend, as you can see here --- https://prnt.sc/EKoSztzFyirl
Please, what is wrong?
Is the code still working? --or is there an updated version of it?
How do I fix this issue?
Special Regards.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @peculiardigitals Sorry for the late response. How many roles are assigned to the Subscriber? If there's more than 1 role, you need to make the Subscriber role the Primary role by adding a Priority number in the role settings. This means by adding a priority number, the register form will use this role's settings for redirection and others.