Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / um_activity_get_download_link_direct.php
Last active February 25, 2025 21:09
Code snippets for the "Social Activity" extension
@yuriinalivaiko
yuriinalivaiko / um_fix_selectWoo_conflict.php
Last active February 4, 2025 11:30
Code snippets for the "WooCommerce" extension
<?php
// Enqueue the "select2" script earlier to avoid a conflict with "selectWoo".
add_action( 'admin_enqueue_scripts', 'um_fix_selectWoo_conflict' );
add_action( 'wp_enqueue_scripts', 'um_fix_selectWoo_conflict' );
function um_fix_selectWoo_conflict() {
if ( wp_script_is( 'select2' ) && wp_script_is( 'selectWoo' ) ) {
$wp_scripts = wp_scripts();
if ( ! in_array( 'select2', $wp_scripts->queue, true ) && isset( $wp_scripts->registered[ 'select2' ] ) ) {
array_unshift( $wp_scripts->queue, 'select2' );
@yuriinalivaiko
yuriinalivaiko / um_on_login_before_redirect.php
Created February 21, 2024 22:09
Redirect users to a different URL the first time they log in.
<?php
// Redirect users to a different URL the first time they log in.
add_action( 'um_on_login_before_redirect', 'my_on_login_before_redirect', 9, 1 );
function my_on_login_before_redirect( $user_id ) {
$first_login = get_user_meta( $user_id, '_um_first_login', true );
if ( empty( $first_login ) ) {
update_user_meta( $user_id, '_um_first_login', current_time( 'mysql', true ) );
// Set a custom redirect URL for the first time login here.
@yuriinalivaiko
yuriinalivaiko / um_after_email_confirmation_redirect.php
Last active October 29, 2023 18:47
This code overrides the "URL redirect after e-mail activation" setting. After activation the user will be redirected to the page used for registration. This may be helpful if the registration page is placed in a popup or sidebar.
<?php
// Save the page URL on registration.
add_action( 'um_registration_set_extra_data', 'um_registration_set_extra_data_custom', 10, 3 );
function um_registration_set_extra_data_custom( $user_id, $args, $form_data ) {
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
$url = esc_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) );
update_user_meta( $user_id, 'um_registration_page_url', $url );
} elseif ( isset( $_SERVER['REQUEST_URI'] ) ) {
$url = esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) );
@yuriinalivaiko
yuriinalivaiko / add_a_hidden_field_to_register.php
Last active May 17, 2025 13:21
Ultimate Member documentation. Article: Add a hidden field to your register form.
<?php
// Add hidden fields you need to this array.
$GLOBALS['um_registration_extra_data'] = array(
'field_key_1' => 'abc',
'field_key_2' => 'xyz',
);
// This code adds hidden fields to the form.
add_action( 'um_after_register_fields', 'add_a_hidden_field_to_register', 10, 1 );
@yuriinalivaiko
yuriinalivaiko / um_friends_button_shortcode.php
Last active September 19, 2023 14:03
This code adds a shortcode [um_friends_button] that displays the "Add Friend" button. This code requires the "Ultimate Member" and "Ultimate Member - Friends" plugins to be installed.
<?php
/**
* Add a shortcode [um_friends_button] that displays the "Add Friend" button.
*
* Attributes:
* - (int) post_id - The post/page ID. Optional. Default: current post/page ID.
* - (int) user_id - The user ID. Optional. Default: requested user ID or the post/page author ID.
*
* Example: [um_friends_button user_id="20"]
@yuriinalivaiko
yuriinalivaiko / um_send_registration_notification_after_updating_profile.php
Last active October 6, 2023 14:01
This code triggers sending the "New User Notification" email notification. Example 1 - after the profile update. Example 2 - after create an account during checkout (WooCommerce).
<?php
// Send the "New User Notification" email when profile is updated.
add_action( 'um_user_after_updating_profile', function( $to_update, $user_id, $args ) {
$GLOBALS['um_temp_submitted'] = isset( $args['submitted'] ) ? $args['submitted'] : $args;
function um_user_after_updating_profile_submitted( $value ) {
return $GLOBALS['um_temp_submitted'];
}
function um_user_after_updating_profile_timestamp( $value ) {
@yuriinalivaiko
yuriinalivaiko / um_custom_button_in_profile.php
Last active December 13, 2024 12:31
Add a button (link) for each member in the member directory, and also add a button (link) to the user profile.
<?php
/**
* Change the $href variable to an URL that navigates to a page you need
* and change the $title variable to a button text you need
* then add this code to the functions.php file in the theme directory.
*/
// Add a custom button (link) on user profile.
function um_custom_button_in_profile( $args ) {
@yuriinalivaiko
yuriinalivaiko / um_wpseo_sitemaps_users.php
Last active June 16, 2023 18:59
This code snippet adds all approved users whose Ultimate Member profiles are public to the sitemap generated by Yoast SEO plugin.
<?php
/**
* Add all approved users whose Ultimate Member profiles are public to the sitemap.
*/
add_filter( 'wpseo_sitemap_entry', 'um_wpseo_sitemap_entry', 10, 3 );
add_filter( 'wpseo_sitemap_exclude_author', 'um_wpseo_sitemaps_users' );
/**
@yuriinalivaiko
yuriinalivaiko / um_user_locations_map_args_customize_05.php
Last active October 26, 2023 11:31
This code snippet uses the Map ID to customize the map styles in the User Locations extension.
<?php
/**
* Use Map ID to customize the user location map.
*/
add_action( 'wp_footer', function () {
?><script type="text/javascript">
function um_user_locations_customize_mapId( args, hash, directory ) {
args.mapId = 'YOUR_MAP_ID';