Setup options for number fields, should fix #55

This commit is contained in:
Jay Wood
2016-09-30 12:19:44 -04:00
parent f6a8e942d7
commit 40d4f18c4a
2 changed files with 16 additions and 5 deletions

View File

@ -417,6 +417,11 @@ class CWV2_Admin {
'name' => __( 'Background Opacity', 'content-warning-v2' ), 'name' => __( 'Background Opacity', 'content-warning-v2' ),
'desc' => __( 'Input a float value from 0-1, the latter being completely opaque.', 'content-warning-v2' ), 'desc' => __( 'Input a float value from 0-1, the latter being completely opaque.', 'content-warning-v2' ),
'type' => 'number', 'type' => 'number',
'options' => array(
'step' => 0.1,
'max' => 1,
'min' => 0,
),
), ),
array( array(
'id' => 'bg_color', 'id' => 'bg_color',

View File

@ -1,11 +1,8 @@
<?php <?php
class CWV2_Settings { class CWV2_Settings {
// Stuff
public function def_group() { public function def_group() {}
}
/** /**
* Just gets a default set of arguments to make sure they're always set. * Just gets a default set of arguments to make sure they're always set.
@ -73,13 +70,22 @@ class CWV2_Settings {
$field_id = $args['id']; $field_id = $args['id'];
$description = $args['desc']; $description = $args['desc'];
$default = empty( $args['default'] ) ? array() : $args['default']; $default = empty( $args['default'] ) ? array() : $args['default'];
$options = empty( $args['options'] ) ? array() : $args['options'];
if ( empty( $field_id ) ) { if ( empty( $field_id ) ) {
return; return;
} }
$option_value = get_option( $field_id, $field_id, $default ); $option_value = get_option( $field_id, $field_id, $default );
?><input type="number" name="<?php echo $field_id; ?>" value="<?php echo intval( $option_value ); ?>" id="<?php echo $field_id; ?>" /><?php $attributes = '';
if ( ! empty( $options ) ) {
foreach ( $options as $k => $v ) {
$attributes .= $k . '="' . $v . '"';
}
}
?><input type="number" name="<?php echo $field_id; ?>" value="<?php echo intval( $option_value ); ?>" id="<?php echo $field_id; ?>" <?php echo $attributes; ?>/><?php
if ( ! empty( $description ) ) { if ( ! empty( $description ) ) {
?><p class="description"><?php echo $description; ?></p><?php ?><p class="description"><?php echo $description; ?></p><?php