-
-
Save pbrocks/36cd6c1e28bd902cd85d130a2d5af6f9 to your computer and use it in GitHub Desktop.
This code will filter ACF fields added to custom templates using the post's membership requirements.
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 | |
/** | |
* pmpro_hide_acf_fields This code will filter ACF fields added to custom templates using the post's membership requirements. | |
* | |
* Add this code to your PMPro Customizations Plugin | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
* https://www.advancedcustomfields.com/resources/acf-format_value/ | |
* | |
* @param mixed $value Value which was loaded from the database | |
* @param mixed $post_id Post ID value was loaded from | |
* @param array $field Array containing all the field settings for the field which was used to upload the attachment | |
* | |
* @return mixed Returned value if member has access | |
*/ | |
function pmpro_hide_acf_fields( $value, $post_id, $field ) { | |
// Check if the user has access to the post. | |
$hasaccess = pmpro_has_membership_access( $post_id ); | |
if ( empty( $hasaccess ) ) { | |
// If user does not have acces to the post, empty the field value. | |
$value = ''; | |
} | |
// return | |
return $value; | |
} | |
add_filter( 'acf/format_value', 'pmpro_hide_acf_fields', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment