<?php
/**
 * It helper of current plugin.
 *
 * @package  vitepos
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 *  It is a default helper to get user title.
 */
if ( ! function_exists( 'apbd_get_user_title_by_user' ) ) {
	/**
	 * This function is for getting user name.
	 *
	 * @param WP_User $user wp_user.
	 * @return string
	 */
	function apbd_get_user_title_by_user( $user ) {
		$title = '';
		if ( $user instanceof WP_User ) {
			if ( ! empty( $user->first_name ) && property_exists( $user, 'last_name' ) ) {
				$title = $user->first_name . ' ' . $user->last_name;
				if ( empty( trim( $title ) ) ) {
					$title = $user->display_name;
				}
			} elseif ( ! empty( $user->display_name ) ) {
				$title = $user->display_name;
			}
		}
		return $title;
	}
}
if ( ! function_exists( 'apbd_get_user_title_by_user_id' ) ) {
	/**
	 * The apbd get user title by user id is generated by appsbd
	 *
	 * @param mixed $user_id It is user_id param.
	 *
	 * @return string|null
	 */
	function apbd_get_user_title_by_user_id( $user_id ) {
		if ( ! empty( $user_id ) ) {
			$user = get_user( $user_id );
			return apbd_get_user_title_by_user( $user );
		} else {
			return null;
		}
	}
}
