Elgg\Database\UsersTable::getByUsername PHP Method

getByUsername() public method

Get user by username
public getByUsername ( string $username ) : ElggUse\ElggUser | false
$username string The user's username
return ElggUse\ElggUser | false Depending on success
    public function getByUsername($username)
    {
        // Fixes #6052. Username is frequently sniffed from the path info, which,
        // unlike $_GET, is not URL decoded. If the username was not URL encoded,
        // this is harmless.
        $username = rawurldecode($username);
        if (!$username) {
            return false;
        }
        $entity = $this->entity_cache->getByUsername($username);
        if ($entity) {
            return $entity;
        }
        $users = $this->entities->getEntitiesFromAttributes(['types' => 'user', 'attribute_name_value_pairs' => ['name' => 'username', 'value' => $username], 'limit' => 1]);
        return $users ? $users[0] : false;
    }