| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for field select |
| 4 |
* |
| 5 |
* @package Wow_Plugin |
| 6 |
* @copyright Copyright (c) 2018, Dmytro Lobov |
| 7 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 8 |
* @since 1.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
$label = ! empty( $arg['label'] ) ? $arg['label'] : ''; |
| 16 |
$attr = ! empty( $arg['attr'] ) ? $arg['attr'] : ''; |
| 17 |
$help = ! empty( $arg['help'] ) ? $arg['help'] : ''; |
| 18 |
$icon = ! empty( $arg['icon'] ) ? $arg['icon'] : ''; |
| 19 |
$value = ! empty( $arg['attr']['value'] ) ? $arg['attr']['value'] : ''; |
| 20 |
$tooltip = ! empty( $arg['tooltip'] ) ? $arg['tooltip'] : ''; |
| 21 |
|
| 22 |
$check_id = ''; |
| 23 |
$checkbox_class = ''; |
| 24 |
$checkbox = ''; |
| 25 |
if ( ! empty( $arg['checkbox'] ) ) { |
| 26 |
$checkbox_class = ' checkbox'; |
| 27 |
$check_name = $arg['checkbox']['name']; |
| 28 |
$check_val = $arg['checkbox']['value']; |
| 29 |
$check_id = $arg['checkbox']['id']; |
| 30 |
$disabled = isset( $arg['checkbox']['disabled'] ) ? ' disabled="disabled"' : ''; |
| 31 |
$check_class = isset( $arg['checkbox']['class'] ) ? ' ' . $arg['checkbox']['class'] : ''; |
| 32 |
$cheched = ! empty( $arg['checkbox']['value'] ) ? ' checked="checked"' : ''; |
| 33 |
$checkbox = '<input type="hidden" name="' . esc_attr( $check_name ) . '" value="">'; |
| 34 |
$checkbox .= '<input type="checkbox" class="is-radiusless' . esc_attr( $check_class ) . '" id="' . esc_attr( $check_id ) . '" name="' . esc_attr( $check_name ) . '" value="1"' . $cheched . $disabled . '>'; |
| 35 |
} |
| 36 |
|
| 37 |
$add_control_class = ! empty( $icon ) ? ' has-icons-left' : ''; |
| 38 |
$control_classes = 'control' . $add_control_class; |
| 39 |
|
| 40 |
$add_field_class = ! empty( $arg['attr']['class'] ) ? ' ' . $arg['attr']['class'] : ''; |
| 41 |
$field_classes = 'is-radiusless' . $add_field_class; |
| 42 |
|
| 43 |
$attributes = ''; |
| 44 |
foreach ( $attr as $key => $val ) { |
| 45 |
if ( $key == 'class' || $key == 'value' ) { |
| 46 |
continue; |
| 47 |
} |
| 48 |
$attributes .= esc_attr( $key ) . '="' . esc_attr( $val ) . '"'; |
| 49 |
} |
| 50 |
|
| 51 |
if ( ! empty( $arg['func'] ) ) { |
| 52 |
$attributes .= 'onchange="' . esc_attr( $arg['func'] ) . ';"'; |
| 53 |
} |
| 54 |
|
| 55 |
$option = ''; |
| 56 |
foreach ( $arg['options'] as $key => $val ) { |
| 57 |
$selected = ( $value == $key ) ? 'selected="selected"' : ''; |
| 58 |
$option .= '<option value="' . esc_attr( $key ) . '" ' . $selected . '>' . esc_attr( $val ) . '</option>'; |
| 59 |
} |
| 60 |
|
| 61 |
?> |
| 62 |
|
| 63 |
<?php if ( ! empty( $label ) ) : ?> |
| 64 |
<label class="label<?php echo esc_attr( $checkbox_class ); ?>" for="<?php echo esc_attr( $check_id ); ?>"> |
| 65 |
<?php echo $checkbox; ?> |
| 66 |
<?php echo esc_attr( $label ); ?> |
| 67 |
<?php if ( ! empty( $tooltip ) ) : ?> |
| 68 |
<span class="is-primary has-tooltip-multiline has-tooltip-right" |
| 69 |
data-tooltip="<?php echo esc_attr( $tooltip ); ?>"> |
| 70 |
<span class="wow-help dashicons dashicons-editor-help"></span> |
| 71 |
</span> |
| 72 |
<?php endif; ?> |
| 73 |
</label> |
| 74 |
<?php endif; ?> |
| 75 |
<div class="field"> |
| 76 |
<div class="<?php echo esc_attr( $control_classes ); ?>"> |
| 77 |
<div class="select is-primary is-fullwidth"> |
| 78 |
<select class="<?php echo esc_attr( $field_classes ); ?>" <?php echo $attributes; ?>> |
| 79 |
<?php echo $option; ?> |
| 80 |
</select> |
| 81 |
</div> |
| 82 |
<?php if ( ! empty( $icon ) ) : ?> |
| 83 |
<span class="icon is-small is-left"> |
| 84 |
<i class="<?php echo esc_attr( $icon ); ?>"></i> |
| 85 |
</span> |
| 86 |
<?php endif; ?> |
| 87 |
</div> |
| 88 |
</div> |
| 89 |
<?php if ( ! empty( $help ) ) : ?> |
| 90 |
<p class="help is-info"><?php echo esc_attr( $help ); ?></p> |
| 91 |
<?php endif; ?> |