Skip to content

Instantly share code, notes, and snippets.

View nikitasinelnikov's full-sized avatar

Mykyta Synelnikov nikitasinelnikov

  • ultimatemember.com
  • Kharkiv, Ukraine
View GitHub Profile
@nikitasinelnikov
nikitasinelnikov / functions.php
Created July 29, 2021 09:22
Ultimate Member >= 2.2.0. How to change the field's sanitizing type or remove it.
function um_custom_settings_map( $settings_map ) {
// changed type to wp_kses for ability to use HTML inside Secondary button title
$settings_map['register_secondary_btn_word']['sanitize'] = 'wp_kses';
// please use the line below to remove the sanitizing value before saving to DB. It's highly not recommended because this way you can put your site at risk.
// unset( $settings_map['register_secondary_btn_word']['sanitize'] );
return $settings_map;
}
add_filter( 'um_settings_map', 'um_custom_settings_map', 10, 1 );
// the similar hooks for another places where we need to handle data from inputs and save them to DB
@nikitasinelnikov
nikitasinelnikov / functions.php
Created July 29, 2021 09:35
Ultimate Member >= 2.2.0. Custom sanitizing type and callback function for it.
function um_custom_settings_map( $settings_map ) {
// let's change and sanitizing for Secondary button word setting and use your own function for that
// if you sanitize callback is public function
$settings_map['register_secondary_btn_word']['sanitize'] = 'my_custom_sanitize';
// if you sanitize callback inside the class
$settings_map['register_secondary_btn_word']['sanitize'] = array( 'my_sanitize_class', 'trim' );
// if it's simple PHP function with the only 1st and single required variable
$settings_map['register_secondary_btn_word']['sanitize'] = 'trim';
return $settings_map;
}
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active January 5, 2024 13:40
Ultimate Member >= 2.2.1. Change the WP_Post object for displaying the restricted post in archive or single page
/**
* Customize WP_Post object for the restricted post (if it's not hidden) in the archive page
*
* @param WP_Post $post
* @param array $restriction_settings
* @param WP_Post $original_post
*
* @return WP_Post
*/
function um_custom_data_restricted_archive_post( $post, $restriction_settings, $original_post ) {
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active December 30, 2022 13:12
Ultimate Member 2.2.x fix for number of queries. Paste to your theme or better to the separate plugin or mu-plugin
<?php
if ( function_exists( 'UM' ) ) {
remove_action( 'pre_get_posts', array( UM()->access(), 'exclude_posts' ), 99 );
remove_filter( 'get_next_post_where', array( UM()->access(), 'exclude_navigation_posts' ), 99 );
remove_filter( 'get_previous_post_where', array( UM()->access(), 'exclude_navigation_posts' ), 99 );
remove_filter( 'widget_posts_args', array( UM()->access(), 'exclude_restricted_posts_widget' ), 99 );
remove_filter( 'wp_count_posts', array( UM()->access(), 'custom_count_posts_handler' ), 99 );
remove_filter( 'getarchives_where', array( UM()->access(), 'exclude_restricted_posts_archives_widget' ), 99 );
remove_action( 'pre_get_terms', array( UM()->access(), 'exclude_hidden_terms_query' ), 99 );
remove_action( 'pre_get_comments', array( UM()->access(), 'exclude_posts_comments' ), 99 );
@nikitasinelnikov
nikitasinelnikov / functions.php
Created August 23, 2021 13:57
Ultimate Member: Remove custom fields from general member directory search (Custom metatable isn't active)
<?php
function um_my_custom_general_search_fields( $custom_fields ) {
$custom_fields = array(
'zip_code',
'user_score',
{any_usermeta_key_here},
);
return $custom_fields;
}
add_filter( 'um_general_search_custom_fields', 'um_my_custom_general_search_fields', 10, 1 );
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active December 22, 2021 12:28
Replace Ultimate Member placeholders after nav menus rendered
remove_filter( 'wp_nav_menu_objects', 'um_add_custom_message_to_menu', 9999 );
/**
* Add dynamic profile headers
*
* @param $items
* @param $args
*
* @return mixed
@nikitasinelnikov
nikitasinelnikov / functions.php
Created December 23, 2021 21:29
Integration member directory with course system and show only users that completed course
add_filter( 'um_prepare_user_query_args', 'um_custom_meta_filter', 10, 2 );
function um_custom_meta_filter( $query_args, $directory_data ) {
if ( absint( $directory_data['form_id'] ) === 75648 ) {
$query_args['meta_query'][] = array(
'key' => 'course_completed_2204',
'compare' => 'EXISTS',
);
}
return $query_args;
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active December 24, 2021 15:16
Customize homepage redirect when one user doesn't have access to the another one user
$GLOBALS['um_custom_redirect'] = false;
function um_custom_pre_profile_shortcode( $args ) {
global $um_custom_redirect;
/**
* @var $mode
*/
extract( $args );
@nikitasinelnikov
nikitasinelnikov / footer.php
Created April 12, 2022 10:43
JobBoardWP: Replace applying job wrapper
@nikitasinelnikov
nikitasinelnikov / functions.php
Created September 7, 2022 22:03
Ultimate Member v3: Password Reset 'um_pre_password_shortcode' hook
// 'um_before_form_is_loaded', 'um_before_password_form_is_loaded' - action hook for the lostpassword form, use 'um_pre_password_shortcode' for both
/**
* Fires before Password Reset form loading inside shortcode callback.
*
* Hook: um_pre_password_shortcode
* Note: Use this hook for adding some custom content before the password reset form or enqueue scripts when password reset form shortcode loading.
* Legacy v2.x hooks: 'um_before_password_form_is_loaded', 'um_before_form_is_loaded'
*
* Type: action