Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / um_notifications_add_type.php
Last active May 13, 2025 18:29
Code snippets for the "Real-time Notifications" extension
<?php
/**
* Add a new real-time notification type 'new_photo_comment'.
*
* @param array $array Notification types.
* @return array
*/
function um_user_photos_add_notification_type( $array ) {
$array['new_photo_comment'] = array(
@yuriinalivaiko
yuriinalivaiko / um_login_redirect_url.php
Created February 26, 2025 12:15
Ultimate Member customization. Redirect logged in users from the Login page.
<?php
// Redirect logged in users from the Login page to the page specified in the role setting “Set Custom Redirect URL”.
add_action( 'template_redirect', function() {
if ( function_exists( 'um_is_core_page' ) && um_is_core_page( 'login' ) && is_user_logged_in() ) {
if ( um_user( 'login_redirect_url' ) ) {
$redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) );
} else {
$redirect_url = home_url();
}
@yuriinalivaiko
yuriinalivaiko / um_user_shortcode.php
Created February 24, 2025 19:02
Ultimate Member customization. Shortcode that displays the profile data where you need.
<?php
/**
* Shortcode that displays the profile data.
* Example: [um_user data="roles" user_id="1"]
*
* @param array $atts Shortcode attributes:
* - (string) data - Data type or usermeta key. Display name by default
* - (int) user_id - User ID. Profile ID or current user ID by default.
*
@yuriinalivaiko
yuriinalivaiko / um_user_bookmarks_disable.php
Last active February 13, 2025 13:39
Code snippets for the "User Bookmarks" extension
<?php
// Disable the default "Bookmark" button in the post content.
if ( defined( 'um_user_bookmarks_version' ) ) {
remove_filter( 'the_content', array( UM()->User_Bookmarks()->common(), 'add_um_user_bookmarks_button' ), 20 );
remove_filter( 'the_excerpt', array( UM()->User_Bookmarks()->common(), 'add_um_user_bookmarks_button_excerpt' ), 9999 );
}
@yuriinalivaiko
yuriinalivaiko / um_disable_restrictions.php
Last active November 26, 2025 20:05
Ultimate Member customization. Disable content restriction for searching.
<?php
// Disable content restriction for searching.
add_action( 'wp_loaded', function() {
if ( ( is_search() || isset( $_GET['s'] ) ) && function_exists( 'UM' ) ) {
remove_action( 'template_redirect', array( UM()->access(), 'template_redirect' ), 1000 );
remove_action( 'pre_get_terms', array( UM()->access(), 'exclude_hidden_terms_query' ), 99 );
remove_filter( 'widget_posts_args', array( UM()->access(), 'exclude_restricted_posts_widget' ), 99 );
remove_filter( 'wp_list_pages_excludes', array( UM()->access(), 'exclude_restricted_pages' ) );
@yuriinalivaiko
yuriinalivaiko / um_friends_hide_for_guests.php
Created February 4, 2025 11:32
Code snippets for the "Friends" extension
<?php
// Hide the "Friends" extension elements for guests.
if ( ! is_user_logged_in() && defined( 'um_friends_version' ) ) {
// A button in profile cover area.
remove_action( 'um_before_profile_main_meta', 'um_friends_add_button', 10 );
// A button in profile meta area.
remove_action( 'um_after_profile_header_name', 'um_friends_add_button_nocover', 60 );
@yuriinalivaiko
yuriinalivaiko / um_custom_validate_reset_password_email.php
Created January 21, 2025 18:00
Ultimate Member customization. Add validation and error message for the field in the Password Reset form.
<?php
/**
* Custom validation and error message for the "Password Reset" field.
*/
add_action( 'um_reset_password_errors_hook', 'um_custom_validate_reset_password_email', 20 );
function um_custom_validate_reset_password_email( $inputs ) {
if ( isset( $inputs['username_b'] ) ) {
if ( isset( UM()->form()->errors['username_b'] ) ) {
unset( UM()->form()->errors['username_b'] );
@yuriinalivaiko
yuriinalivaiko / um-profile-menu-vertical.css
Last active January 16, 2025 11:42
Ultimate Member customization. Make the profile menu vertical.
/**
* Make the profile menu vertical
*/
.um-profile:not(.uimob340) .um-form {
display: table;
}
.um-profile:not(.uimob340) .um-form .um-profile-nav,
.um-profile:not(.uimob340) .um-form .um-profile-body {
box-sizing: border-box;
margin-top: 0px !important;
@yuriinalivaiko
yuriinalivaiko / um_email__alter_recipient.php
Created January 15, 2025 12:29
Ultimate Member customization. Change the recipient for the "Account Needs Review Notification" email depending on the account role.
<?php
// Set a role admin email address for the "Account Needs Review Notification" email.
add_action( 'um_before_email_notification_sending', function( $email, $template ) {
if ( 'notification_review' === $template ) {
$role = um_user( 'role' );
// role admins.
$role_admins = array(
'subscriber' => 'role.admin.email.0@gmail.com',
@yuriinalivaiko
yuriinalivaiko / um_profile_role_specific_redirect.php
Created January 6, 2025 11:25
Ultimate Member customization. Redirect to Account page if the profile is not specific for the profile owner role.
<?php
// Redirect from the empty profile to Account.
add_filter( 'um_ultimatemember_shortcode_disable_singleton', function( $disable, $args ) {
if ( ! empty( $args['form_id'] ) ) {
$post_data = UM()->query()->post_data( $args['form_id'] );
$form_data = array_map( 'maybe_unserialize', $post_data );
$args = array_merge( $args, $form_data );
}
if ( 'profile' === $args['mode'] && ! empty( $args['use_custom_settings'] ) && ! empty( $args['role'] ) ) {