Function
Render a radio group setting field.
tml_admin_setting_callback_radio_group_field( array $args )
Parameters
-
$argsarray -
Optional. An array of arguments for rendering a radio group.
-
$label_forstring - The radio button name/ID.
-
$legendstring - The legend text.
-
$optionsarray - An array of options for the radio group.
-
$checkedstring - The value of the checked option.
-
$descriptionstring - A short description of the radio group.
-
Source
function tml_admin_setting_callback_radio_group_field( $args ) {
$args = wp_parse_args(
$args,
array(
'label_for' => '',
'legend' => '',
'options' => array(),
'checked' => '',
'description' => '',
)
);
$options = array();
foreach ( (array) $args['options'] as $value => $label ) {
$options[] = sprintf(
'<label><input type="radio" name="%1$s" value="%2$s"%3$s> %4$s</label>',
esc_html( $args['label_for'] ),
esc_attr( $value ),
checked( $args['checked'], $value, false ),
esc_html( $label )
);
}
?>
<fieldset>
<legend class="screen-reader-text"><span><?php echo esc_html( $args['legend'] ); ?></span></legend>
<?php echo implode( "<br />\n", $options ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- each $options entry is already built via esc_attr()/esc_html() above. */ ?>
</fieldset>
<?php if ( ! empty( $args['description'] ) ) : ?>
<p class="description"><?php echo wp_kses_post( $args['description'] ); ?></p>
<?php endif; ?>
<?php
}
Uses
Changelog
| Version | Description |
|---|---|
| 7.0 | Introduced. |