Created
September 13, 2017 12:53
-
-
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.
This file contains hidden or 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 | |
| /** | |
| * 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/