Last active
January 4, 2021 11:49
-
-
Save verygoodplugins/8d8fdab62268754302fb43dbdc7c6f38 to your computer and use it in GitHub Desktop.
Denies access to any content that was published before the user's registration date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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