I am looking for a code that will allow me to restrict access to content based on a User Registration Date. Therefore, if a user registers after content has already been posted then the user will not be able to view the content. Access to view post content will only be available if the post is made after the user is already registered.

  • @dicm 's answer should get you where you want to be. I'm just curious what the use case is for this? – karpstrucking Jun 11 '16 at 22:24
  • Hi Kaiser, apologies for the late response. We are building a content subscription blog and the customer requested that old content (digital downloadable format) needs to be restricted for new subscribers. SHould they want the content they will need to apply for or purchase it seperately. – Bernie Jun 13 '16 at 21:58

I have just made this code you can try out:

add_filter( 'the_content', 'restrict_access' );
function restrict_access( $content ) { 

    $user_info = wp_get_current_user(); // Get logged in user info
    $registered = $user_info->user_registered;

    if( !is_user_logged_in() ) {

        $content = __( "You are not logged in.", 'your_textdomain' );

    } else if (new DateTime( get_the_date() ) < new DateTime( $registered )) {

        $content = __( "You are not allowed to view this content. Your user was registered ( ".date( "d-m-Y", strtotime( $registered ) )." ) after content was created ( ".get_the_date( "d-m-Y" )." ) , you are only allowed to view new content.", 'your_textdomain' );


    return $content;
| improve this answer | |
  • 2
    Please explain why your code is supposed to help solve the question. ProTip: Add line breaks so there's no horizontal scrolling needed :) – kaiser Jun 11 '16 at 21:43
  • thank you for the code. will be trying it shortly. I am a novice in wordpress, so it's going to go slow at first - will let you know if it works. – Bernie Jun 13 '16 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.