Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / um_user_locations_alter_scripts.php
Last active May 17, 2025 13:29
Code snippets for the "User Locations" extension
<?php
/**
* Defer scripts of the "Ultimate Member - User Locations" extension.
*
* @link https://developer.wordpress.org/reference/classes/wp_scripts/add_data/
* @global WP_Scripts $wp_scripts
*/
function um_user_locations_alter_scripts() {
global $wp_scripts;
@yuriinalivaiko
yuriinalivaiko / um_member_directory_filter_select_options_sorted.php
Created May 17, 2025 13:24
Ultimate Member customization. Code snippets for the member directory.
<?php
// Sort member directory filter options by values.
add_filter( 'um_member_directory_filter_select_options_sorted', function( $options, $attrs ) {
asort( $options );
return $options;
}, 10, 2 );
@yuriinalivaiko
yuriinalivaiko / um_messaging_autodelete.php
Last active May 16, 2025 12:15
Code snippets for the "Private Messages" extension
<?php
// Delete private messages after 6 months.
add_action( 'um_daily_scheduled_events', 'um_messaging_autodelete' );
function um_messaging_autodelete() {
global $wpdb;
$timestamp = strtotime( '6 months ago');
$sql = $wpdb->prepare(
@yuriinalivaiko
yuriinalivaiko / new_service.php
Last active April 11, 2025 20:03
Ticket 97389: Integration of Google Maps API for Custom Radius-Based Notification System
<?php
// Add custom email notifications.
add_filter( 'um_email_notifications', 'onemec_email_notifications', 10, 1 );
// Call action when a new Job is published.
add_action( 'jb_job_published', 'onemec_job_submitted', 10, 2 );
/**
* Extend Ultimate Member email notifications.
@yuriinalivaiko
yuriinalivaiko / um_get_field_block.php
Created April 10, 2025 16:51
Ultimate Member customization. Apply shortcodes in the "Content Block" field.
<?php
// apply shortcodes in the "Content Block" field.
add_filter( 'um_get_field_block', function( $data ) {
if ( array_key_exists( 'content', $data ) ) {
$data['content'] = apply_shortcodes( $data['content'] );
}
return $data;
} );
@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 February 6, 2025 17:31
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' ) );