diff --git a/README.md b/README.md index a9421a1a..fb7fe833 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WordPress Libs WordPress library which supports a core plugin and theme. -**Version [1.16.0](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.16.0)** +**Version [1.17.0](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.17.0)** ### Requirements 1. PHP Version 7.1.3+ (Recommended 7.2.0+) diff --git a/src/CMB2/Field/True_False.php b/src/CMB2/Field/True_False.php new file mode 100644 index 00000000..07883073 --- /dev/null +++ b/src/CMB2/Field/True_False.php @@ -0,0 +1,185 @@ + 'checkbox', + 'class' => 'cmb2-option cmb2-list', + 'value' => 'on', + 'desc' => '', + ]; + + $meta_value = $this->field->escaped_value(); + + $is_checked = $this->is_checked ?? ! empty( $meta_value ); + + if ( $is_checked ) { + $defaults['checked'] = 'checked'; + } + + return $this->rendered( + sprintf( + '%s ', + $this->render_toggle_field( $defaults ), + $this->_id(), + $this->_desc() + ) + ); + } + + /** + * Generates a CSS only driven toggle on/off field. + * + * @param array $args + * + * @return string + */ + protected function render_toggle_field( array $args ) : string { + ob_start(); + $args['class'] .= ' checkbox-toggle-checkbox'; + ?> +