Skip to content

Instantly share code, notes, and snippets.

@denisbaranov
denisbaranov / Add new account tab with custom WooCommerce fields.php
Last active June 18, 2021 10:34
This example shows how to add custom Account tab with WooCommerce fields in Ultimate Member.
<?php
/**
* This example shows how to add custom Account tab with WooCommerce fields in Ultimate Member.
* See the article https://docs.ultimatemember.com/article/1504-how-to-add-custom-woocommerce-fields-to-account
*
* This example adds the tab 'wc_custom' that contains the field 'wc_custom_01'. You can add your own tabs and fields.
* Important! Each account tab has an unique key. Replace 'wc_custom' to your unique key.
*
* You can add this code to the end of the file functions.php in the active theme directory.
@denisbaranov
denisbaranov / Add new profile tab with a form.php
Last active January 25, 2024 01:16
This example shows how to add a new tab into the Profile page of the Ultimate Member.
<?php
/**
* This example shows how to add a new tab into the Profile page of the Ultimate Member.
* See the article https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles
*
* This example adds the tab 'mycustomtab' that contains the field 'description'. You can add your own tabs and fields.
* Important! Each profile tab has an unique key. Replace 'mycustomtab' to your unique key.
*
* You can add this code to the end of the file functions.php in the active theme (child theme) directory.
@denisbaranov
denisbaranov / Show default field value on if field value is empty.php
Last active July 7, 2020 11:22
How to show default field value on "view" mode if field value is empty.
<?php
/**
* This code shows default field value on "view" mode if field value is empty in the Profile form of the Ultimate Member.
*
* You can add this code to the end of the file functions.php in the active theme (child theme) directory.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/
*/
@denisbaranov
denisbaranov / Manual approve a new member after email verification
Last active November 24, 2022 11:47
The way to use both Email verification and Admin review in Ultimate Member. This custom code works if the user role setting "Registration Status" is "Require Email Activation". This code snippet removes the default function, which handles email confirmation, and adds a new instead. Add this code to the end of the functions.php file in the active…
/**
* Set status 'awaiting_admin_review' after the Email verification
*/
function my_activate_account_via_email_link() {
if ( isset( $_REQUEST['act'] ) && $_REQUEST['act'] == 'activate_via_email' && isset( $_REQUEST['hash'] ) && is_string( $_REQUEST['hash'] ) && strlen( $_REQUEST['hash'] ) == 40 &&
isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { // valid token
$user_id = absint( $_REQUEST['user_id'] );
delete_option( "um_cache_userdata_{$user_id}" );
um_fetch_user( $user_id );
@denisbaranov
denisbaranov / Display fallback value '--' if the field value is empty.php
Last active December 7, 2020 11:21
​Empty fields are hidden on profile form "view" mode. It may look weird. You may use the code snippet below to display fallback value "--" for the empty fields. It works only for the "view" mode. Just add this code snippet to the functions.php file in the active theme (child theme) directory.
<?php
/**
* Displays fallback value if the field value is empty. For the "view" mode only.
* @param string $value
* @param string $default
* @param string $key
* @param string $type
* @param array $data
* @return string
@denisbaranov
denisbaranov / Validate the email address by domain on registration.php
Last active December 7, 2023 12:19
The following code requires @gmail.com as an email 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.
<?php
/**
* This example shows how to validate the email address by domain on registration.
* The code below requires a user email to be collected during registration.
*
* Change the array $allowed_email_domains - add or remove what you need.
* Add this code snippet to the end of the file functions.php in the active theme directory.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
@denisbaranov
denisbaranov / Add several tabs to the profile.php
Last active December 13, 2020 12:59
This example shows how to add several tabs with custom shortcodes into the Profile page of the Ultimate Member.
<?php
/**
* This example shows how to add several tabs with custom shortcodes into the Profile page of the Ultimate Member.
* You can add custom code to the end of the file functions.php in the active theme directory.
* Important! Each tab must have a unique key.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/
*/
@denisbaranov
denisbaranov / Custom field that extends the 'checkbox' field type.php
Created June 25, 2020 11:42
This example shows how to add custom predefined field that extends the 'checkbox' field type in Ultimate Member
<?php
/**
* This example shows how to add custom predefined field that extends the 'checkbox' field type in Ultimate Member
* You can add custom code to the end of the file functions.php in the active theme directory.
* Important! You have to change variables: $type, $title, $options
*
* @author Ultimate Member support <support@ultimatemember.com>
* @package Ultimate Member
* @since 2020-06-25
@denisbaranov
denisbaranov / Restore capabilities 'edit_user' and 'delete_user'.php
Created November 18, 2020 14:00
This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin.
<?php
/**
* This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin.
*
* You can add this code to the end of the file functions.php in the active theme (child theme) directory.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/
*
@denisbaranov
denisbaranov / um_grouped_filtes.php
Last active February 12, 2023 17:59
This example shows how to group several filters in the Members Directory of the Ultimate Member.
<?php
/**
* This example shows how to group several filters in the Members Directory of the Ultimate Member.
* For example there are three phone fields in the profile ("Phone", "Phone number", "Mobile Number"),
* but you want to use a single filter "Phone number" to filter by these three fields in the Member Directory.
*
* Note: This example works if the setting "Enable custom table for usermeta" is turned off.
* See the gist https://gist.github.com/denisbaranov/dd8e7c0845af35eeba2bdd08f5f72a76 otherwise.
*