cmb.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * 'icon' field type for Custom Meta Boxes |
| 5 | * |
| 6 | * @link https://github.com/humanmade/Custom-Meta-Boxes/wiki/Adding-your-own-field-types CMB Wiki |
| 7 | * @version 0.1.1 |
| 8 | * @since Icon_Picker 0.2.0 |
| 9 | */ |
| 10 | class Icon_Picker_Field_Cmb extends CMB_Field { |
| 11 | /** |
| 12 | * Constructor |
| 13 | * |
| 14 | * @since 0.1.0 |
| 15 | * @see {CMB_Field::__construct()} |
| 16 | */ |
| 17 | public function __construct( $name, $title, array $values, $args = array() ) { |
| 18 | parent::__construct( $name, $title, $values, $args ); |
| 19 | Icon_Picker::instance()->load(); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Parse save values |
| 24 | * |
| 25 | * When used as a sub-field of a `group` field, wrap the values with array. |
| 26 | * |
| 27 | * @since 0.1.1 |
| 28 | */ |
| 29 | public function parse_save_values() { |
| 30 | if ( ! empty( $this->parent ) ) { |
| 31 | $this->values = array( $this->values ); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Display the field |
| 37 | * |
| 38 | * @since 0.1.0 |
| 39 | * @see {CMB_Field::html()} |
| 40 | */ |
| 41 | public function html() { |
| 42 | icon_picker_field( array( |
| 43 | 'id' => $this->id, |
| 44 | 'name' => $this->get_the_name_attr(), |
| 45 | 'value' => $this->get_value(), |
| 46 | ) ); |
| 47 | } |
| 48 | } |
| 49 |