Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Check if the current user has a specific CRM tag based on an ACF dropdown field value.
- *
- * @param bool $can_access Whether the user can access the content.
- * @param int $user_id The ID of the user.
- * @param int $post_id The ID of the content.
- *
- * @return bool Whether the user can access the content.
- */
- function my_custom_wpf_user_can_access( $can_access, $user_id, $post_id ) {
- // Get the value of the ACF dropdown field
- $field_value = get_field( 'my_field_name', $post_id );
- // Define the CRM tags for each field value
- $crm_tags = array(
- 'A' => 'tag_for_A',
- 'B' => 'tag_for_B',
- 'C' => 'tag_for_C',
- );
- // Check if the field value matches one of the predefined values
- if ( array_key_exists( $field_value, $crm_tags ) ) {
- // Get the tag for the current field value
- $required_tag = $crm_tags[ $field_value ];
- // Check if the user has the required tag
- if ( wpf_has_tag( $required_tag, $user_id ) ) {
- return true;
- } else {
- return false;
- }
- }
- return $can_access;
- }
- add_filter( 'wpf_user_can_access', 'my_custom_wpf_user_can_access', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement