1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WCQD_METABOX_Radio_Field' ) )
{
class WCQD_METABOX_Radio_Field extends WCQD_METABOX_Field
{
/**
* Get field HTML
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static function html( $meta, $field )
{
$html = array();
$tpl = '<label><input type="radio" class="rwmb-radio" name="%s" value="%s"%s> %s</label>';
foreach ( $field['options'] as $value => $label )
{
$html[] = sprintf(
$tpl,
$field['field_name'],
$value,
checked( $value, $meta, false ),
$label
);
}
return implode( ' ', $html );
}
/**
* Output the field value
* Display option name instead of option value
*
* @use self::meta()
*
* @param array $field Field parameters
* @param array $args Additional arguments. Rarely used. See specific fields for details
* @param int|null $post_id Post ID. null for current post. Optional.
*
* @return mixed Field value
*/
static function the_value( $field, $args = array(), $post_id = null )
{
$value = parent::get_value( $field, $args, $post_id );
return empty( $value ) ? '' : $field['options'][$value];
}
}
}