Skip to main content

get_users

Retrieves users from the database with optional filtering by client and search terms.

Signature

get_users($client_filter = null, $search_term = null, int $limit = 500, int $offset = 0)

Parameters

client_filter
string
default:"null"
Filter users by associated client name. If provided, only returns users who have played games associated with this client.
search_term
string
default:"null"
Search term to filter users by display name or email address. Uses SQL LIKE with wildcards.
limit
integer
default:"500"
Maximum number of results to return. Hard capped at 500 to prevent performance issues.
offset
integer
default:"0"
Number of results to skip for pagination.

Returns

users
array
Array of user objects with the following properties:

Example Usage

// Get first 100 users
$users = get_users(null, null, 100, 0);

Implementation Details

This function implements a hard limit of 500 results per query to prevent performance degradation. The limit parameter is clamped between 1 and 500 using min(max(1, $limit), 500).
When $client_filter is provided, the function performs additional JOINs across de_app_sessions, de_posts, and de_postmeta tables to filter users by client association. This may impact query performance for large datasets.

Error Handling

The function uses try/catch blocks for database errors. On failure, it logs the error and returns an empty array:
try {
    $stmt = $pdo->prepare($sql);
    $stmt->execute($params);
    return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
    error_log('[get_users] ' . $e->getMessage());
    return [];
}

get_user_meta

Retrieves a specific metadata value for a user.

Signature

get_user_meta($userId, $key)

Parameters

userId
integer
required
User ID
key
string
required
Meta key to retrieve (e.g., ‘area’, ‘_user_cliente_id’)

Returns

value
string
The meta value, or false if not found

Example Usage

// Get user's area
$area = get_user_meta(42, 'area');

// Get user's client ID
$clientId = get_user_meta(42, '_user_cliente_id');

get_user_client_name

Retrieves the client name associated with a user based on their metadata.

Signature

get_user_client_name($userId)

Parameters

userId
integer
required
User ID

Returns

client_name
string
Client name, or null if no client is associated

Example Usage

$clientName = get_user_client_name(42);
if ($clientName) {
    echo "User belongs to: " . $clientName;
}
Retrieves the logo URL for the client associated with a user.

Signature

get_user_client_logo($userId)

Parameters

userId
integer
required
User ID

Returns

logo_url
string
Full URL to the client’s logo image, or null if no logo exists

Example Usage

$logoUrl = get_user_client_logo(42);
if ($logoUrl) {
    echo '<img src="' . htmlspecialchars($logoUrl) . '" alt="Client Logo">';
}

Sessions

Retrieve user session data

Games

Get games played by users

Build docs developers (and LLMs) love