# supportcandy/2.3.1/includes/rest_api/v1/get_agentonly_fields.php

SupportCandy – AI Customer Support Ticket System &amp; Live Chatbot Agent, version 2.3.1. 58 lines.

- Page: https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/rest_api/v1/get_agentonly_fields.php
- Raw: https://pluginprobe.com/plugins/supportcandy/2.3.1/raw/includes/rest_api/v1/get_agentonly_fields.php
- Modified: 2022-07-21T08:20:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/rest_api/v1/get_agentonly_fields.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

global $current_user;

$response = array();

$agentonly_fields = get_terms([
	'taxonomy'   => 'wpsc_ticket_custom_fields',
	'hide_empty' => false,
	'orderby'    => 'meta_value_num',
	'meta_key'	 => 'wpsc_tf_load_order',
	'order'    	 => 'ASC',
	'meta_query' => array(
		array(
      'key'       => 'agentonly',
      'value'     => '1',
      'compare'   => '='
    )
	),
]);

foreach ( $agentonly_fields as $ao_field ) {
  
    if ( $current_user->ID && ( $ao_field->slug == 'customer_name' || $ao_field->slug == 'customer_email' ) ) {
      continue;
    }
    
    $options = get_term_meta( $ao_field->term_id, 'wpsc_tf_options', true);
    $options = is_array($options) ? $options : array();
    $options = isset($options[0]) && $options[0] ? $options : array();
    
    $temp_options = array();
    foreach ($options as $value) {
      $temp_options[] = array(
        'name'  => $value,
        'value' => $value
      );
    }
    $options = $temp_options;
    
    $field = array(
      'id'                    => $ao_field->term_id,
      'slug'                  => $ao_field->slug,
      'label'                 => get_term_meta( $ao_field->term_id, 'wpsc_tf_label', true),
      'extra_info'            => get_term_meta( $ao_field->term_id, 'wpsc_tf_extra_info', true),
      'type'                  => get_term_meta( $ao_field->term_id, 'wpsc_tf_type', true),
      'options'               => $options,
    );
    
    $field = apply_filters('wpsc_api_v1_ao_fields',$field);
    
    $response[] = $field;
  
}

```
