From 873cbd00016adf2e94839327fdc03c2686b69732 Mon Sep 17 00:00:00 2001 From: Jay Wood Date: Fri, 30 Sep 2016 10:41:18 -0400 Subject: [PATCH] A better checked method ref #45, #49 - props @kloneets --- includes/settings.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/settings.php b/includes/settings.php index 61e7f07..74069bb 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -26,27 +26,42 @@ class CWV2_Settings { } + private function checked_array( $haystack, $cur, $show = true ) { + if ( is_array( $haystack ) && in_array( $cur, $haystack ) ) { + $cur = $haystack = 1; + } + if ( is_array( $haystack ) ) { //if $haystack is still an array, take first value + $haystack = array_shift( $haystack ); + } + + return checked( $haystack, $cur, $show ); + } + public function check( $args = array() ) { $args = $this->get_default_args( $args ); $field_id = $args['id']; $description = $args['desc']; $options = $args['options']; + $default = empty( $args['default'] ); if ( ! $options || empty( $field_id ) ) { return; } + $option_value = get_option( $field_id, $field_id, $default ); + ?>
$label ) { - $cur_id = $id . '-' . $offset; + foreach ( $options as $op_value => $label ) { + $cur_id = $op_value . '-' . $offset; $offset++; ?>