ReduxFramework_checkbox

Main ReduxFramework_checkbox class.

Defined (1)

The class is defined in the following location(s).

/inc/ReduxFramework/ReduxCore/inc/fields/checkbox/field_checkbox.php  
  1. class ReduxFramework_checkbox { 
  2.  
  3. /** 
  4. * Field Constructor. 
  5. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function 
  6. * @since 1.0.0 
  7. * @access public 
  8. * @return void 
  9. */ 
  10. function __construct ( $field = array(), $value = '', $parent ) { 
  11.  
  12. $this->parent = $parent; 
  13. $this->field = $field; 
  14. $this->value = $value; 
  15.  
  16. /** 
  17. * Field Render Function. 
  18. * Takes the vars and outputs the HTML for the field in the settings 
  19. * @since 1.0.0 
  20. * @access public 
  21. * @return void 
  22. */ 
  23. public function render () { 
  24. if( !empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { 
  25. if (empty($this->field['args'])) { 
  26. $this->field['args'] = array(); 
  27.  
  28. $this->field['options'] = $this->parent->get_wordpress_data($this->field['data'], $this->field['args']); 
  29. if (empty($this->field['options'])) { 
  30. return; 
  31.  
  32. $this->field[ 'data_class' ] = ( isset ( $this->field[ 'multi_layout' ] ) ) ? 'data-' . $this->field[ 'multi_layout' ] : 'data-full'; 
  33.  
  34. if ( !empty ( $this->field[ 'options' ] ) && ( is_array ( $this->field[ 'options' ] ) || is_array ( $this->field[ 'default' ] ) ) ) { 
  35.  
  36. echo '<ul class="' . $this->field[ 'data_class' ] . '">'; 
  37.  
  38. if ( !isset ( $this->value ) ) { 
  39. $this->value = array(); 
  40.  
  41. if ( !is_array ( $this->value ) ) { 
  42. $this->value = array(); 
  43.  
  44. if ( empty ( $this->field[ 'options' ] ) && isset ( $this->field[ 'default' ] ) && is_array ( $this->field[ 'default' ] ) ) { 
  45. $this->field[ 'options' ] = $this->field[ 'default' ]; 
  46.  
  47. foreach ( $this->field[ 'options' ] as $k => $v ) { 
  48.  
  49. if ( empty ( $this->value[ $k ] ) ) { 
  50. $this->value[ $k ] = ""; 
  51.  
  52. echo '<li>'; 
  53. echo '<label for="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . '][' . $k . ']', array( 
  54. '[' => '_',  
  55. ']' => '' 
  56. ) ) . '_' . array_search ( $k, array_keys ( $this->field[ 'options' ] ) ) . '">'; 
  57. echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field[ 'name' ] . '[' . $k . ']' . $this->field[ 'name_suffix' ] . '" value="' . $this->value[ $k ] . '" ' . '/>'; 
  58. echo '<input type="checkbox" class="checkbox ' . $this->field[ 'class' ] . '" id="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . '][' . $k . ']', array( 
  59. '[' => '_',  
  60. ']' => '' 
  61. ) ) . '_' . array_search ( $k, array_keys ( $this->field[ 'options' ] ) ) . '" value="1" ' . checked ( $this->value[ $k ], '1', false ) . '/>'; 
  62. echo ' ' . $v . '</label>'; 
  63. echo '</li>'; 
  64.  
  65. echo '</ul>'; 
  66. } else if ( empty ( $this->field[ 'data' ] ) ) { 
  67.  
  68. echo (!empty ( $this->field[ 'desc' ] ) ) ? ' <ul class="data-full"><li><label for="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . ']', array( 
  69. '[' => '_',  
  70. ']' => '' 
  71. ) ) . '">' : ''; 
  72.  
  73. // Got the "Checked" status as "0" or "1" then insert it as the "value" option 
  74. //$ch_value = 1; // checked($this->value, '1', false) == "" ? "0" : "1"; 
  75. echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field[ 'name' ] . $this->field[ 'name_suffix' ] . '" value="' . $this->value . '" ' . '/>'; 
  76. echo '<input type="checkbox" id="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . ']', array( 
  77. '[' => '_',  
  78. ']' => '' 
  79. ) ) . '" value="1" class="checkbox ' . $this->field[ 'class' ] . '" ' . checked ( $this->value, '1', false ) . '/></li></ul>'; 
  80.  
  81. /** 
  82. * Enqueue Function. 
  83. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  84. * @since 1.0.0 
  85. * @access public 
  86. * @return void 
  87. */ 
  88. public function enqueue () { 
  89.  
  90. redux_enqueue_style( 
  91. $this->parent,  
  92. 'redux-field-checkbox-css',  
  93. ReduxFramework::$_url . 'inc/fields/checkbox/field_checkbox.css',  
  94. ReduxFramework::$_dir . 'inc/fields/checkbox',  
  95. array(),  
  96. time(),  
  97. false 
  98. );  
  99.  
  100. // wp_enqueue_style ( 
  101. // 'redux-field-checkbox-css', ReduxFramework::$_url . 'inc/fields/checkbox/field_checkbox.css', time (), true 
  102. // ); 
  103.  
  104. wp_enqueue_script ( 
  105. 'redux-field-checkbox-js', ReduxFramework::$_url . 'inc/fields/checkbox/field_checkbox' . Redux_Functions::isMin () . '.js', array( 'jquery', 'redux-js' ), time (), true 
  106. );