• Resolved Simon

    (@simonmaddox)


    I was using {display_name} as a top-level menu item for users’ accounts, but it is possible for users to select a blank display name – then the menu does not appear.

    Would it be possible to add an option to fall back to username if display name is empty?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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?

    Plugin Author Daniel Iser

    (@danieliser)

    @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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fallback if display name is empty’ is closed to new replies.