ReduxFramework_select

The Gravity Forms Advanced File Uploader ReduxFramework select class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/select/field_select.php  
  1. class ReduxFramework_select { 
  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 ReduxFramework 1.0.0 
  7. */ 
  8. public function __construct( $field = array(), $value = '', $parent ) { 
  9. $this->parent = $parent; 
  10. $this->field = $field; 
  11. $this->value = $value; 
  12.  
  13. /** 
  14. * Field Render Function. 
  15. * Takes the vars and outputs the HTML for the field in the settings 
  16. * @since ReduxFramework 1.0.0 
  17. */ 
  18. public function render() { 
  19. $sortable = ( isset( $this->field['sortable'] ) && $this->field['sortable'] ) ? ' select2-sortable"' : ""; 
  20.  
  21. if ( ! empty( $sortable ) ) { // Dummy proofing :P 
  22. $this->field['multi'] = true; 
  23.  
  24. if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { 
  25. if ( empty( $this->field['args'] ) ) { 
  26. $this->field['args'] = array(); 
  27.  
  28. if ( $this->field['data'] == "elusive-icons" || $this->field['data'] == "elusive-icon" || $this->field['data'] == "elusive" ) { 
  29. $icons_file = ReduxFramework::$_dir . 'inc/fields/select/elusive-icons.php'; 
  30. /** 
  31. * filter 'redux-font-icons-file}' 
  32. * @param array $icon_file File for the icons 
  33. */ 
  34. $icons_file = apply_filters( 'redux-font-icons-file', $icons_file ); 
  35.  
  36. /** 
  37. * filter 'redux/{opt_name}/field/font/icons/file' 
  38. * @param array $icon_file File for the icons 
  39. */ 
  40. $icons_file = apply_filters( "redux/{$this->parent->args['opt_name']}/field/font/icons/file", $icons_file ); 
  41. if ( file_exists( $icons_file ) ) { 
  42. require_once( $icons_file ); 
  43.  
  44. $this->field['options'] = $this->parent->get_wordpress_data( $this->field['data'], $this->field['args'] ); 
  45.  
  46. if ( ! empty( $this->field['data'] ) && ( $this->field['data'] == "elusive-icons" || $this->field['data'] == "elusive-icon" || $this->field['data'] == "elusive" ) ) { 
  47. $this->field['class'] = " font-icons"; 
  48. //if 
  49.  
  50. if ( ! empty( $this->field['options'] ) ) { 
  51. $multi = ( isset( $this->field['multi'] ) && $this->field['multi'] ) ? ' multiple="multiple"' : ""; 
  52.  
  53. if ( ! empty( $this->field['width'] ) ) { 
  54. $width = ' style="' . $this->field['width'] . '"'; 
  55. } else { 
  56. $width = ' style="width: 40%;"'; 
  57.  
  58. $nameBrackets = ""; 
  59. if ( ! empty( $multi ) ) { 
  60. $nameBrackets = "[]"; 
  61.  
  62. $placeholder = ( isset( $this->field['placeholder'] ) ) ? esc_attr( $this->field['placeholder'] ) : __( 'Select an item', 'redux-framework' ); 
  63.  
  64. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  65. $select2_params = json_encode( $this->field['select2'] ); 
  66. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  67.  
  68. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  69.  
  70. if ( isset( $this->field['multi'] ) && $this->field['multi'] && isset( $this->field['sortable'] ) && $this->field['sortable'] && ! empty( $this->value ) && is_array( $this->value ) ) { 
  71. $origOption = $this->field['options']; 
  72. $this->field['options'] = array(); 
  73.  
  74. foreach ( $this->value as $value ) { 
  75. $this->field['options'][ $value ] = $origOption[ $value ]; 
  76.  
  77. if ( count( $this->field['options'] ) < count( $origOption ) ) { 
  78. foreach ( $origOption as $key => $value ) { 
  79. if ( ! in_array( $key, $this->field['options'] ) ) { 
  80. $this->field['options'][ $key ] = $value; 
  81.  
  82. $sortable = ( isset( $this->field['sortable'] ) && $this->field['sortable'] ) ? ' select2-sortable"' : ""; 
  83.  
  84. echo '<select ' . $multi . ' id="' . $this->field['id'] . '-select" data-placeholder="' . $placeholder . '" name="' . $this->field['name'] . $this->field['name_suffix'] . $nameBrackets . '" class="redux-select-item ' . $this->field['class'] . $sortable . '"' . $width . ' rows="6">'; 
  85. echo '<option></option>'; 
  86.  
  87. foreach ( $this->field['options'] as $k => $v ) { 
  88.  
  89. if (is_array($v)) { 
  90. echo '<optgroup label="' . $k . '">'; 
  91.  
  92. foreach($v as $opt => $val) { 
  93. $this->make_option($opt, $val, $k); 
  94.  
  95. echo '</optgroup>'; 
  96.  
  97. continue; 
  98.  
  99. $this->make_option($k, $v); 
  100. //foreach 
  101.  
  102. echo '</select>'; 
  103. } else { 
  104. echo '<strong>' . __( 'No items of this type were found.', 'redux-framework' ) . '</strong>'; 
  105. } //function 
  106.  
  107. private function make_option($id, $value, $group_name = '') { 
  108. if ( is_array( $this->value ) ) { 
  109. $selected = ( is_array( $this->value ) && in_array( $id, $this->value ) ) ? ' selected="selected"' : ''; 
  110. } else { 
  111. $selected = selected( $this->value, $id, false ); 
  112.  
  113. echo '<option data-group="' . $group_name . '" value="' . $id . '"' . $selected . '>' . $value . '</option>';  
  114.  
  115. /** 
  116. * Enqueue Function. 
  117. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  118. * @since ReduxFramework 1.0.0 
  119. */ 
  120. public function enqueue() { 
  121.  
  122. wp_enqueue_script( 
  123. 'redux-field-select-js',  
  124. ReduxFramework::$_url . 'inc/fields/select/field_select' . Redux_Functions::isMin() . '.js',  
  125. array( 'jquery', 'select2-js', 'redux-js' ),  
  126. time(),  
  127. true 
  128. ); 
  129.  
  130. redux_enqueue_style( 
  131. $this->parent,  
  132. 'redux-field-select-css',  
  133. ReduxFramework::$_url . 'inc/fields/select/field_select.css',  
  134. ReduxFramework::$_dir . 'inc/fields/select',  
  135. array(),  
  136. time(),  
  137. false 
  138. );  
  139.  
  140. // wp_enqueue_style( 
  141. // 'redux-field-select-css',  
  142. // ReduxFramework::$_url . 'inc/fields/select/field_select.css',  
  143. // time(),  
  144. // true 
  145. // ); 
  146. } //function 
  147. } //class