class-redux-radio.php (1986B)
1 <?php 2 /** 3 * Radio Button Field. 4 * 5 * @package ReduxFramework/Fields 6 * @author Dovy Paukstys & Kevin Provance (kprovance) 7 * @version 4.0.0 8 */ 9 10 defined( 'ABSPATH' ) || exit; 11 12 if ( ! class_exists( 'Redux_Radio', false ) ) { 13 14 /** 15 * Class Redux_Radio 16 */ 17 class Redux_Radio extends Redux_Field { 18 19 /** 20 * Field Render Function. 21 * Takes the vars and outputs the HTML for the field in the settings 22 * 23 * @since ReduxFramework 1.0.0 24 */ 25 public function render() { 26 if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { 27 if ( empty( $this->field['args'] ) ) { 28 $this->field['args'] = array(); 29 } 30 31 if ( is_array( $this->field['data'] ) ) { 32 $this->field['options'] = $this->field['data']; 33 } else { 34 $this->field['options'] = $this->parent->get_wordpress_data( $this->field['data'], $this->field['args'], $this->value ); 35 } 36 } 37 38 $this->field['data_class'] = ( isset( $this->field['multi_layout'] ) ) ? 'data-' . $this->field['multi_layout'] : 'data-full'; 39 40 if ( isset( $this->field['options'] ) && ! empty( $this->field['options'] ) ) { 41 echo '<ul class="' . esc_attr( $this->field['data_class'] ) . '">'; 42 43 foreach ( $this->field['options'] as $k => $v ) { 44 echo '<li>'; 45 echo '<label for="' . esc_attr( $this->field['id'] . '_' . array_search( $k, array_keys( $this->field['options'] ), true ) ) . '">'; 46 echo '<input 47 type="radio" 48 class="radio ' . esc_attr( $this->field['class'] ) . '" 49 id="' . esc_attr( $this->field['id'] . '_' . array_search( $k, array_keys( $this->field['options'] ), true ) ) . '" 50 name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" 51 value="' . esc_attr( $k ) . '" ' . checked( $this->value, $k, false ) . '/>'; 52 53 echo ' <span>' . esc_html( $v ) . '</span>'; 54 echo '</label>'; 55 echo '</li>'; 56 } 57 58 echo '</ul>'; 59 } 60 } 61 } 62 } 63 64 class_alias( 'Redux_Radio', 'ReduxFramework_Radio' );