-
-
Save champsupertramp/a1ed201cb05ff68bcecac4c7cd5b004b to your computer and use it in GitHub Desktop.
/** | |
* 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' ); |
PeregrinoHTX
commented
Feb 15, 2023
via email
hello guys, does this code still work? i have copy and pasted but i cant seem to get it to work.
Hi @workboy101 - this still works. Could you please share your shortcode?
hello @champsupertramp , the code works for "first_name", but not for "user_login" or "user_email", may I know how to solve it? thanks. [um_user meta_key="user_email"]
Hi @kinglin this code is for the data coming from the wp_usermeta
table. The user_login
and user_email
are coming from the wp_users
table. So this shortcode won't work with those meta keys.
thanks @champsupertramp , is there any way I can query wp_usermeta table?
i used this code
/**
-
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' );
perhaps i am setting it up wrong, pls help.
Been on this for almost 2 weeks now. Nothing happens when i use the code
hi @champsupertramp thanks for the code. I copied your latest one 2020 version into my functions.php child theme
but, it doesn't return any value when i use the shortcode [um_user user_id="" meta_key="first_name" ]
am i doing something wrong?
Hi @sambalbetawi Try removing the user_id=""
, just use [um_user meta_key="first_name" ]
Hello @champsupertramp,
Kindly save me from this much stress. I will never stop appreciating you, if you can walk me step by step, on how to achieve this below task. I have watch almost all YouTube videos, none of them specifically take on Redirect after registration. They focus much on redirect after login.
This is the task, I want to achieve.
I am using Ultimate Member, to register my users. So far it is great! Now, I want my users to be redirected to a custom page, which I have set, in the User Role set for the FORM.
What am I saying?
The Ultimate Member form, I'm talking about, has Subscriber Role set in its settings. Then, I edited Subscriber role, and set New registration to be redirected to a custom page. I type in the page url, which is a page on my website. (note, the page is typed in full. E. G https://example.com/verification)
Unfortunately, this is not working. Once user register, it just redirect to home page. This is awkward! User don't get to know, if their registration is successful or not.
But, if I pick the custom message, in the User Role settings, and write some custom message. The message will display.
Why is it acting this way? What have I done wrong???
I'm urgently in need of your reply, as my eLearn website is about to be launched. TutorLMS form is not satisfactorily, this is why I'm using Ultimate Member form.
Kindly, help. I wait here pls.
Thanks.
Waiting @champsupertramp
Please....
Hello,
Can we somehow achive to retrieveng a field that contains the pdf file ? The code works perfectly fine until the field with a pdf file and i need it display . If anyone can help me out i would appreciate it .
Hello @champsupertramp,
Kindly save me from this much stress. I will never stop appreciating you, if you can walk me step by step, on how to achieve this below task. I have watch almost all YouTube videos, none of them specifically take on Redirect after registration. They focus much on redirect after login.
This is the task, I want to achieve.
I am using Ultimate Member, to register my users. So far it is great! Now, I want my users to be redirected to a custom page, which I have set, in the User Role set for the FORM.
What am I saying?
The Ultimate Member form, I'm talking about, has Subscriber Role set in its settings. Then, I edited Subscriber role, and set New registration to be redirected to a custom page. I type in the page url, which is a page on my website. (note, the page is typed in full. E. G https://example.com/verification)
Unfortunately, this is not working. Once user register, it just redirect to home page. This is awkward! User don't get to know, if their registration is successful or not.
But, if I pick the custom message, in the User Role settings, and write some custom message. The message will display.
Why is it acting this way? What have I done wrong???
I'm urgently in need of your reply, as my eLearn website is about to be launched. TutorLMS form is not satisfactorily, this is why I'm using Ultimate Member form.
Kindly, help. I wait here pls.
Thanks.
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.
I will try this your suggestion and revert. Thanks.