Advertisement
verygoodplugins

Untitled

Jul 16th, 2024 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Check if the current user has a specific CRM tag based on an ACF dropdown field value.
  4.  *
  5.  * @param bool   $can_access Whether the user can access the content.
  6.  * @param int    $user_id    The ID of the user.
  7.  * @param int    $post_id    The ID of the content.
  8.  *
  9.  * @return bool Whether the user can access the content.
  10.  */
  11. function my_custom_wpf_user_can_access( $can_access, $user_id, $post_id ) {
  12.     // Get the value of the ACF dropdown field
  13.     $field_value = get_field( 'my_field_name', $post_id );
  14.  
  15.     // Define the CRM tags for each field value
  16.     $crm_tags = array(
  17.         'A' => 'tag_for_A',
  18.         'B' => 'tag_for_B',
  19.         'C' => 'tag_for_C',
  20.     );
  21.  
  22.     // Check if the field value matches one of the predefined values
  23.     if ( array_key_exists( $field_value, $crm_tags ) ) {
  24.         // Get the tag for the current field value
  25.         $required_tag = $crm_tags[ $field_value ];
  26.  
  27.         // Check if the user has the required tag
  28.         if ( wpf_has_tag( $required_tag, $user_id ) ) {
  29.             return true;
  30.         } else {
  31.             return false;
  32.         }
  33.     }
  34.  
  35.     return $can_access;
  36. }
  37.  
  38. add_filter( 'wpf_user_can_access', 'my_custom_wpf_user_can_access', 10, 3 );
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement