Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created November 27, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/14ba17751b376960e93b39dd776715d5 to your computer and use it in GitHub Desktop.
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.
<?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