Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Denies access to any content that was published before the user's registration date
<?php
//
// Denies access to any content that was published before the user's registration date
//
function disallow_before_date_published( $can_access, $user_id, $post_id ) {
$published = get_the_date( 'U', $post_id );
$userdata = get_userdata( $user_id );
if ( strtotime( $userdata->user_registered ) < $published ) {
$can_access = false;
}
return $can_access;
}
add_filter( 'wpf_user_can_access', 'disallow_before_date_published', 10, 3 );
//
// OR: Do it based on the date a tag was appplied
//
function disallow_before_date_published_alt( $can_access, $user_id, $post_id ) {
$published = get_the_date( 'U', $post_id );
$startdate = get_user_meta( $user_id, 'startdate', true );
// If the content was published before the user's startdate field, deny access
if ( empty( $startdate ) || $startdate < $published ) {
$can_access = false;
}
return $can_access;
}
add_filter( 'wpf_user_can_access', 'disallow_before_date_published_alt', 10, 3 );
function update_tag_applied_timestamp( $user_id, $tags ) {
// When TAGNAME is applied, save the current time to the startdate field
if ( in_array( 'TAGNAME', $tags ) ) {
update_user_meta( $user_id, 'startdate', time() );
}
}
add_action( 'wpf_tags_applied', 'update_tag_applied_timestamp', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment