is_admin(), ]); } /** * Normalize parameters for field. * * @param array $field Field parameters. * @return array */ public static function normalize( $field ) { $field = wp_parse_args( $field, [ 'js_options' => [], 'placeholder' => __( 'Select an item', 'meta-box' ), ] ); $field = parent::normalize( $field ); $field['js_options'] = wp_parse_args( $field['js_options'], [ 'allowClear' => true, 'dropdownAutoWidth' => true, 'placeholder' => $field['placeholder'], 'width' => 'style', ] ); return $field; } /** * Get the attributes for a field. * * @param array $field Field parameters. * @param mixed $value Meta value. * @return array */ public static function get_attributes( $field, $value = null ) { $attributes = parent::get_attributes( $field, $value ); $attributes = wp_parse_args( $attributes, [ 'data-options' => wp_json_encode( $field['js_options'] ), ] ); return $attributes; } }