| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user; |
| 7 |
|
| 8 |
$response = array(); |
| 9 |
|
| 10 |
$agentonly_fields = get_terms([ |
| 11 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 12 |
'hide_empty' => false, |
| 13 |
'orderby' => 'meta_value_num', |
| 14 |
'meta_key' => 'wpsc_tf_load_order', |
| 15 |
'order' => 'ASC', |
| 16 |
'meta_query' => array( |
| 17 |
array( |
| 18 |
'key' => 'agentonly', |
| 19 |
'value' => '1', |
| 20 |
'compare' => '=' |
| 21 |
) |
| 22 |
), |
| 23 |
]); |
| 24 |
|
| 25 |
foreach ( $agentonly_fields as $ao_field ) { |
| 26 |
|
| 27 |
if ( $current_user->ID && ( $ao_field->slug == 'customer_name' || $ao_field->slug == 'customer_email' ) ) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
|
| 31 |
$options = get_term_meta( $ao_field->term_id, 'wpsc_tf_options', true); |
| 32 |
$options = is_array($options) ? $options : array(); |
| 33 |
$options = isset($options[0]) && $options[0] ? $options : array(); |
| 34 |
|
| 35 |
$temp_options = array(); |
| 36 |
foreach ($options as $value) { |
| 37 |
$temp_options[] = array( |
| 38 |
'name' => $value, |
| 39 |
'value' => $value |
| 40 |
); |
| 41 |
} |
| 42 |
$options = $temp_options; |
| 43 |
|
| 44 |
$field = array( |
| 45 |
'id' => $ao_field->term_id, |
| 46 |
'slug' => $ao_field->slug, |
| 47 |
'label' => get_term_meta( $ao_field->term_id, 'wpsc_tf_label', true), |
| 48 |
'extra_info' => get_term_meta( $ao_field->term_id, 'wpsc_tf_extra_info', true), |
| 49 |
'type' => get_term_meta( $ao_field->term_id, 'wpsc_tf_type', true), |
| 50 |
'options' => $options, |
| 51 |
); |
| 52 |
|
| 53 |
$field = apply_filters('wpsc_api_v1_ao_fields',$field); |
| 54 |
|
| 55 |
$response[] = $field; |
| 56 |
|
| 57 |
} |
| 58 |
|