select.php
31 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) || die; |
| 3 | |
| 4 | /** |
| 5 | * Select walker select fields. |
| 6 | */ |
| 7 | class RWMB_Walker_Select extends RWMB_Walker_Base { |
| 8 | /** |
| 9 | * Start the element output. |
| 10 | * |
| 11 | * @see Walker::start_el() |
| 12 | * |
| 13 | * @param string $output Passed by reference. Used to append additional content. |
| 14 | * @param object $object The data object. |
| 15 | * @param int $depth Depth of the item. |
| 16 | * @param array $args An array of additional arguments. |
| 17 | * @param int $current_object_id ID of the current item. |
| 18 | */ |
| 19 | public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { |
| 20 | $indent = str_repeat( ' ', $depth * 4 ); |
| 21 | |
| 22 | $output .= sprintf( |
| 23 | '<option value="%s" %s>%s%s</option>', |
| 24 | esc_attr( $object->value ), |
| 25 | selected( in_array( $object->value, $this->meta ), true, false ), |
| 26 | $indent, |
| 27 | esc_html( $object->label ) |
| 28 | ); |
| 29 | } |
| 30 | } |
| 31 |