Last active
October 6, 2022 18:46
-
-
Save yuriinalivaiko/0cc8d895dfa37561d0c03ccdb7538d35 to your computer and use it in GitHub Desktop.
This code snippet displays the default value if the field value is empty in the profile view mode. You can add this code to the functions.php file in the active theme directory.
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 | |
/** | |
* Display default value if the field value is empty in the profile view mode. | |
* | |
* @param string $value Field Value. | |
* @param string $default Field Default Value. | |
* @param string $key Field Key. | |
* @param string $type Field Type. | |
* @param array $data Field Data. | |
* @return string Field value to display. | |
*/ | |
function um_field_value_show_default( $value, $default, $key, $type, $data ) { | |
if ( empty( $value ) && ! empty( UM()->fields()->viewing ) ) { | |
if ( ! empty( $default ) ) { | |
$value = $default; | |
} | |
} | |
return $value; | |
} | |
add_filter( 'um_field_value', 'um_field_value_show_default', 50, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a part of the article How to display fallback value if the field value is empty.
Documentation: https://docs.ultimatemember.com/
Support forum: https://wordpress.org/support/plugin/ultimate-member/