Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created September 13, 2017 12:53
Show Gist options
  • Save andrewlimaza/a0358c84b0dd0860f904622ac49608ca to your computer and use it in GitHub Desktop.
Save andrewlimaza/a0358c84b0dd0860f904622ac49608ca to your computer and use it in GitHub Desktop.
Allow non-members temporary access to restricted PMPro Content until a certain date.
<?php
/**
* Allow temporary access to all restricted content for non-members until a certain date.
* Add this function below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_allow_temp_access_for_non_members($hasaccess, $mypost, $myuser, $post_membership_levels){
// Do not affect existing memberships access to posts.
if( pmpro_hasMembershipLevel() ){
return $hasaccess;
}
$end_date = strtotime( date( '2017-12-31' ) ); //change this date value. Format ( Y-m-d ).
$today = strtotime( date( 'Y-m-d' ) );
//get the difference in date.
$diff = $end_date - $today;
// If end date is today or earlier, grant access - if today > end date, return false.
if( $diff >= 0 ){
$hasaccess = true;
}else{
$hasaccess = false;
}
return $hasaccess;
}
add_filter( 'pmpro_has_membership_access_filter', 'pmpro_allow_temp_access_for_non_members', 30, 4 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Lock or Unlock Posts Based on Age and Post Date" at Paid Memberships Pro here: https://www.paidmembershipspro.com/lock-unlock-posts-based-age-post-date/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment