Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fix: Staff get more capabilities than vendor
- add_filter('wcfmgs_vendor_staff_capability', function ($wcfm_capability_options) {
- if (!wcfm_is_vendor_staff()) {
- return $wcfm_capability_options;
- }
- $vendor_id = wcfm_get_staff_vendor();
- $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';
- $vendor_capability_options = array();
- if ($wcfm_user_has_custom_capability == 'yes') {
- $vendor_capability_options = (array) get_user_meta($vendor_id, '_wcfm_user_capability_options', true);
- } else {
- $wcfm_user_groups = (array) get_user_meta($vendor_id, '_wcfm_vendor_group', true);
- if (!empty(array_filter($wcfm_user_groups))) {
- $allowed_categories = array();
- foreach ($wcfm_user_groups as $wcfm_user_group) {
- if ($wcfm_user_group) {
- $group_capability_options = (array) get_post_meta($wcfm_user_group, '_group_capability_options', true);
- if (!empty(array_filter($group_capability_options))) {
- if (isset($group_capability_options['allowed_categories']) && is_array($group_capability_options['allowed_categories'])) {
- $allowed_categories = array_merge($allowed_categories, $group_capability_options['allowed_categories']);
- }
- if (empty($vendor_capability_options)) {
- $vendor_capability_options = $group_capability_options;
- } else {
- $vendor_capability_options = array_intersect_key($vendor_capability_options, $group_capability_options);
- }
- }
- }
- }
- $vendor_capability_options['allowed_categories'] = $allowed_categories;
- } else {
- $vendor_capability_options = get_option('wcfm_capability_options', array());
- }
- }
- return $wcfm_capability_options + $vendor_capability_options;
- }, 501);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement