select2.php
44 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file belongs to the YIT Plugin Framework. |
| 4 | * |
| 5 | * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0) |
| 6 | * that is bundled with this package in the file LICENSE.txt. |
| 7 | * It is also available through the world-wide-web at this URL: |
| 8 | * http://www.gnu.org/licenses/gpl-3.0.txt |
| 9 | * |
| 10 | * @var array $args |
| 11 | * @var string $custom_attributes |
| 12 | */ |
| 13 | |
| 14 | !defined( 'ABSPATH' ) && exit; // Exit if accessed directly |
| 15 | ?> |
| 16 | |
| 17 | <select |
| 18 | id="<?php echo $args[ 'id' ] ?>" |
| 19 | class="<?php echo $args[ 'class' ] ?>" |
| 20 | name="<?php echo $args[ 'name' ] ?>" |
| 21 | data-placeholder="<?php echo $args[ 'data-placeholder' ] ?>" |
| 22 | data-allow_clear="<?php echo $args[ 'data-allow_clear' ] ?>" |
| 23 | <?php echo !empty( $args[ 'data-action' ] ) ? 'data-action="' . $args[ 'data-action' ] . '"' : ''; ?> |
| 24 | <?php echo !empty( $args[ 'data-multiple' ] ) ? 'multiple="multiple"' : ''; ?> |
| 25 | style="<?php echo $args[ 'style' ] ?>" |
| 26 | <?php echo $custom_attributes ?> |
| 27 | > |
| 28 | |
| 29 | <?php if ( !empty( $args[ 'value' ] ) ) { |
| 30 | $values = $args[ 'value' ]; |
| 31 | |
| 32 | if ( !is_array( $values ) ) { |
| 33 | $values = explode( ',', $values ); |
| 34 | } |
| 35 | |
| 36 | foreach ( $values as $value ): ?> |
| 37 | <option value="<?php echo $value; ?>" <?php selected( true, true, true ) ?> > |
| 38 | <?php echo $args[ 'data-selected' ][ $value ]; ?> |
| 39 | </option> |
| 40 | <?php endforeach; |
| 41 | } |
| 42 | ?> |
| 43 | </select> |
| 44 |