'cx-checkbox-id',
'name' => 'cx-checkbox-name',
'value' => array(
'checkbox-1' => 'true',
'checkbox-2' => 'true',
'checkbox-3' => 'true',
),
'options' => array(
'checkbox-1' => 'checkbox 1',
'checkbox-2' => 'checkbox 2',
'checkbox-3' => 'checkbox 3',
),
'label' => '',
'class' => '',
);
/**
* Render html UI_Checkbox.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '
';
$counter = 0;
if ( isset( $this->settings['options_callback'] ) ) {
$this->settings['options'] = call_user_func( $this->settings['options_callback'] );
}
if ( ! empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ) {
if ( ! is_array( $this->settings['value'] ) ) {
$this->settings['value'] = array( $this->settings['value'] );
}
if ( '' !== $this->settings['label'] ) {
$html .= '
';
}
foreach ( $this->settings['options'] as $option => $option_value ) {
if ( ! empty( $this->settings['value'] ) ) {
$option_checked = array_key_exists( $option, $this->settings['value'] ) ? $option : '';
$item_value = ! empty( $option_checked ) ? $this->settings['value'][ $option ] : 'false';
} else {
$option_checked = '';
$item_value = 'false';
}
$checked = ( ! empty( $option_checked ) && filter_var( $item_value, FILTER_VALIDATE_BOOLEAN ) ) ? 'checked' : '';
$item_value = filter_var( $item_value, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
$option_label = isset( $option_value ) && is_array( $option_value ) ? $option_value['label'] : $option_value;
$html .= '
';
$html .= '';
$html .= '';
$html .= '';
$html .= ' ';
$html .= '';
$html .= '
';
$counter++;
}
}
$html .= '
';
return $html;
}
}
}