Conditions | 3 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 2 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
16 | public function to_json( $load ) { |
||
17 | $field_data = parent::to_json( $load ); |
||
18 | |||
19 | $options = $this->parse_options( $this->get_options() ); |
||
20 | $values = wp_list_pluck( $options, 'value' ); |
||
21 | $value = $this->get_formatted_value(); |
||
22 | if ( ! empty( $values ) ) { |
||
23 | // this roundabout way is required in order to keep proper value types |
||
24 | // as values taken from the database are always strings |
||
25 | $value_index = array_search( $value, $values ); |
||
26 | if ( $value_index !== false ) { |
||
27 | $value = $values[ $value_index ]; |
||
28 | } else { |
||
29 | $value = $values[0]; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | $field_data = array_merge( $field_data, array( |
||
34 | 'value' => $value, |
||
35 | 'options' => $options, |
||
36 | ) ); |
||
37 | |||
38 | return $field_data; |
||
39 | } |
||
40 | } |
||
41 |