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:

  1. First checks for a cached value in user meta (_jc_member_since)
  2. 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
  3. 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:

  1. Gets the member since date using jc_get_member_since()
  2. Displays a date input field with the current value
  3. Field is editable by administrators

jc_save_member_since_field($user_id)

Handles saving the member since field:

  1. Verifies nonce and user capabilities
  2. Sanitizes the input
  3. 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.

  • functions.php: Contains all the member since related functions
  • _events.scss: Contains styling for displaying member since in the events section