Drip Content by Registration Date
Adds a [wpide_drip days="7"] shortcode that unlocks the content inside it a set number of days after each member registered, and tells them when it unlocks.
Opens WPIDE on
Code
add_shortcode( 'wpide_drip', function ( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'days' => 0, 'locked' => 'This part unlocks on %s.' ), $atts, 'wpide_drip' );
if ( ! is_user_logged_in() ) {
return '<p class="wpide-drip-locked">Please <a href="' . esc_url( wp_login_url( get_permalink() ) ) . '">log in</a> to see this content.</p>';
}
if ( current_user_can( 'edit_others_posts' ) ) {
return do_shortcode( $content );
}
$unlocks = strtotime( wp_get_current_user()->user_registered . ' UTC' ) + max( 0, (int) $atts['days'] ) * DAY_IN_SECONDS;
if ( time() >= $unlocks ) {
return do_shortcode( $content );
}
return '<p class="wpide-drip-locked">' . esc_html( sprintf( $atts['locked'], wp_date( get_option( 'date_format' ), $unlocks ) ) ) . '</p>';
} );
Notes
Example: [wpide_drip days="14"]Week 3 lesson[/wpide_drip]. Administrators and editors always see the content.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.