Created
April 9, 2026 09:26
-
-
Save dwanjuki/cfb8f5e6414611bb7d20f9152fcfe685 to your computer and use it in GitHub Desktop.
Posts with specified tags will not require membership to view
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 | |
| /** | |
| * Posts with specified tags will not require membership to view | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_open_tag_posts_to_all_visitors( $hasaccess, $thepost, $theuser, $post_membership_levels ) { | |
| // if PMPro says true already, return true | |
| if ( $hasaccess ) { | |
| return $hasaccess; | |
| } | |
| // Posts with these tags will be accessible to everyone | |
| $tags = array( 'free-tag' ); | |
| if ( has_tag( $tags, $thepost ) ) { | |
| $hasaccess = true; | |
| } | |
| return $hasaccess; | |
| } | |
| add_filter( 'pmpro_has_membership_access_filter', 'my_pmpro_open_tag_posts_to_all_visitors', 20, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment