json['value'] = $this->value(); $this->json['choices'] = $this->choices; $this->json['link'] = $this->get_link(); $this->json['numeric_value'] = $this->numeric_value(); $this->json['unit_value'] = $this->unit_value(); $this->json['available_units'] = $this->get_units(); } public function content_template() { ?> choices ) && is_array( $this->choices ) && ! empty( $this->choices ) ) { $choices = array(); foreach ( $this->choices as $choice ) { if ( in_array( $choice, $all_units ) ) { $choices[] = $choice; } } if ( ! empty( $choices ) ) { return $choices; } } return $defaults; } /** * Get the numeric value of the field * * @return float|int */ public function numeric_value() { // Sanitize the input field and return numeric values, rounded to 2 decimals. return round( filter_var( $this->value(), FILTER_SANITIZE_NUMBER_FLOAT ), 2 ); } /** * Get the value of the units we're using. * * @return string */ public function unit_value() { foreach ( $this->get_units() as $unit ) { if ( false !== strpos( $this->value(), $unit ) ) { $located_unit = $unit; break; } } return ( isset( $located_unit ) ) ? $located_unit : 'px'; } }