Thread Starter
Simon
(@simonmaddox)
I found that adding the following to /includes/classes/menu/items.php
case 'display_or_username':
if ($current_user->display_name <> ""){
$replace = $current_user->display_name;
} else {
$replace = $current_user->user_login;
}
break;
and the following to /includes/classes/user/codes.php:
'display_or_username' => __( 'Display or UserName', 'user-menus' ),
worked. Maybe consider adding to next release?
@simonmaddox – Actually that isn’t needed. Instead you can use the built in fallback mechanism, though I just tested and found a bug that needs patched.
modify includes/classes/menu/item.php:132 And correct it like so:
if ( ! array_key_exists( $string, Codes::valid_codes() ) ) {
// If its not a valid code it is likely a fallback.
$replace = $string;
} else if ( $current_user->ID == 0 && array_key_exists( $string, Codes::valid_codes() ) ) {
// If the code exists & user is not logged in, return nothing.
$replace = '';
} else {
Now just do Hey {{first_name||There}}
If the first_name field is empty it will just return Hey There.
Hope that helps. Will get that patched in the next update.