| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
if ( ! class_exists( 'ReduxFramework_radio' ) ) { |
| 9 |
class ReduxFramework_radio { |
| 10 |
|
| 11 |
/** |
| 12 |
* Field Constructor. |
| 13 |
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function |
| 14 |
* |
| 15 |
* @since ReduxFramework 1.0.0 |
| 16 |
*/ |
| 17 |
function __construct( $field = array(), $value = '', $parent ) { |
| 18 |
$this->parent = $parent; |
| 19 |
$this->field = $field; |
| 20 |
$this->value = $value; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Field Render Function. |
| 25 |
* Takes the vars and outputs the HTML for the field in the settings |
| 26 |
* |
| 27 |
* @since ReduxFramework 1.0.0 |
| 28 |
*/ |
| 29 |
function render() { |
| 30 |
|
| 31 |
if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { |
| 32 |
if ( empty( $this->field['args'] ) ) { |
| 33 |
$this->field['args'] = array(); |
| 34 |
} |
| 35 |
$this->field['options'] = $this->parent->get_wordpress_data( $this->field['data'], $this->field['args'] ); |
| 36 |
} |
| 37 |
|
| 38 |
$this->field['data_class'] = ( isset( $this->field['multi_layout'] ) ) ? 'data-' . $this->field['multi_layout'] : 'data-full'; |
| 39 |
|
| 40 |
if ( ! empty( $this->field['options'] ) ) { |
| 41 |
echo '<ul class="' . $this->field['data_class'] . '">'; |
| 42 |
|
| 43 |
foreach ( $this->field['options'] as $k => $v ) { |
| 44 |
echo '<li>'; |
| 45 |
echo '<label for="' . $this->field['id'] . '_' . array_search( $k, array_keys( $this->field['options'] ) ) . '">'; |
| 46 |
echo '<input type="radio" class="radio ' . $this->field['class'] . '" id="' . $this->field['id'] . '_' . array_search( $k, array_keys( $this->field['options'] ) ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '" value="' . $k . '" ' . checked( $this->value, $k, false ) . '/>'; |
| 47 |
echo ' <span>' . $v . '</span>'; |
| 48 |
echo '</label>'; |
| 49 |
echo '</li>'; |
| 50 |
} |
| 51 |
//foreach |
| 52 |
|
| 53 |
echo '</ul>'; |
| 54 |
} |
| 55 |
} //function |
| 56 |
} //class |
| 57 |
} |