Last active
January 9, 2026 13:23
-
-
Save yuriinalivaiko/90d2777af68f65b2524adbe74dcfadd8 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Code snippets for fields and filters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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