Skip to content

Instantly share code, notes, and snippets.

@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:66259b3282b232a5b447
Last active January 18, 2023 04:52
Private Messages API: Get number of unread messages for a user
global $um_messaging;
$user_id = 'xx'; // enter user id here
$count = $um_messaging->api->get_unread_count( $user_id );
echo $count;
@ultimatemember
ultimatemember / gist:78aac8b268b2c75489f0
Last active September 13, 2022 11:58
Apply your own custom validation to a field
/*
In this code sample, you can learn how to apply custom
validations on any fields you want.
This can be done using these steps:
1. Edit the field in backend (field modal)
2. Where it asks for field validation choose "Custom"
3. Enter a unique validation action name e.g. my_8numbers
@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:44d89249baf9f73b89d6
Last active December 21, 2020 15:08
Using the new RESTful API to process remote queries
// API Request
$url = 'http://localhost/um-api/get.user/?id=1';
// Include your public key and token to the URL
$url = add_query_arg('key', '75d9a913782eee3d990e4464ce26213e', $url );
$url = add_query_arg('token', 'bae6ee38cf02a50a0ac8259eed34ceb9', $url );
// Process your request
$request = wp_remote_get( $url );
$response = json_decode( wp_remote_retrieve_body( $request ) , true );
@ultimatemember
ultimatemember / gist:643cd90967e5e415378d
Last active June 20, 2020 21:32
Custom profile tab example: showing user pages
/* add a custom tab to show user pages */
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$tabs['pages'] = array(
'name' => 'Pages',
'icon' => 'um-faicon-pencil',
'custom' => true
);
return $tabs;
}
@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:5f725bff6bcf79d2988e
Last active January 22, 2020 19:00
Using notifications API to add custom notifications
/*
This code sample shows you how to use the API to create
and add custom notifications (for real-time notifications)
plugin.
STEP 1: You need to extend the filter: um_notifications_core_log_types with your
new notification type as follows for example
*/
@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: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');