Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save denisbaranov/454914a5f946eb1049748192192575c1 to your computer and use it in GitHub Desktop.
Save denisbaranov/454914a5f946eb1049748192192575c1 to your computer and use it in GitHub Desktop.
How to show default field value on "view" mode if field value is empty.
<?php
/**
* This code shows default field value on "view" mode if field value is empty in the Profile form of the Ultimate Member.
*
* You can add this code to the end of the file functions.php in the active theme (child theme) directory.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/
*/
/**
* Show default field value on "view" mode if field value is empty.
* @param mixed $value
* @param string $default
* @param string $key
* @param string $type
* @param array $data
* @return mixed
*/
function um_show_field_value_if_empty( $value, $default, $key = '', $type = '', $data = array() ) {
if( empty( $value ) && $default ) {
$value = $default;
}
return $value;
}
add_filter( 'um_field_value', 'um_show_field_value_if_empty', 20, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment