Skip to main content

Tell a Member When a Locked Episode Opens for Their Plan

Free Beginner

In a theme’s episode template, tell a signed-in member the date an episode becomes available on their plan, using benecaster_get_episode_available_at() and benecaster_get_user_tier_for_show().

The part that is easy to get wrong: the date comes back in UTC, as stored. Hand it to wp_date() as a UTC timestamp, never to date_i18n(), or the date shifts by your site’s distance from UTC.

Code

<?php
$show_id = (int) wp_get_post_parent_id( get_the_ID() );
$tier    = benecaster_get_user_tier_for_show( $show_id, get_current_user_id() );
if ( '' !== $tier ) {
    $opens = benecaster_get_episode_available_at( get_the_ID(), $tier );
    if ( null !== $opens && strtotime( $opens . ' UTC' ) > time() ) {
        printf(
            /* translators: %s: date the episode opens */
            esc_html__( 'Opens for your plan on %s', 'my-theme' ),
            esc_html( wp_date( get_option( 'date_format' ), strtotime( $opens . ' UTC' ) ) )
        );
    }
}

View on GitHub →

Need this built rather than just documented? See our services →