wpDiscuz 7 API Documentation

  1. Home
  2. Docs
  3. wpDiscuz 7 API Documentation
  4. Filters
  5. wpdiscuz_user_can_view_field
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

wpdiscuz_user_can_view_field

The logic of the hook is the same as the wpdiscuz_user_can_view_fields one. However, it works separately for each custom field. This means that using this hook, it’s possible to separately show or hide a specific field.

Changelog

since 7.6.20 version

Parameters

1. $canView – if true user can view the field
2. $currentUser – the current user
3. $fieldData- the current field’s data from settings
4. $fieldValue – the value of current field in the Database

Usage

add_filter("wpdiscuz_user_can_view_field", function ($canView, $currentUser, $fieldData, $fieldValue) {

    if (!empty($currentUser->roles) && is_array($currentUser->roles) && in_array('administrator', $currentUser->roles)) {

        if (isset($fieldData['name']) && $fieldData['name'] === 'Rating' && $fieldValue < 4) {
            $canView = false;
        }

    }
    
    return $canView;
}, 10, 4);

Was this article helpful to you? Yes 1 No