Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / um_display_all_form_errors.css
Last active April 24, 2024 13:06
Display all form errors below the form in Ultimate Member
/**
* Hide error messages under fields.
*/
.um-field .um-field-error {
display: none;
}
@yuriinalivaiko
yuriinalivaiko / um_grouped_filters.php
Last active March 14, 2024 22:13
This code adds custom filters to the member directory of the Ultimate Member plugin. These filters are grouped - one filter searches in multiple fields.
<?php
/**
* Add custom grouped filters to the member directory.
*
* Add filters you need to this array. Every filter is an array where:
* - key Filter key. Any valid string key.
* - type Filter type. Accepts: 'text', 'select', 'slider', 'datepicker', 'timepicker'.
* - label Filter label (used as the filter placeholder).
* - fields An array of usermeta keys. Filter searches a value in these usermeta.
@yuriinalivaiko
yuriinalivaiko / my_template_tags.php
Created March 12, 2024 10:47
Add custom email placeholders
<?php
// Add role-specific content to the email template.
add_filter( 'um_template_tags_patterns_hook', 'my_template_tags_patterns', 10, 1 );
add_filter( 'um_template_tags_replaces_hook', 'my_template_tags_replaces', 10, 1 );
function my_template_tags_patterns( $search ) {
$search[] = '{welcome_content_for_subscriber}';
$search[] = '{welcome_content_for_customer}';
$search[] = '{welcome_content_for_um_member}';
return $search;
<?php
// Change the default WooCommerce login redirect URL.
function um_woocommerce_login_redirect( $redirect, $user ) {
if ( function_exists( 'um_get_core_page' ) ) {
$redirect = um_get_core_page( 'account' );
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'um_woocommerce_login_redirect', 10, 2 );
@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_profile_header_shortcode.php
Last active December 6, 2023 12:54
This code adds a shortcode that displays the header section of the Ultimate Member profile.
<?php
/**
* Shortcode that displays the profile header.
* Example: [um_profile_header form_id="7" user_id="1"]
*
* @global \wpdb $wpdb
*
* @param array $atts Shortcode attributes:
* - (int) form_id - profile form ID. The first profile form if blank.
@yuriinalivaiko
yuriinalivaiko / um_add_video_file_types.php
Last active November 11, 2023 15:50
This code snippet extends the "File upload" field type to add video formats. An array of supported video formats: 'mp4', 'm4v', 'webm', 'ogv', 'flv'.
<?php
/**
* Allow to upload video files via the "File Upload" field type.
* Add this code to the file functions.php in the active theme directory.
*/
add_filter( 'um_allowed_file_types', 'um_add_video_file_types' );
add_filter( 'um_profile_field_filter_hook__file', 'um_profile_field_filter_hook__file_video', 101, 2 );
/**
@yuriinalivaiko
yuriinalivaiko / um_activity_post_insert_tools_emoji.php
Created November 3, 2023 17:37
This code adds the "Add emoji" tool to the activity post form. This code uses elements of the "Ultimate Member - Private Messages", so this extension is required.
<?php
// "Add emoji" tool for the activity post form.
add_action( 'wp_loaded', 'um_fix_emotize', 20 );
add_action( 'um_activity_post_insert_tools', 'um_activity_post_insert_tools_emoji' );
function um_activity_post_insert_tools_emoji() {
if ( defined( 'um_messaging_plugin' ) ) {
UM()->get_template( 'emoji.php', um_messaging_plugin, array(), true );
wp_enqueue_script( 'um-messaging' );
@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 October 28, 2023 17:15
This code adds hidden fields to the Ultimate Member registration 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 );