Last active
October 30, 2023 11:36
-
-
Save kimcoleman/ed9e3eaeb985d760acf487e3d890d647 to your computer and use it in GitHub Desktop.
Filter to only allow access to a protected post by post ID after a specific calendar 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 | |
/** | |
* Filter to only allow access to a protected post by post ID after a specific calendar date. | |
*/ | |
function my_pmpro_has_membership_access_on_date( $hasaccess, $post, $user ) { | |
// If they already don't have access, return. | |
if ( ! $hasaccess ) { | |
return $hasaccess; | |
} | |
// Set the post IDs and dates in an array. | |
$posts_in_series_with_dates = array( | |
'123' => '2023-10-28', | |
'456' => '2023-10-29', | |
'789' => '2023-10-30' | |
); | |
// Check if the post is in the array. | |
if ( array_key_exists( $post->ID, $posts_in_series_with_dates ) ) { | |
// Check if the current time of the WordPress site server is less than the date in the array. | |
if ( current_time( 'timestamp' ) < strtotime( $posts_in_series_with_dates[$post->ID], current_time( 'timestamp' ) ) ) { | |
$hasaccess = false; | |
} | |
} | |
return $hasaccess; | |
} | |
add_filter( 'pmpro_has_membership_access_filter', 'my_pmpro_has_membership_access_on_date', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment