Last active
October 25, 2024 19:17
-
-
Save MaximilianoRicoTabo/a9408b80b6eb31c762ebac459ffadd1a to your computer and use it in GitHub Desktop.
Fix Approval bug by removing Add On filter and adding a custom one
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 | |
/** | |
* This recipe fix an Approvals Add On bug by removing Add On filter and adding a custom one | |
* | |
* 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_custom_pmpro_approval_membership_shortcode() { | |
remove_filter( 'pmpro_member_shortcode_access', array( 'PMPro_Approvals', 'pmpro_member_shortcode_access' ), 10, 4 ); | |
add_filter( 'pmpro_member_shortcode_access', 'my_pmpro_member_shortcode_access', 10, 4 ); | |
} | |
function my_pmpro_member_shortcode_access( $access, $content, $levels, $delay ) { | |
global $current_user; | |
// Bail if they are not logged-in, default behavior. | |
if ( ! is_user_logged_in() ) { | |
return $access; | |
} | |
// Bail if the user is logged in but doesn't have a membership level. | |
if ( ! pmpro_hasMembershipLevel() ) { | |
return $access; | |
} | |
// If no levels are defined let's set this to false. | |
if ( empty( $levels ) ) { | |
return false; | |
} | |
foreach( $levels as $level ) { | |
if ( PMPro_Approvals::isApproved( $current_user->ID, $level ) ) { | |
return $access; | |
break; | |
} | |
} | |
return $access; | |
} | |
add_action( 'init', 'my_custom_pmpro_approval_membership_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment