Advertisement
wclovers

Untitled

Sep 14th, 2023
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. // Fix: Staff get more capabilities than vendor
  2. add_filter('wcfmgs_vendor_staff_capability', function ($wcfm_capability_options) {
  3.     if (!wcfm_is_vendor_staff()) {
  4.         return $wcfm_capability_options;
  5.     }
  6.  
  7.     $vendor_id = wcfm_get_staff_vendor();
  8.     $wcfm_user_has_custom_capability = get_user_meta($vendor_id, '_wcfm_user_has_custom_capability', true) ? get_user_meta($vendor_id, '_wcfm_user_has_custom_capability', true) : 'no';
  9.     $vendor_capability_options = array();
  10.  
  11.     if ($wcfm_user_has_custom_capability == 'yes') {
  12.         $vendor_capability_options = (array) get_user_meta($vendor_id, '_wcfm_user_capability_options', true);
  13.     } else {
  14.         $wcfm_user_groups = (array) get_user_meta($vendor_id, '_wcfm_vendor_group', true);
  15.         if (!empty(array_filter($wcfm_user_groups))) {
  16.             $allowed_categories = array();
  17.             foreach ($wcfm_user_groups as $wcfm_user_group) {
  18.                 if ($wcfm_user_group) {
  19.                     $group_capability_options = (array) get_post_meta($wcfm_user_group, '_group_capability_options', true);
  20.                     if (!empty(array_filter($group_capability_options))) {
  21.                         if (isset($group_capability_options['allowed_categories']) && is_array($group_capability_options['allowed_categories'])) {
  22.                             $allowed_categories = array_merge($allowed_categories, $group_capability_options['allowed_categories']);
  23.                         }
  24.                         if (empty($vendor_capability_options)) {
  25.                             $vendor_capability_options = $group_capability_options;
  26.                         } else {
  27.                             $vendor_capability_options = array_intersect_key($vendor_capability_options, $group_capability_options);
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.             $vendor_capability_options['allowed_categories'] = $allowed_categories;
  33.         } else {
  34.             $vendor_capability_options = get_option('wcfm_capability_options', array());
  35.         }
  36.     }
  37.  
  38.     return $wcfm_capability_options + $vendor_capability_options;
  39. }, 501);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement