Skip to content

Function

Render a checkbox setting field.

tml_admin_setting_callback_checkbox_field( array $args )

Parameters

$args array
Optional. An array of arguments for rendering a checkbox.
$label_for string
The checkbox name/ID.
$label stirng
The checkbox label text.
$value string
The checkbox value.
$checked bool
Whether the checkbox is checked or not.
$description string
A short description of the checkbox.

Source

function tml_admin_setting_callback_checkbox_field( $args ) {
    $args = wp_parse_args(
        $args,
        array(
            'label_for'   => '',
            'label'       => '',
            'value'       => '1',
            'checked'     => '',
            'description' => '',
        )
    );
    ?>

    <input type="checkbox" name="<?php echo esc_attr( $args['label_for'] ); ?>" id="<?php echo esc_attr( $args['label_for'] ); ?>" value="<?php echo esc_attr( $args['value'] ); ?>" <?php checked( ! empty( $args['checked'] ) ); ?> /> <label for="<?php echo esc_attr( $args['label_for'] ); ?>"><?php echo esc_html( $args['label'] ); ?></label>

    <?php if ( ! empty( $args['description'] ) ) : ?>
        <p class="description"><?php echo wp_kses_post( $args['description'] ); ?></p>
    <?php endif; ?>

    <?php
}

Uses

Changelog

VersionDescription
7.0 Introduced.