Member Since Calculation
The member since calculation is a feature that tracks when a user first became a member by finding their earliest subscription start date. This information is cached in user meta for performance.
Core Functions
jc_get_member_since($user_id)
This function calculates the earliest subscription start date for a user:
- First checks for a cached value in user meta (
_jc_member_since
) - If no cache exists:
- Gets all user subscriptions using
wcs_get_users_subscriptions()
- Loops through subscriptions to find the earliest
date_created
- Caches the result in user meta
- Gets all user subscriptions using
- Returns the date in Y-m-d format
jc_add_member_since_field($user)
Adds the member since field to the user profile page in the “About Yourself” section:
- Gets the member since date using
jc_get_member_since()
- Displays a date input field with the current value
- Field is editable by administrators
jc_save_member_since_field($user_id)
Handles saving the member since field:
- Verifies nonce and user capabilities
- Sanitizes the input
- Updates the user meta with the new date
Usage
To get a user’s member since date:
$member_since = jc_get_member_since($user_id);
The date will be returned in Y-m-d format (e.g. “2024-03-20”).
Caching
The member since date is cached in user meta with the key _jc_member_since
. This improves performance by avoiding repeated database queries to calculate the date.
Display
The member since field appears in the user profile page under the “About Yourself” section. It’s displayed as a date input field that administrators can edit.
Related Files
functions.php
: Contains all the member since related functions_events.scss
: Contains styling for displaying member since in the events section