<?php
namespace Bookaro\Utils;

defined('ABSPATH') || exit;

class UserHelper
{
    /**
     * Return the user's first and last name if set, otherwise display name.
     */
    public static function preferred_name($user): string
    {
        if (! $user) {
            return '';
        }
        $first = property_exists($user, 'first_name') ? $user->first_name : '';
        $last  = property_exists($user, 'last_name') ? $user->last_name : '';
        $name  = trim($first . ' ' . $last);
        return $name !== '' ? $name : $user->display_name;
    }
}

