Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active January 9, 2026 13:23
Show Gist options
  • Select an option

  • Save yuriinalivaiko/90d2777af68f65b2524adbe74dcfadd8 to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/90d2777af68f65b2524adbe74dcfadd8 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Code snippets for fields and filters.
<?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;
} );
<?php
/**
* Fix "Country" and "Languages" fields and filters on translated pages.
*/
function um_translate_not( $translation, $text ) {
if ( ! empty( $GLOBALS['um_translate_not'] ) ) {
// Do not translate this text.
$translation = $text;
}
return $translation;
}
function um_translate_not_filter( $attrs, $key ) {
// Do not translate options for these fields.
$fields = array(
'country' => array(
'label' => 'Country',
'options' => 'countries',
),
'languages' => array(
'label' => 'Languages',
'options' => 'languages',
),
);
if ( isset( $fields[ $key ] ) && isset( $fields[ $key ]['options'] ) && isset( $attrs['options'] ) ) {
$GLOBALS['um_translate_not'] = true;
$attrs['options'] = (array) UM()->builtin()->get( $fields[ $key ]['options'] );
$GLOBALS['um_translate_not'] = false;
}
return $attrs;
}
function my_um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
if ( ! empty( $data['metakey'] ) ) {
$data = um_translate_not_filter( $data, $data['metakey'] );
}
return um_profile_field_filter_xss_validation( $value, $data, $type );
}
add_filter( 'gettext_ultimate-member', 'um_translate_not', 10, 2 );
add_filter( 'um_search_fields', 'um_translate_not_filter', 10, 2 );
add_filter( 'um_profile_field_filter_hook__', 'my_um_profile_field_filter_xss_validation', 10, 3 );
remove_filter( 'um_profile_field_filter_hook__', 'um_profile_field_filter_xss_validation', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment