-
-
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' ); |
Hi everyone
Using um_profile_id() to get the current UM user ID seems to make more sense instead of get_current_user_id()
@ALL
How can I use the received Profile Photo URL to dispolay the photo?
To use somethng like this
<img src= [um_user user_id="19" meta_key="profile_photo" ]>
Does not work?
Ty for help
Got it just used this
<img src= '[um_user user_id="19" meta_key="profile_photo" ]'>
instead of this
<img src= [um_user user_id="19" meta_key="profile_photo" ]>
the ' were the solution
Another Question
the meta user_login to display the Username does not work?
Ty für helping me
Hi, I am using this code in code snippet:
/**
* 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}'
*/
add_action('template_redirect','sc_init_um_user_shortcode');
add_action('init','sc_init_um_user_shortcode');
function sc_init_um_user_shortcode(){
add_shortcode( 'um_user', 'sc_um_user_shortcode' );
}
function sc_um_user_shortcode( $atts ) {
$atts = shortcode_atts( array(
'user_id' => get_current_user_id(),
'meta_key' => ''
), $atts );
extract( $atts );
if ( ! $user_id || empty( $meta_key ) ) return;
$raw_meta_value = get_user_meta( $user_id, $meta_key, true );
if( is_serialized( $raw_meta_value ) ){
$meta_value = unserialize( $raw_meta_value );
}else if( is_array( $raw_meta_value ) ){
$meta_value = implode(",",$raw_meta_value);
}else{
$meta_value = $raw_meta_value;
}
return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value, $raw_meta_value, $user_id );
}
add_filter("um_user_shortcode_filter__profile_photo","um_user_shortcode_filter__profile_photo", 10, 3);
function um_user_shortcode_filter__profile_photo( $meta_value, $raw_meta_value, $user_id ){
return UM()->uploader()->get_upload_user_base_url( $user_id )."/".$meta_value;
}
and this short code:
[um_user meta_key="image_realtor"]
as I have create an image upload field with "image_realtor" meta. But it is showing a value like this:
stream_photo_36318a1a_76850750071ddc5c51a9c62d3eca15a26145531a.png
No image is showing. It is working for other fields like number or text field.
Hi @aknahin
Replace this:
add_filter("um_user_shortcode_filter__profile_photo","um_user_shortcode_filter__profile_photo", 10, 3);
function um_user_shortcode_filter__profile_photo( $meta_value, $raw_meta_value, $user_id ){
return UM()->uploader()->get_upload_user_base_url( $user_id )."/".$meta_value;
}
with the following:
add_filter("um_user_shortcode_filter__image_realtor","um_user_shortcode_filter__image_realtor", 10, 3);
function um_user_shortcode_filter_image_realtor( $meta_value, $raw_meta_value, $user_id ){
return UM()->uploader()->get_upload_user_base_url( $user_id )."/".$meta_value;
}
Thanks for your reply. But unfortunately, that hasn't worked. even after changing this code there is nothing.
I had this working fine, and then my theme updated. I have gone back and put the code in the header, and the short code is still there, but I cannot make it work now. It's just showing the short code. What am I forgetting?
Hi @PeregrinoHTX please check if your theme has stopped supporting shortcode in the post/page templates. How do you add the custom shortcode? Is it when you edit/add a page/post?
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.
Is there a way to pull the user's email address and insert it into html?
I can get the user's email address to display using your code snippet and "[um_user meta_key="user_email"]"
But I would like that content to behave as a link:
<a href="mailto:__________________">Send Email</a>