Skip to content

Instantly share code, notes, and snippets.

@champsupertramp
Last active August 31, 2023 09:06
Show Gist options
  • Save champsupertramp/a1ed201cb05ff68bcecac4c7cd5b004b to your computer and use it in GitHub Desktop.
Save champsupertramp/a1ed201cb05ff68bcecac4c7cd5b004b 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' );
@Cbookwap
Copy link

Cbookwap commented Aug 24, 2023

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.

@Cbookwap
Copy link

Waiting @champsupertramp

Please....

@Bilgehano
Copy link

Bilgehano commented Aug 30, 2023

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 .

@champsupertramp
Copy link
Author

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.

@Cbookwap
Copy link

I will try this your suggestion and revert. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment