Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
ultimatemember / gist:d98861b4c14a1540291b
Last active June 23, 2019 15:36
Conditionally sync UM user role based on WP role (Gravity forms)
/* This code will sync the UM role based on WP role using gravity registration */
add_action("gform_user_registered", "um_gravity_user_role_sync", 200, 4);
function um_gravity_user_role_sync($user_id, $config, $entry, $user_pass) {
$user = new WP_User( $user_id );
$wp_role = $user->roles[0];
// if WP role is subscriber, set UM role to member
if ( $wp_role == 'subscriber' ) {
@ultimatemember
ultimatemember / gist:d1cdd1ffb04b74743c6b
Last active August 14, 2017 23:39
Sync UM role during Gravity user registration
/* This code will update the user registered with gravity
form and allow you to give him a specific UM community role */
add_action("gform_user_registered", "um_gravity_user_role_sync", 88, 4);
function um_gravity_user_role_sync($user_id, $config, $entry, $user_pass) {
update_user_meta($user_id, 'role', 'member'); // member can be your UM role slug
}
@ultimatemember
ultimatemember / gist:962dcd6eaa6db560f6c7
Last active January 26, 2018 01:18
Sync UM / WP User Role During User Approval
/* This example syncs both UM / WP role during user approval */
add_action('um_after_user_is_approved', 'sync_um_and_wp_role', 99 );
function sync_um_and_wp_role( $user_id ) {
// Get UM role
$role = get_user_meta( $user_id, 'role', true );
// Set WordPress role for same user
$wp_user_object = new WP_User( $user_id );
@ultimatemember
ultimatemember / gist:5f093ac300baa1d2a5f1
Last active October 25, 2018 01:50
Example: block any registration that does not use @gmail as mail provider
/*
The following code will require @gmail.com as domain
for user registrations.
You can change @gmail.com to any provider you want.
The code below requires a user email to be collected during registration
*/
add_action('um_before_new_user_register', 'require_google_email_for_signup');
@ultimatemember
ultimatemember / gist:1d81b59cd8b21f67b36c
Last active January 22, 2020 19:03
Add a hidden field to registration forms
add_action('um_after_register_fields', 'add_a_hidden_field_to_register');
function add_a_hidden_field_to_register( $args ){
echo '<input type="hidden" name="field_id" id="field_id" value="HERE_GOES_THE_VALUE" />';
}
@ultimatemember
ultimatemember / gist:8cdaf61e7bd9de35512c
Last active April 19, 2021 20:35
Extending Ultimate Member Profile Menu using Hooks
/* First we need to extend main profile tabs */
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
@ultimatemember
ultimatemember / gist:f7eab149cb33df735b08
Last active April 30, 2023 01:17
Extend Ultimate Member Account page with custom tabs/content
/* add new tab called "mytab" */
add_filter('um_account_page_default_tabs_hook', 'my_custom_tab_in_um', 100 );
function my_custom_tab_in_um( $tabs ) {
$tabs[800]['mytab']['icon'] = 'um-faicon-pencil';
$tabs[800]['mytab']['title'] = 'My Custom Tab';
$tabs[800]['mytab']['custom'] = true;
return $tabs;
}
@ultimatemember
ultimatemember / gist:6c8d18b2b0869662d203
Last active August 29, 2015 14:15
Check when user updates e-mail via account page
add_action('um_account_pre_update_profile', 'did_user_change_email', 10, 2 );
function did_user_change_email( $changes, $user_id ) {
$data = get_userdata($user_id);
if ( isset( $changes['user_email'] ) && $data->user_email != $changes['user_email'] ) {
// user e-mail changed! Do something
}
}
@ultimatemember
ultimatemember / gist:cebf7407ea1c93dea904
Last active August 29, 2015 14:15
Control the output of a textfield using UM filter hooks
/*
This is a sample filter that assumes your textfield meta key is "buttoncode"
The filter below allow you to change the output dynamically
to show a shortcode instead of the value entered for that field
Use in theme functions.php and do not have to rely on UM core
*/
@ultimatemember
ultimatemember / gist:296161825d8127fa28fc
Last active February 28, 2018 15:59
Stop registration if customer_code field does not equal ABCDE
add_action('um_submit_form_errors_hook', 'check_customer_code', 100 );
function check_customer_code( $args ){
if ( isset( $args['customer_code'] ) && $args['customer_code'] != 'ABCDE' )
exit( wp_redirect( add_query_arg('err', 'invalid_customer_code') ) );
}