Created
November 27, 2020 13:00
-
-
Save andrewlimaza/14ba17751b376960e93b39dd776715d5 to your computer and use it in GitHub Desktop.
Give user's access to all content on an Addon Packages Page if purchased. Includes PMPro [membership] shortcode.
This file contains 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 | |
/** | |
* Give's users that purchase an Addon Package access to shortcodes that aren't for their level. | |
* User's with level 1, will gain access to all content on a purchased Addon Package item such as [membership level="2"]This content[/membership] | |
* | |
* 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_pmproap_pmpro_member_shortcode_access( $hasaccess, $content, $levels, $delay ) { | |
if ( ! is_user_logged_in() ) { | |
return $hasaccess; | |
} | |
global $current_user, $post; | |
if ( pmproap_isPostLocked( $post->ID ) ) { | |
// okay check if the user has access | |
if ( pmproap_hasAccess( $current_user->ID, $post->ID ) ) { | |
$hasaccess = true; | |
} else { | |
$hasaccess = false; | |
} | |
} | |
return $hasaccess; | |
} | |
add_filter( 'pmpro_member_shortcode_access', 'my_pmproap_pmpro_member_shortcode_access', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment