/lib/php/class-dc-wp-fields.php

  1. <?php 
  2. /** 
  3. * Dualcube Wp Fields Lib 
  4. * 
  5. * All Standard HTML fields can be include in your frontend or backend pages  
  6. * 
  7. * @author Dualcube 
  8. * @category Library 
  9. * @package lib/php 
  10. * @version 1.0.2 
  11. */ 
  12. class DC_WP_Fields { 
  13.  
  14. /** 
  15. * Start up 
  16. */ 
  17. public function __construct() { 
  18.  
  19.  
  20. /** 
  21. * Output a hidden input box. 
  22. * 
  23. * @access public 
  24. * @param array $field 
  25. * @return void 
  26. */ 
  27. function hidden_input( $field ) { 
  28.  
  29. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  30. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'hidden'; 
  31. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  32.  
  33. // Custom attribute handling 
  34. $custom_attributes = array(); 
  35.  
  36. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  37. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  38. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  39.  
  40. printf( 
  41. '<input type="hidden" id="%s" name="%s" class="%s" value="%s" %s />',  
  42. esc_attr($field['id']),  
  43. esc_attr($field['name']),  
  44. esc_attr($field['class']),  
  45. esc_attr($field['value']),  
  46. implode( ' ', $custom_attributes ) 
  47. ); 
  48.  
  49. /** 
  50. * Output a text input box. 
  51. * 
  52. * @access public 
  53. * @param array $field 
  54. * @return void 
  55. */ 
  56. public function text_input($field) { 
  57. $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; 
  58. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'regular-text'; 
  59. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  60. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  61. $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text'; 
  62.  
  63. // Custom attribute handling 
  64. $custom_attributes = array(); 
  65.  
  66. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  67. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  68. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  69.  
  70. $field = $this->field_wrapper_start($field); 
  71.  
  72. printf( 
  73. '<input type="%s" id="%s" name="%s" class="%s" value="%s" placeholder="%s" %s />',  
  74. $field['type'],  
  75. esc_attr($field['id']),  
  76. esc_attr($field['name']),  
  77. esc_attr($field['class']),  
  78. esc_attr($field['value']),  
  79. esc_attr($field['placeholder']),  
  80. implode( ' ', $custom_attributes ) 
  81. ); 
  82.  
  83. $this->field_wrapper_end($field); 
  84.  
  85. /** 
  86. * Output a textarea input box. 
  87. * 
  88. * @access public 
  89. * @param array $field 
  90. * @return void 
  91. */ 
  92. function textarea_input( $field ) { 
  93.  
  94. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  95. $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; 
  96. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'textarea'; 
  97. $field['rows'] = isset( $field['rows'] ) ? $field['rows'] : 2; 
  98. $field['cols'] = isset( $field['cols'] ) ? $field['cols'] : 20; 
  99. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  100.  
  101. // Custom attribute handling 
  102. $custom_attributes = array(); 
  103.  
  104. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  105. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  106. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  107.  
  108. $field = $this->field_wrapper_start($field); 
  109.  
  110. printf( 
  111. '<textarea id="%s" name="%s" class="%s" placeholder="%s" rows="%s" cols="%s" %s>%s</textarea>',  
  112. esc_attr($field['id']),  
  113. esc_attr($field['name']),  
  114. esc_attr($field['class']),  
  115. esc_attr($field['placeholder']),  
  116. absint($field['rows']),  
  117. absint($field['cols']),  
  118. implode( ' ', $custom_attributes ),  
  119. esc_textarea($field['value']) 
  120. ); 
  121.  
  122. $this->field_wrapper_end($field); 
  123.  
  124. /** 
  125. * Output a wp editor box. 
  126. * 
  127. * @access public 
  128. * @param array $field 
  129. * @return void 
  130. */ 
  131. function wpeditor_input( $field ) { 
  132.  
  133. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  134. $field['rows'] = isset( $field['rows'] ) ? $field['rows'] : 5; 
  135. $field['cols'] = isset( $field['cols'] ) ? $field['cols'] : 10; 
  136. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  137.  
  138. $field = $this->field_wrapper_start($field); 
  139.  
  140. wp_editor(stripslashes($field['value']), $field['id'], $settings = array('textarea_name' => $field['name'], 'textarea_rows' => $field['rows'])); 
  141.  
  142. $this->field_wrapper_end($field); 
  143.  
  144. /** 
  145. * Output a checkbox. 
  146. * 
  147. * @access public 
  148. * @param array $field 
  149. * @return void 
  150. */ 
  151. public function checkbox_input($field) { 
  152. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox'; 
  153. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  154. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  155. $field['dfvalue'] = isset( $field['dfvalue'] ) ? $field['dfvalue'] : ''; 
  156.  
  157. // Custom attribute handling 
  158. $custom_attributes = array(); 
  159.  
  160. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  161. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  162. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  163.  
  164. $field = $this->field_wrapper_start($field); 
  165.  
  166. printf( 
  167. '<input type="checkbox" id="%s" name="%s" class="%s" value="%s" %s %s />',  
  168. esc_attr($field['id']),  
  169. esc_attr($field['name']),  
  170. esc_attr($field['class']),  
  171. esc_attr($field['value']),  
  172. checked( $field['value'], $field['dfvalue'], false ),  
  173. implode( ' ', $custom_attributes ) 
  174. ); 
  175.  
  176. $this->field_wrapper_end($field); 
  177.  
  178. /** 
  179. * Output a radio gruop field. 
  180. * 
  181. * @access public 
  182. * @param array $field 
  183. * @return void 
  184. */ 
  185. public function radio_input($field) { 
  186. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short'; 
  187. $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; 
  188. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  189. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  190. $field['dfvalue'] = isset( $field['dfvalue'] ) ? $field['dfvalue'] : ''; 
  191. $field['value'] = ( $field['value'] ) ? $field['value'] : $field['dfvalue']; 
  192.  
  193. $options = ''; 
  194. foreach ( $field['options'] as $key => $value ) { 
  195. $options .= '<label title="' . esc_attr($key) .'"><input class="' . esc_attr($field['class']) . '" type="radio" ' . checked( esc_attr($field['value']), esc_attr($key), false ) . ' value="' . esc_attr($key) . '" name="' . esc_attr($field['name']) . '"> <span>' . esc_html($value) . '</span></label><br />'; 
  196.  
  197. $field = $this->field_wrapper_start($field); 
  198.  
  199. printf( 
  200. <fieldset id="%s" class="%s_field %s"> 
  201. <legend class="screen-reader-text"><span>%s</span></legend> 
  202. %s 
  203. </fieldset> 
  204. ',  
  205. esc_attr($field['id']),  
  206. esc_attr($field['id']),  
  207. esc_attr($field['wrapper_class']),  
  208. esc_attr($field['title']),  
  209. $options 
  210. ); 
  211.  
  212. $this->field_wrapper_end($field); 
  213.  
  214. /** 
  215. * Output a select input box. 
  216. * 
  217. * @access public 
  218. * @param array $field 
  219. * @return void 
  220. */ 
  221. public function select_input($field) { 
  222. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short'; 
  223. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  224. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  225.  
  226. // Custom attribute handling 
  227. $custom_attributes = array(); 
  228.  
  229. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  230. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  231. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  232.  
  233. $options = ''; 
  234. foreach ( $field['options'] as $key => $value ) { 
  235. $options .= '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; 
  236.  
  237. $field = $this->field_wrapper_start($field); 
  238.  
  239. printf( 
  240. '<select id="%s" name="%s" class="%s" %s />%s</select>',  
  241. esc_attr($field['id']),  
  242. esc_attr($field['name']),  
  243. esc_attr($field['class']),  
  244. implode( ' ', $custom_attributes ),  
  245. $options 
  246. ); 
  247.  
  248. $this->field_wrapper_end($field); 
  249.  
  250. /** 
  251. * Output a upload input box. 
  252. * 
  253. * @access public 
  254. * @param array $field 
  255. * @return void 
  256. */ 
  257. public function upload_input($field) { 
  258. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'upload_input'; 
  259. $field['mime'] = isset( $field['mime'] ) ? $field['mime'] : 'image'; 
  260. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  261. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  262. $field['prwidth'] = isset( $field['prwidth'] ) ? $field['prwidth'] : 75; 
  263. $customStyle = isset( $field['value'] ) ? 'display: none;' : ''; 
  264. $placeHolder = ( $field['value'] ) ? '' : 'placeHolder'; 
  265. if($field['mime'] != 'image') $placeHolder = 'placeHolder'; 
  266.  
  267. // Custom attribute handling 
  268. $custom_attributes = array(); 
  269.  
  270. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) 
  271. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  272. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  273.  
  274. $field = $this->field_wrapper_start($field); 
  275.  
  276. printf( 
  277. <span class="dc-wp-fields-uploader"> 
  278. <img id="%s_display" src="%s" width="%d" class="%s" /> 
  279. <input type="text" name="%s" id="%s" style="%s" class="%s" readonly value="%s" %s /> 
  280. <input type="button" class="upload_button button button-secondary" name="%s_button" id="%s_button" value="Upload" /> 
  281. <input type="button" class="remove_button button button-secondary" name="%s_remove_button" id="%s_remove_button" value="Remove" /> 
  282. </span> 
  283. ',  
  284. esc_attr($field['id']),  
  285. esc_attr( $field['value'] ),  
  286. absint( $field['prwidth'] ),  
  287. $placeHolder,  
  288. esc_attr($field['name']),  
  289. esc_attr($field['id']),  
  290. $customStyle,  
  291. esc_attr( $field['class'] ),  
  292. esc_attr( $field['value'] ),  
  293. implode( ' ', $custom_attributes ),  
  294. esc_attr($field['id']),  
  295. esc_attr($field['id']),  
  296. esc_attr($field['id']),  
  297. esc_attr($field['id']) 
  298. ); 
  299.  
  300. $this->field_wrapper_end($field); 
  301.  
  302. /** 
  303. * Output a colorpicker box. 
  304. * 
  305. * @access public 
  306. * @param array $field 
  307. * @return void 
  308. */ 
  309. public function colorpicker_input($field) { 
  310. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'colorpicker'; 
  311. $field['default'] = isset( $field['default'] ) ? $field['default'] : 'fbfbfb'; 
  312. $field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default']; 
  313. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  314.  
  315. $field = $this->field_wrapper_start($field); 
  316.  
  317. printf( 
  318. '<input type="%s" id="%s" name="%s" class="%s" data-default="%s" value="%s" />',  
  319. $field['type'],  
  320. esc_attr($field['id']),  
  321. esc_attr($field['name']),  
  322. esc_attr($field['class']),  
  323. esc_attr($field['default']),  
  324. esc_attr($field['value']) 
  325. ); 
  326.  
  327. $this->field_wrapper_end($field); 
  328.  
  329. /** 
  330. * Output a date input box. 
  331. * 
  332. * @access public 
  333. * @param array $field 
  334. * @return void 
  335. */ 
  336. public function datepicker_input($field) { 
  337. $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; 
  338. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'regular-text'; 
  339. $field['value'] = isset( $field['value'] ) ? $field['value'] : ''; 
  340. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  341. $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text'; 
  342. $field['class'] .= ' dc_datepicker'; 
  343.  
  344. // Custom attribute handling 
  345. $custom_attributes = array(); 
  346.  
  347. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { 
  348. foreach ( $field['custom_attributes'] as $attribute => $value ) 
  349. $custom_attributes[] = 'data-' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  350. } else { 
  351. $custom_attributes[] = 'data-date_format="dd/mm/yy"'; 
  352.  
  353. $field = $this->field_wrapper_start($field); 
  354.  
  355. printf( 
  356. '<input type="%s" id="%s" name="%s" class="%s" value="%s" placeholder="%s" %s />',  
  357. $field['type'],  
  358. esc_attr($field['id']),  
  359. esc_attr($field['name']),  
  360. esc_attr($field['class']),  
  361. esc_attr($field['value']),  
  362. esc_attr($field['placeholder']),  
  363. implode( ' ', $custom_attributes ) 
  364. ); 
  365.  
  366. $this->field_wrapper_end($field); 
  367.  
  368. /** 
  369. * Output a multiinput box. 
  370. * 
  371. * @access public 
  372. * @param array $field 
  373. * @return void 
  374. */ 
  375. public function multi_input($field) { 
  376. $field['class'] = isset( $field['class'] ) ? $field['class'] : ''; 
  377. $field['value'] = isset( $field['value'] ) ? $field['value'] : array(); 
  378. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  379. $field['options'] = isset( $field['options'] ) ? $field['options'] : array(); 
  380. $field['value'] = array_values($field['value']); 
  381.  
  382. $field = $this->field_wrapper_start($field); 
  383.  
  384. printf( 
  385. '<div id="%s" class="%s multi_input_holder" data-name="%s" data-length="%s">',  
  386. $field['id'],  
  387. $field['class'],  
  388. $field['name'],  
  389. count($field['value']) 
  390. ); 
  391.  
  392. $eleCount = count($field['value']); 
  393. if(!$eleCount) $eleCount = 1; 
  394.  
  395.  
  396. if(!empty($field['options'])) { 
  397. for($blockCount = 0; $blockCount < $eleCount; $blockCount++) { 
  398. printf('<div class="multi_input_block">'); 
  399. foreach($field['options'] as $optionKey => $optionField) { 
  400. $optionField = $this->check_field_id_name($optionKey, $optionField); 
  401. if(isset($field['value']) && isset($field['value'][$blockCount]) && isset($field['value'][$blockCount][$optionField['name']])) $optionField['value'] = $field['value'][$blockCount][$optionField['name']]; 
  402. $optionField['custom_attributes']['name'] = $optionField['name']; 
  403. $optionField['class'] .= ' multi_input_block_element'; 
  404. $optionField['id'] = $field['id'] . '_' . $optionField['name'] . '_' . $blockCount; 
  405. $optionField['name'] = $field['name'].'['.$blockCount.']['.$optionField['name'].']'; 
  406. if(!empty($optionField['type'])) { 
  407. switch($optionField['type']) { 
  408. case 'input': 
  409. case 'text': 
  410. case 'email': 
  411. case 'url': 
  412. $this->text_input($optionField); 
  413. break; 
  414.  
  415. case 'hidden': 
  416. $this->hidden_input($optionField); 
  417. break; 
  418.  
  419. case 'textarea': 
  420. $this->textarea_input($optionField); 
  421. break; 
  422.  
  423. case 'wpeditor': 
  424. $this->wpeditor_input($optionField); 
  425. break; 
  426.  
  427. case 'checkbox': 
  428. $this->checkbox_input($optionField); 
  429. break; 
  430.  
  431. case 'radio': 
  432. $this->radio_input($optionField); 
  433. break; 
  434.  
  435. case 'select': 
  436. $this->select_input($optionField); 
  437. break; 
  438.  
  439. case 'upload': 
  440. $this->upload_input($optionField); 
  441. break; 
  442.  
  443. case 'colorpicker': 
  444. $this->colorpicker_input($optionField); 
  445. break; 
  446.  
  447. case 'datepicker': 
  448. $this->datepicker_input($optionField); 
  449. break; 
  450.  
  451. case 'multiinput': 
  452. $this->multi_input($optionField); 
  453. break; 
  454.  
  455. default: 
  456.  
  457. break; 
  458.  
  459. printf('<span class="multi_input_block_manupulate remove_multi_input_block button-secondary">-</span> 
  460. <span class="add_multi_input_block multi_input_block_manupulate button-primary">+</span></div>'); 
  461.  
  462. printf('</div>'); 
  463.  
  464. $this->field_wrapper_end($field); 
  465.  
  466. /**************************************** Help Functions ************************************************/ 
  467.  
  468. public function field_wrapper_start($field) { 
  469. $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? ($field['wrapper_class'] . ' ' . $field['id'] . '_wrapper') : ($field['id'] . '_wrapper'); 
  470. $field['label_holder_class'] = isset( $field['label_holder_class'] ) ? ($field['label_holder_class']. ' ' . $field['id'] . '_label_holder') : ($field['id'] . '_label_holder'); 
  471. $field['label_for'] = isset( $field['label_for'] ) ? ($field['label_for']. ' ' . $field['id']) : $field['id']; 
  472. $field['label_class'] = isset( $field['label_class'] ) ? ($field['label_for']. ' ' . $field['label_class']) : $field['label_for']; 
  473.  
  474. do_action('before_field_wrapper'); 
  475. do_action('before_field_wrapper_' . $field['id']); 
  476.  
  477. if(isset($field['in_table'])) { 
  478. printf( 
  479. '<tr class="%s">',  
  480. $field['wrapper_class'] 
  481. ); 
  482.  
  483. do_action('field_wrapper_start'); 
  484. do_action('field_wrapper_start_' . $field['id']); 
  485.  
  486. if(isset($field['label'])) { 
  487. do_action('before_field_label'); 
  488. do_action('before_field_label_' . $field['id']); 
  489.  
  490. if(isset($field['in_table'])) { 
  491. printf( 
  492. '<th class="%s">',  
  493. $field['label_holder_class'] 
  494. ); 
  495. do_action('field_label_start'); 
  496. do_action('field_label_start_' . $field['id']); 
  497. printf( 
  498. '<p class="%s"><strong>%s</strong>',  
  499. $field['label_class'],  
  500. $field['label'] 
  501. ); 
  502. if(isset($field['hints'])) { 
  503. printf( 
  504. '<span class="img_tip" data-desc="%s"></span>',  
  505. wp_kses_post ( $field['hints'] ) 
  506. ); 
  507. printf( 
  508. '</p><label class="screen-reader-text" for="%s">%s</label>',  
  509. $field['label_for'],  
  510. $field['label'] 
  511. ); 
  512. do_action('field_label_end_' . $field['id']); 
  513. do_action('field_label_end'); 
  514. if(isset($field['in_table'])) printf('</th>'); 
  515.  
  516. do_action('after_field_label_' . $field['id']); 
  517. do_action('after_field_label'); 
  518.  
  519. do_action('before_field'); 
  520. do_action('before_field_' . $field['id']); 
  521.  
  522. if(isset($field['in_table'])) printf('<td>'); 
  523.  
  524. do_action('field_start'); 
  525. do_action('field_start_' . $field['id']); 
  526.  
  527. $field['custom_attributes'] = apply_filters('manupulate_custom_attributes', $field['custom_attributes']); 
  528. $field['custom_attributes'] = apply_filters('manupulate_custom_attributes_' . $field['id'], $field['custom_attributes']); 
  529.  
  530. return $field; 
  531.  
  532. public function field_wrapper_end($field) { 
  533.  
  534. // Help message 
  535. if(!isset($field['label']) && isset($field['hints'])) { 
  536. do_action('before_hints'); 
  537. do_action('before_hints_' . $field['id']); 
  538.  
  539. printf( 
  540. '<span class="img_tip" data-desc="%s"></span>',  
  541. wp_kses_post ( $field['hints'] ) 
  542. ); 
  543.  
  544. do_action('after_hints_' . $field['id']); 
  545. do_action('after_hints'); 
  546.  
  547. // Description 
  548. if(isset($field['desc'])) { 
  549. do_action('before_desc'); 
  550. do_action('before_desc_' . $field['id']); 
  551.  
  552. printf( 
  553. '<p class="description">%s</p>',  
  554. wp_kses_post ( $field['desc'] ) 
  555. ); 
  556.  
  557. do_action('after_desc_' . $field['id']); 
  558. do_action('after_desc'); 
  559.  
  560. do_action('field_end_' . $field['id']); 
  561. do_action('field_end'); 
  562.  
  563. if(isset($field['in_table'])) printf('</td>'); 
  564.  
  565. do_action('after_field_' . $field['id']); 
  566. do_action('after_field'); 
  567.  
  568. do_action('field_wrapper_end_' . $field['id']); 
  569. do_action('field_wrapper_end'); 
  570.  
  571. if(isset($field['in_table'])) printf('</tr>'); 
  572.  
  573. do_action('afet_field_wrapper_' . $field['id']); 
  574. do_action('after_field_wrapper'); 
  575.  
  576. public function dc_generate_form_field($fields, $common_attrs = array()) { 
  577. if(!empty($fields)) { 
  578. foreach($fields as $fieldID => $field) { 
  579. $field = $this->check_field_id_name($fieldID, $field); 
  580. if(!empty($common_attrs))  
  581. foreach($common_attrs as $common_attr_key => $common_attr_val) 
  582. $field[$common_attr_key] = $common_attr_val; 
  583. if(!empty($field['type'])) { 
  584. switch($field['type']) { 
  585. case 'input': 
  586. case 'text': 
  587. case 'email': 
  588. case 'url': 
  589. $this->text_input($field); 
  590. break; 
  591.  
  592. case 'hidden': 
  593. $this->hidden_input($field); 
  594. break; 
  595.  
  596. case 'textarea': 
  597. $this->textarea_input($field); 
  598. break; 
  599.  
  600. case 'wpeditor': 
  601. $this->wpeditor_input($field); 
  602. break; 
  603.  
  604. case 'checkbox': 
  605. $this->checkbox_input($field); 
  606. break; 
  607.  
  608. case 'radio': 
  609. $this->radio_input($field); 
  610. break; 
  611.  
  612. case 'select': 
  613. $this->select_input($field); 
  614. break; 
  615.  
  616. case 'upload': 
  617. $this->upload_input($field); 
  618. break; 
  619.  
  620. case 'colorpicker': 
  621. $this->colorpicker_input($field); 
  622. break; 
  623.  
  624. case 'datepicker': 
  625. $this->datepicker_input($field); 
  626. break; 
  627.  
  628. case 'multiinput': 
  629. $this->multi_input($field); 
  630. break; 
  631.  
  632. default: 
  633.  
  634. break; 
  635.  
  636.  
  637. public function check_field_id_name($fieldID, $field) { 
  638. if(empty($fieldID)) return $field; 
  639.  
  640. if(!isset($field['id']) || empty($field['id'])) $field['id'] = $fieldID; 
  641. if(!isset($field['name']) || empty($field['name'])) $field['name'] = $fieldID; 
  642.  
  643. return $field; 
.