Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save denisbaranov/5d3904d7765c1f977a1cffd0d9e53756 to your computer and use it in GitHub Desktop.
Save denisbaranov/5d3904d7765c1f977a1cffd0d9e53756 to your computer and use it in GitHub Desktop.
​Empty fields are hidden on profile form "view" mode. It may look weird. You may use the code snippet below to display fallback value "--" for the empty fields. It works only for the "view" mode. Just add this code snippet to the functions.php file in the active theme (child theme) directory.
<?php
/**
* Displays fallback value if the field value is empty. For the "view" mode only.
* @param string $value
* @param string $default
* @param string $key
* @param string $type
* @param array $data
* @return string
*/
function um_field_value_fallback( $value, $default, $key, $type, $data ) {
if ( empty( $value ) && isset( UM()->fields()->viewing ) && UM()->fields()->viewing === true ) {
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
if ( !in_array( $type, $fields_without_metakey ) ) {
$value = '--';
}
}
return $value;
}
add_filter( 'um_field_value', 'um_field_value_fallback', 50, 5 );
@denisbaranov
Copy link
Author

2020-03-30_005237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment