Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
ultimatemember / gist:08c7f3369f49021cb749
Last active April 4, 2018 14:20
How to stop registration using Ultimate Member action hooks
/*
You need to hook into um_submit_form_errors_hook with a
priority over 10.
You can stop registration here if the customer_code field does not
match the value you want "ALLOWED_VALUE" in this example
*/
@ultimatemember
ultimatemember / gist:02311172f7b42adeb3ed
Last active January 17, 2018 07:12
Delete display_name usermeta from all users
$users = get_users( array('fields' => 'ID') );
foreach( $users as $user_id ) {
delete_user_meta( $user_id, 'display_name' );
}
@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') ) );
}
@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: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: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: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: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: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: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 );