acf_field_range

The Advanced Custom Fields: Range acf field range class.

Defined (2)

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

/range-v5.php  
  1. class acf_field_range extends acf_field { 
  2.  
  3.  
  4. /** 
  5. * __construct 
  6. * This function will setup the field type data 
  7. * @type function 
  8. * @date 5/03/2014 
  9. * @since 5.0.0 
  10. * @param n/a 
  11. * @return n/a 
  12. */ 
  13.  
  14. function __construct() { 
  15.  
  16. /** 
  17. * name (string) Single word, no spaces. Underscores allowed 
  18. */ 
  19.  
  20. $this->name = 'Range'; 
  21.  
  22.  
  23. /** 
  24. * label (string) Multiple words, can include spaces, visible when selecting a field type 
  25. */ 
  26.  
  27. $this->label = __('Range', 'acf-range'); 
  28.  
  29.  
  30. /** 
  31. * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME 
  32. */ 
  33.  
  34. $this->category = 'jQuery'; 
  35.  
  36.  
  37. /** 
  38. * defaults (array) Array of default settings which are merged into the field object. These are used later in settings 
  39. */ 
  40.  
  41. $this->defaults = array( 
  42. 'font_size' => 14,  
  43. 'slider_type' => 'default',  
  44. 'min' => 0,  
  45. 'max' => 100,  
  46. 'default_value_1' => 0,  
  47. 'default_value_2' => 100,  
  48. 'step' => 1,  
  49. 'title' => __('Range', 'acf'),  
  50. 'separate' => '-',  
  51. 'prepend' => '',  
  52. 'append' => '' 
  53. ); 
  54.  
  55.  
  56. /** 
  57. * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via: 
  58. * var message = acf._e('FIELD_NAME', 'error'); 
  59. */ 
  60.  
  61. $this->l10n = array( 
  62. 'error' => __('Error! Please enter a higher value', 'acf-range'),  
  63. ); 
  64.  
  65.  
  66. // do not delete! 
  67. parent::__construct(); 
  68.  
  69. $this->settings = array( 
  70. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  71. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  72. 'version' => '1.1.2' 
  73. ); 
  74.  
  75.  
  76.  
  77.  
  78. /** 
  79. * render_field_settings() 
  80. * Create extra settings for your field. These are visible when editing a field 
  81. * @type action 
  82. * @since 3.6 
  83. * @date 23/01/13 
  84. * @param $field (array) the $field being edited 
  85. * @return n/a 
  86. */ 
  87.  
  88. function render_field_settings( $field ) { 
  89.  
  90. /** 
  91. * acf_render_field_setting 
  92. * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 
  93. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 
  94. * More than one setting can be added by copy/paste the above code. 
  95. * Please note that you must also have a matching $defaults value for the field name (font_size) 
  96. */ 
  97.  
  98. acf_render_field_setting( $field, array( 
  99. 'label' => __('Type', 'acf-range'),  
  100. 'instructions' => __('Choose the number or slider view', 'acf-range'),  
  101. 'type' => 'radio',  
  102. 'name' => 'slider_type',  
  103. 'choices' => array( 
  104. 'default' => __("Number", 'acf'),  
  105. 'range' => __("Range", 'acf'),  
  106. ),  
  107. 'layout' => 'horizontal',  
  108. )); 
  109.  
  110. acf_render_field_setting( $field, array( 
  111. 'label' => __('Title', 'acf-range'),  
  112. 'instructions' => __('eg. Show extra content before numbers', 'acf-range'),  
  113. 'type' => 'text',  
  114. 'name' => 'title',  
  115. )); 
  116.  
  117. acf_render_field_setting( $field, array( 
  118. 'label' => __('Prepend', 'acf-range'),  
  119. 'instructions' => __('Appears before the number', 'acf-range'),  
  120. 'type' => 'text',  
  121. 'name' => 'prepend',  
  122. )); 
  123.  
  124. acf_render_field_setting( $field, array( 
  125. 'label' => __('Append', 'acf-range'),  
  126. 'instructions' => __('Appears after the number', 'acf-range'),  
  127. 'type' => 'text',  
  128. 'name' => 'append',  
  129. )); 
  130.  
  131. acf_render_field_setting( $field, array( 
  132. 'label' => __('Separate Symbol', 'acf-range'),  
  133. 'instructions' => __('Choose the separator for two values for the Slider view', 'acf-range'),  
  134. 'type' => 'text',  
  135. 'name' => 'separate',  
  136. )); 
  137.  
  138. acf_render_field_setting( $field, array( 
  139. 'label' => __('Default Value #1', 'acf-range'),  
  140. 'instructions' => __('Appears when creating a new post', 'acf-range'),  
  141. 'type' => 'number',  
  142. 'name' => 'default_value_1',  
  143. )); 
  144.  
  145. acf_render_field_setting( $field, array( 
  146. 'label' => __('Default Value #2', 'acf-range'),  
  147. 'instructions' => __('Appears when creating a new post for the Slider view', 'acf-range'),  
  148. 'type' => 'number',  
  149. 'name' => 'default_value_2',  
  150. )); 
  151.  
  152. acf_render_field_setting( $field, array( 
  153. 'label' => __('Minimum value', 'acf-range'),  
  154. 'type' => 'number',  
  155. 'name' => 'min',  
  156. )); 
  157.  
  158. acf_render_field_setting( $field, array( 
  159. 'label' => __('Maximum Value', 'acf-range'),  
  160. 'type' => 'number',  
  161. 'name' => 'max',  
  162. )); 
  163.  
  164. acf_render_field_setting( $field, array( 
  165. 'label' => __('Step size', 'acf-range'),  
  166. 'type' => 'number',  
  167. 'name' => 'step',  
  168. )); 
  169.  
  170.  
  171.  
  172.  
  173. /** 
  174. * render_field() 
  175. * Create the HTML interface for your field 
  176. * @param $field (array) the $field being rendered 
  177. * @type action 
  178. * @since 3.6 
  179. * @date 23/01/13 
  180. * @param $field (array) the $field being edited 
  181. * @return n/a 
  182. */ 
  183.  
  184. function render_field( $field ) { 
  185.  
  186. // var_dump( $field ); 
  187. /** 
  188. * Review the data of $field. 
  189. * This will show what data is available 
  190. */ 
  191.  
  192. // echo '<pre>'; 
  193. // print_r( $field ); 
  194. // echo '</pre>'; 
  195. $step = $field['step']; 
  196. if(empty($step)) 
  197. $step = 1; 
  198. $slider_type = $field['slider_type']; 
  199. if(empty($slider_type)) 
  200. $slider_type = 'default'; 
  201. $min = $field['min']; 
  202. $max = $field['max']; 
  203. $prepend = $field['prepend']; 
  204. $append = $field['append']; 
  205. $default_value_1 = $field['default_value_1']; 
  206. $default_value_2 = $field['default_value_2']; 
  207. $value = $field['value']; 
  208.  
  209. $title = ''; 
  210. if(!empty($field['title'])) { 
  211. $title = '<span class="am_range_amount_title"> '.$field['title'].' </span>'; 
  212.  
  213. $separate = ''; 
  214. if(!empty($field['separate'])) { 
  215. $separate = ' <span class="am_range_amount_sep">'.$field['separate'].'</span> '; 
  216. $min_cur = $default_value_1; 
  217. $max_cur = $default_value_2; 
  218. if($slider_type=='range') { 
  219. if( isset( $value ) && $value != '') { 
  220. $value_ar = explode(';', $value); 
  221. if(isset($value_ar[0])) { 
  222. $min_cur = $value_ar[0]; 
  223. if(isset($value_ar[1])) { 
  224. $max_cur = $value_ar[1]; 
  225. if($value===false) { 
  226. $value = $min_cur.';'.$max_cur; 
  227. }else{ 
  228. if( isset( $value ) && $value!='') { 
  229. $min_cur = $max_cur = $value; 
  230. if( isset( $value ) && $value===false) { 
  231. $value = $min_cur; 
  232.  
  233. echo '<div class="am_range_amount">'; 
  234.  
  235. if($slider_type=='range') { 
  236. echo '<p>'.$title.$prepend.'<span class="am_range_amount_min"></span>'.$append.$separate.$prepend.'<span class="am_range_amount_max"></span>'.$append.'</p>'; 
  237. }else{ 
  238. echo '<p>'.$title.$prepend.'<span class="am_range_amount_min"></span>'.$append.'</p>'; 
  239.  
  240. echo '<div class="am_range" data-min="' . $min . '" data-max="' . $max . '" data-min-cur="' . $min_cur . '" data-max-cur="' . $max_cur . '" data-step="' . $step . '" data-type="' . $slider_type . '"></div>'; 
  241.  
  242. echo '<input type="hidden" value="' . $value . '" name="' . $field['name'] . '" class="am_range_input" />'; 
  243.  
  244. echo '</div>'; 
  245.  
  246.  
  247.  
  248. /** 
  249. * input_admin_enqueue_scripts() 
  250. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  251. * Use this action to add CSS + JavaScript to assist your render_field() action. 
  252. * @type action (admin_enqueue_scripts) 
  253. * @since 3.6 
  254. * @date 23/01/13 
  255. * @param n/a 
  256. * @return n/a 
  257. */ 
  258.  
  259.  
  260.  
  261. function input_admin_enqueue_scripts() { 
  262.  
  263. $dir = plugin_dir_url( __FILE__ ); 
  264.  
  265.  
  266. wp_register_script('acf-input-range', $dir . 'js/input.js', array('acf-input'), $this->settings['version']); 
  267. wp_register_style('acf-input-range', $dir . 'css/input.css', array('acf-input'), $this->settings['version']); 
  268.  
  269.  
  270. // scripts 
  271. wp_enqueue_script(array( 
  272. 'acf-input-range',  
  273. )); 
  274.  
  275. wp_enqueue_script( 'acf-am-range', $dir . 'js/range.js', array('acf-input-range', 'jquery-ui-slider'), $this->settings['version'], true ); 
  276.  
  277. // styles 
  278. wp_enqueue_style(array( 
  279. 'acf-input-range',  
  280. )); 
  281.  
  282. wp_enqueue_style('acf-am-jquery-ui', $dir . 'css/jquery-ui.css', array(), $this->settings['version']); 
  283.  
  284. wp_enqueue_style('acf-am-range', $dir . 'css/range.css', array('acf-input-range', 'acf-am-jquery-ui'), $this->settings['version']); 
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. /** 
  292. * input_admin_head() 
  293. * This action is called in the admin_head action on the edit screen where your field is created. 
  294. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  295. * @type action (admin_head) 
  296. * @since 3.6 
  297. * @date 23/01/13 
  298. * @param n/a 
  299. * @return n/a 
  300. */ 
  301.  
  302. /** 
  303.  
  304. function input_admin_head() { 
  305.  
  306.  
  307.  
  308.  
  309. */ 
  310.  
  311.  
  312. /** 
  313. * input_form_data() 
  314. * This function is called once on the 'input' page between the head and footer 
  315. * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and  
  316. * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 
  317. * seen on comments / user edit forms on the front end. This function will always be called, and includes 
  318. * $args that related to the current screen such as $args['post_id'] 
  319. * @type function 
  320. * @date 6/03/2014 
  321. * @since 5.0.0 
  322. * @param $args (array) 
  323. * @return n/a 
  324. */ 
  325.  
  326. /** 
  327.  
  328. function input_form_data( $args ) { 
  329.  
  330.  
  331.  
  332.  
  333. */ 
  334.  
  335.  
  336. /** 
  337. * input_admin_footer() 
  338. * This action is called in the admin_footer action on the edit screen where your field is created. 
  339. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  340. * @type action (admin_footer) 
  341. * @since 3.6 
  342. * @date 23/01/13 
  343. * @param n/a 
  344. * @return n/a 
  345. */ 
  346.  
  347. /** 
  348.  
  349. function input_admin_footer() { 
  350.  
  351.  
  352.  
  353.  
  354. */ 
  355.  
  356.  
  357. /** 
  358. * field_group_admin_enqueue_scripts() 
  359. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  360. * Use this action to add CSS + JavaScript to assist your render_field_options() action. 
  361. * @type action (admin_enqueue_scripts) 
  362. * @since 3.6 
  363. * @date 23/01/13 
  364. * @param n/a 
  365. * @return n/a 
  366. */ 
  367.  
  368.  
  369.  
  370. function field_group_admin_enqueue_scripts() { 
  371. wp_enqueue_script( 'acf-range-admin', $this->settings['dir'] . 'js/range-admin.js', array('jquery'), $this->settings['version'], true ); 
  372.  
  373.  
  374.  
  375.  
  376. /** 
  377. * field_group_admin_head() 
  378. * This action is called in the admin_head action on the edit screen where your field is edited. 
  379. * Use this action to add CSS and JavaScript to assist your render_field_options() action. 
  380. * @type action (admin_head) 
  381. * @since 3.6 
  382. * @date 23/01/13 
  383. * @param n/a 
  384. * @return n/a 
  385. */ 
  386.  
  387. /** 
  388.  
  389. function field_group_admin_head() { 
  390.  
  391.  
  392. */ 
  393.  
  394.  
  395. /** 
  396. * load_value() 
  397. * This filter is applied to the $value after it is loaded from the db 
  398. * @type filter 
  399. * @since 3.6 
  400. * @date 23/01/13 
  401. * @param $value (mixed) the value found in the database 
  402. * @param $post_id (mixed) the $post_id from which the value was loaded 
  403. * @param $field (array) the field array holding all the field options 
  404. * @return $value 
  405. */ 
  406.  
  407.  
  408.  
  409. function load_value( $value, $post_id, $field ) { 
  410.  
  411. return $value; 
  412.  
  413.  
  414.  
  415.  
  416.  
  417. /** 
  418. * update_value() 
  419. * This filter is applied to the $value before it is saved in the db 
  420. * @type filter 
  421. * @since 3.6 
  422. * @date 23/01/13 
  423. * @param $value (mixed) the value found in the database 
  424. * @param $post_id (mixed) the $post_id from which the value was loaded 
  425. * @param $field (array) the field array holding all the field options 
  426. * @return $value 
  427. */ 
  428.  
  429.  
  430.  
  431. function update_value( $value, $post_id, $field ) { 
  432.  
  433. return $value; 
  434.  
  435.  
  436.  
  437.  
  438.  
  439. /** 
  440. * format_value() 
  441. * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 
  442. * @type filter 
  443. * @since 3.6 
  444. * @date 23/01/13 
  445. * @param $value (mixed) the value which was loaded from the database 
  446. * @param $post_id (mixed) the $post_id from which the value was loaded 
  447. * @param $field (array) the field array holding all the field options 
  448. * @return $value (mixed) the modified value 
  449. */ 
  450.  
  451.  
  452.  
  453. // function format_value( $value, $post_id, $field ) { 
  454.  
  455. // // bail early if no value 
  456. // if( empty($value) ) { 
  457.  
  458. // return $value; 
  459.  
  460. // } 
  461.  
  462.  
  463. // // apply setting 
  464. // // if( $field['font_size'] > 12 ) {  
  465.  
  466. // // format the value 
  467. // // $value = 'something'; 
  468.  
  469. // // } 
  470.  
  471.  
  472. // // return 
  473. // return $value; 
  474. // } 
  475.  
  476. function format_value($value, $post_id, $field) 
  477. // format value 
  478. if( !$value ) 
  479. return 0; 
  480.  
  481.  
  482. if( $value == 'null' ) 
  483. return 0; 
  484.  
  485. $temp = explode(';', $value); 
  486.  
  487. $value_ar = array('min'=>0, 'max'=>0); 
  488.  
  489. if(isset($temp[0])) { 
  490. $value_ar['min'] = floatval($temp[0]); 
  491. if(isset($temp[1])) { 
  492. $value_ar['max'] = floatval($temp[1]); 
  493. }else{ 
  494. if(isset($temp[0])) { 
  495. $value_ar = floatval($temp[0]); 
  496.  
  497. // return value 
  498. return $value_ar; 
  499.  
  500.  
  501.  
  502.  
  503. /** 
  504. * validate_value() 
  505. * This filter is used to perform validation on the value prior to saving. 
  506. * All values are validated regardless of the field's required setting. This allows you to validate and return 
  507. * messages to the user if the value is not correct 
  508. * @type filter 
  509. * @date 11/02/2014 
  510. * @since 5.0.0 
  511. * @param $valid (boolean) validation status based on the value and the field's required setting 
  512. * @param $value (mixed) the $_POST value 
  513. * @param $field (array) the field array holding all the field options 
  514. * @param $input (string) the corresponding input name for $_POST value 
  515. * @return $valid 
  516. */ 
  517.  
  518. /** 
  519.  
  520. function validate_value( $valid, $value, $field, $input ) { 
  521.  
  522. // Basic usage 
  523. if( $value < $field['custom_minimum_setting'] ) 
  524. $valid = false; 
  525.  
  526.  
  527. // Advanced usage 
  528. if( $value < $field['custom_minimum_setting'] ) 
  529. $valid = __('The value is too little!', 'acf-FIELD_NAME'),  
  530.  
  531.  
  532. // return 
  533. return $valid; 
  534.  
  535.  
  536. */ 
  537.  
  538.  
  539. /** 
  540. * delete_value() 
  541. * This action is fired after a value has been deleted from the db. 
  542. * Please note that saving a blank value is treated as an update, not a delete 
  543. * @type action 
  544. * @date 6/03/2014 
  545. * @since 5.0.0 
  546. * @param $post_id (mixed) the $post_id from which the value was deleted 
  547. * @param $key (string) the $meta_key which the value was deleted 
  548. * @return n/a 
  549. */ 
  550.  
  551. /** 
  552.  
  553. function delete_value( $post_id, $key ) { 
  554.  
  555.  
  556.  
  557.  
  558. */ 
  559.  
  560.  
  561. /** 
  562. * load_field() 
  563. * This filter is applied to the $field after it is loaded from the database 
  564. * @type filter 
  565. * @date 23/01/2013 
  566. * @since 3.6.0  
  567. * @param $field (array) the field array holding all the field options 
  568. * @return $field 
  569. */ 
  570.  
  571.  
  572.  
  573. function load_field( $field ) { 
  574.  
  575. return $field; 
  576.  
  577. }  
  578.  
  579.  
  580.  
  581.  
  582. /** 
  583. * update_field() 
  584. * This filter is applied to the $field before it is saved to the database 
  585. * @type filter 
  586. * @date 23/01/2013 
  587. * @since 3.6.0 
  588. * @param $field (array) the field array holding all the field options 
  589. * @return $field 
  590. */ 
  591.  
  592.  
  593.  
  594. function update_field( $field ) { 
  595.  
  596. return $field; 
  597.  
  598. }  
  599.  
  600.  
  601.  
  602.  
  603. /** 
  604. * delete_field() 
  605. * This action is fired after a field is deleted from the database 
  606. * @type action 
  607. * @date 11/02/2014 
  608. * @since 5.0.0 
  609. * @param $field (array) the field array holding all the field options 
  610. * @return n/a 
  611. */ 
  612.  
  613. /** 
  614.  
  615. function delete_field( $field ) { 
  616.  
  617.  
  618.  
  619. }  
  620.  
  621. */ 
  622.  
  623.  
/range-v4.php  
  1. class acf_field_range extends acf_field 
  2. // vars 
  3. var $settings, // will hold info such as dir / path 
  4. $defaults; // will hold default field options 
  5.  
  6.  
  7. /** 
  8. * __construct 
  9. * Set name / label needed for actions / filters 
  10. * @since 3.6 
  11. * @date 23/01/13 
  12. */ 
  13.  
  14. function __construct() 
  15. // vars 
  16. $this->name = 'range'; 
  17. $this->label = __('Range'); 
  18. $this->category = __("jQuery", 'acf'); // Basic, Content, Choice, etc 
  19. $this->defaults = array( 
  20. 'slider_type' => 'default',  
  21. 'min' => 0,  
  22. 'max' => 100,  
  23. 'default_value_1' => 0,  
  24. 'default_value_2' => 100,  
  25. 'step' => 1,  
  26. 'title' => __('Range', 'acf'),  
  27. 'separate' => '-',  
  28. 'prepend' => '',  
  29. 'append' => '' 
  30. ); 
  31.  
  32.  
  33. // do not delete! 
  34. parent::__construct(); 
  35.  
  36.  
  37. // settings 
  38. $this->settings = array( 
  39. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  40. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  41. 'version' => '1.1.2' 
  42. ); 
  43.  
  44.  
  45.  
  46. /** 
  47. * create_options() 
  48. * Create extra options for your field. This is rendered when editing a field. 
  49. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  50. * @type action 
  51. * @since 3.6 
  52. * @date 23/01/13 
  53. * @param $field - an array holding all the field's data 
  54. */ 
  55.  
  56. function create_options($field) 
  57. // defaults? 
  58. $field = array_merge($this->defaults, $field); 
  59.  
  60.  
  61. // key is needed in the field names to correctly save the data 
  62. $key = $field['name']; 
  63.  
  64.  
  65. // Create Field Options HTML 
  66. ?> 
  67. <tr class="field_option field_option_range_type field_option_<?php echo $this->name; ?>"> 
  68. <td class="label"> 
  69. <label><?php _e("Type", 'acf'); ?></label> 
  70. <p class="description"><?php _e('Choose the number or slider view', 'acf'); ?></p> 
  71. </td> 
  72. <td> 
  73. <?php 
  74. do_action('acf/create_field', array( 
  75. 'type' => 'radio',  
  76. 'name' => 'fields[' . $key . '][slider_type]',  
  77. 'choices' => array('default'=>__('Number', 'acf'), 'range'=>__('Range', 'acf')),  
  78. 'value' => $field['slider_type'],  
  79. 'layout' => 'horizontal' 
  80. ) ); 
  81. ?> 
  82. </td> 
  83. </tr> 
  84. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  85. <td class="label"> 
  86. <label><?php _e("Title", 'acf'); ?></label> 
  87. <p class="description"><?php _e('eg. Show extra content before numbers', 'acf'); ?></p> 
  88. </td> 
  89. <td> 
  90. <?php 
  91. do_action('acf/create_field', array( 
  92. 'type' => 'text' 
  93. , 'name' => 'fields[' . $key . '][title]' 
  94. , 'value' => $field['title'] 
  95. ) ); 
  96. ?> 
  97. </td> 
  98. </tr> 
  99. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  100. <td class="label"> 
  101. <label><?php _e("Prepend", 'acf'); ?></label> 
  102. <p class="description"><?php _e('Appears before the number', 'acf'); ?></p> 
  103. </td> 
  104. <td> 
  105. <?php 
  106. do_action('acf/create_field', array( 
  107. 'type' => 'text' 
  108. , 'name' => 'fields[' . $key . '][prepend]' 
  109. , 'value' => $field['prepend'] 
  110. ) ); 
  111. ?> 
  112. </td> 
  113. </tr> 
  114. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  115. <td class="label"> 
  116. <label><?php _e("Append", 'acf'); ?></label> 
  117. <p class="description"><?php _e('Appears after the number', 'acf'); ?></p> 
  118. </td> 
  119. <td> 
  120. <?php 
  121. do_action('acf/create_field', array( 
  122. 'type' => 'text' 
  123. , 'name' => 'fields[' . $key . '][append]' 
  124. , 'value' => $field['append'] 
  125. ) ); 
  126. ?> 
  127. </td> 
  128. </tr> 
  129. <tr class="field_option field_option_range_separate field_option_<?php echo $this->name; ?>" <?php /**if( $field['slider_type']!='range' ): ?>style="display:none"<?php endif;*/ ?>> 
  130. <td class="label"> 
  131. <label><?php _e("Separate Symbol", 'acf'); ?></label> 
  132. <p class="description"><?php _e('Choose the separator for two values for the Slider view', 'acf'); ?></p> 
  133. </td> 
  134. <td> 
  135. <?php 
  136. do_action('acf/create_field', array( 
  137. 'type' => 'text' 
  138. , 'name' => 'fields[' . $key . '][separate]' 
  139. , 'value' => $field['separate'] 
  140. ) ); 
  141. ?> 
  142. </td> 
  143. </tr> 
  144. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  145. <td class="label"> 
  146. <label><?php _e("Default Value #1", 'acf'); ?></label> 
  147. <p class="description"><?php _e('Appears when creating a new post', 'acf'); ?></p> 
  148. </td> 
  149. <td> 
  150. <?php 
  151. do_action('acf/create_field', array( 
  152. 'type' => 'number' 
  153. , 'name' => 'fields[' . $key . '][default_value_1]' 
  154. , 'value' => $field['default_value_1'] 
  155. ) ); 
  156. ?> 
  157. </td> 
  158. </tr> 
  159. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  160. <td class="label"> 
  161. <label><?php _e("Default Value #2", 'acf'); ?></label> 
  162. <p class="description"><?php _e('Appears when creating a new post for the Slider view', 'acf'); ?></p> 
  163. </td> 
  164. <td> 
  165. <?php 
  166. do_action('acf/create_field', array( 
  167. 'type' => 'number' 
  168. , 'name' => 'fields[' . $key . '][default_value_2]' 
  169. , 'value' => $field['default_value_2'] 
  170. ) ); 
  171. ?> 
  172. </td> 
  173. </tr> 
  174. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  175. <td class="label"> 
  176. <label><?php _e("Minimum Value", 'acf'); ?></label> 
  177. </td> 
  178. <td> 
  179. <?php 
  180. do_action('acf/create_field', array( 
  181. 'type' => 'number' 
  182. , 'name' => 'fields[' . $key . '][min]' 
  183. , 'value' => $field['min'] 
  184. ) ); 
  185. ?> 
  186. </td> 
  187. </tr> 
  188. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  189. <td class="label"> 
  190. <label><?php _e("Maximum Value", 'acf'); ?></label> 
  191. </td> 
  192. <td> 
  193. <?php 
  194. do_action('acf/create_field', array( 
  195. 'type' => 'number' 
  196. , 'name' => 'fields[' . $key . '][max]' 
  197. , 'value' => $field['max'] 
  198. ) ); 
  199. ?> 
  200. </td> 
  201. </tr> 
  202. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  203. <td class="label"> 
  204. <label><?php _e("Step Size", 'acf'); ?></label> 
  205. </td> 
  206. <td> 
  207. <?php 
  208. do_action('acf/create_field', array( 
  209. 'type' => 'number' 
  210. , 'name' => 'fields[' . $key . '][step]' 
  211. , 'value' => $field['step'] 
  212. ) ); 
  213. ?> 
  214. </td> 
  215. </tr> 
  216. <?php 
  217.  
  218.  
  219.  
  220. /** 
  221. * create_field() 
  222. * Create the HTML interface for your field 
  223. * @param $field - an array holding all the field's data 
  224. * @type action 
  225. * @since 3.6 
  226. * @date 23/01/13 
  227. */ 
  228.  
  229. function create_field( $field ) 
  230. // vars 
  231. $field = array_merge($this->defaults, $field); 
  232.  
  233. $step = $field['step']; 
  234. if(empty($step)) 
  235. $step = 1; 
  236. $slider_type = $field['slider_type']; 
  237. if(empty($slider_type)) 
  238. $slider_type = 'default'; 
  239. $min = $field['min']; 
  240. $max = $field['max']; 
  241. $prepend = $field['prepend']; 
  242. $append = $field['append']; 
  243. $default_value_1 = $field['default_value_1']; 
  244. $default_value_2 = $field['default_value_2']; 
  245. $value = $field['value']; 
  246.  
  247. $title = ''; 
  248. if(!empty($field['title'])) { 
  249. $title = '<span class="am_range_amount_title"> '.$field['title'].' </span>'; 
  250.  
  251. $separate = ''; 
  252. if(!empty($field['separate'])) { 
  253. $separate = ' <span class="am_range_amount_sep">'.$field['separate'].'</span> '; 
  254. $min_cur = $default_value_1; 
  255. $max_cur = $default_value_2; 
  256. if($slider_type=='range') { 
  257. if($value!='') { 
  258. $value_ar = explode(';', $value); 
  259. if(isset($value_ar[0])) { 
  260. $min_cur = $value_ar[0]; 
  261. if(isset($value_ar[0])) { 
  262. $max_cur = $value_ar[1]; 
  263. if($value===false) { 
  264. $value = $min_cur.';'.$max_cur; 
  265. }else{ 
  266. if($value!='') { 
  267. $min_cur = $max_cur = $value; 
  268. if($value===false) { 
  269. $value = $min_cur; 
  270.  
  271. echo '<div class="am_range_amount">'; 
  272.  
  273. if($slider_type=='range') { 
  274. echo '<p>'.$title.$prepend.'<span class="am_range_amount_min"></span>'.$append.$separate.$prepend.'<span class="am_range_amount_max"></span>'.$append.'</p>'; 
  275. }else{ 
  276. echo '<p>'.$title.$prepend.'<span class="am_range_amount_min"></span>'.$append.'</p>'; 
  277.  
  278. echo '<div class="am_range" data-min="' . $min . '" data-max="' . $max . '" data-min-cur="' . $min_cur . '" data-max-cur="' . $max_cur . '" data-step="' . $step . '" data-type="' . $slider_type . '"></div>'; 
  279.  
  280. echo '<input type="hidden" value="' . $value . '" name="' . $field['name'] . '" class="am_range_input" />'; 
  281.  
  282. echo '</div>'; 
  283.  
  284.  
  285. /** 
  286. * input_admin_enqueue_scripts() 
  287. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  288. * Use this action to add css + javascript to assist your create_field() action. 
  289. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  290. * @type action 
  291. * @since 3.6 
  292. * @date 23/01/13 
  293. */ 
  294.  
  295. function input_admin_enqueue_scripts() 
  296. // Note: This function can be removed if not used 
  297.  
  298.  
  299. // register acf scripts 
  300. wp_register_script('acf-input-range', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version']); 
  301. wp_register_style('acf-input-range', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version']); 
  302.  
  303.  
  304. // scripts 
  305. wp_enqueue_script(array( 
  306. 'acf-input-range',  
  307. )); 
  308.  
  309. wp_enqueue_script( 'acf-am-range', $this->settings['dir'] . 'js/range.js', array('acf-input-range', 'jquery-ui-slider'), $this->settings['version'], true ); 
  310.  
  311. // styles 
  312. wp_enqueue_style(array( 
  313. 'acf-input-range',  
  314. )); 
  315.  
  316. wp_enqueue_style('acf-am-jquery-ui', $this->settings['dir'] . 'css/jquery-ui.css', array(), $this->settings['version']); 
  317.  
  318. wp_enqueue_style('acf-am-range', $this->settings['dir'] . 'css/range.css', array('acf-input-range', 'acf-am-jquery-ui'), $this->settings['version']); 
  319.  
  320.  
  321.  
  322. /** 
  323. * input_admin_head() 
  324. * This action is called in the admin_head action on the edit screen where your field is created. 
  325. * Use this action to add css and javascript to assist your create_field() action. 
  326. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  327. * @type action 
  328. * @since 3.6 
  329. * @date 23/01/13 
  330. */ 
  331.  
  332. function input_admin_head() 
  333. // Note: This function can be removed if not used 
  334.  
  335.  
  336. /** 
  337. * field_group_admin_enqueue_scripts() 
  338. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  339. * Use this action to add css + javascript to assist your create_field_options() action. 
  340. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  341. * @type action 
  342. * @since 3.6 
  343. * @date 23/01/13 
  344. */ 
  345.  
  346. function field_group_admin_enqueue_scripts() 
  347. // Note: This function can be removed if not used 
  348. wp_enqueue_script( 'acf-range-admin', $this->settings['dir'] . 'js/range-admin.js', array('jquery'), $this->settings['version'], true ); 
  349.  
  350.  
  351. /** 
  352. * field_group_admin_head() 
  353. * This action is called in the admin_head action on the edit screen where your field is edited. 
  354. * Use this action to add css and javascript to assist your create_field_options() action. 
  355. * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  356. * @type action 
  357. * @since 3.6 
  358. * @date 23/01/13 
  359. */ 
  360.  
  361. function field_group_admin_head() 
  362. // Note: This function can be removed if not used 
  363.  
  364.  
  365. /** 
  366. * load_value() 
  367. * This filter is appied to the $value after it is loaded from the db 
  368. * @type filter 
  369. * @since 3.6 
  370. * @date 23/01/13 
  371. * @param $value - the value found in the database 
  372. * @param $post_id - the $post_id from which the value was loaded from 
  373. * @param $field - the field array holding all the field options 
  374. * @return $value - the value to be saved in te database 
  375. */ 
  376.  
  377. function load_value($value, $post_id, $field) 
  378. // Note: This function can be removed if not used 
  379. return $value; 
  380.  
  381.  
  382. /** 
  383. * update_value() 
  384. * This filter is appied to the $value before it is updated in the db 
  385. * @type filter 
  386. * @since 3.6 
  387. * @date 23/01/13 
  388. * @param $value - the value which will be saved in the database 
  389. * @param $post_id - the $post_id of which the value will be saved 
  390. * @param $field - the field array holding all the field options 
  391. * @return $value - the modified value 
  392. */ 
  393.  
  394. function update_value($value, $post_id, $field) 
  395. // Note: This function can be removed if not used 
  396. return $value; 
  397.  
  398.  
  399. /** 
  400. * format_value() 
  401. * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action 
  402. * @type filter 
  403. * @since 3.6 
  404. * @date 23/01/13 
  405. * @param $value - the value which was loaded from the database 
  406. * @param $post_id - the $post_id from which the value was loaded 
  407. * @param $field - the field array holding all the field options 
  408. * @return $value - the modified value 
  409. */ 
  410.  
  411. function format_value($value, $post_id, $field) 
  412. // defaults? 
  413. /** 
  414. $field = array_merge($this->defaults, $field); 
  415. */ 
  416.  
  417. // perhaps use $field['preview_size'] to alter the $value? 
  418.  
  419.  
  420. // Note: This function can be removed if not used 
  421. return $value; 
  422.  
  423.  
  424. /** 
  425. * format_value_for_api() 
  426. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field 
  427. * @type filter 
  428. * @since 3.6 
  429. * @date 23/01/13 
  430. * @param $value - the value which was loaded from the database 
  431. * @param $post_id - the $post_id from which the value was loaded 
  432. * @param $field - the field array holding all the field options 
  433. * @return $value - the modified value 
  434. */ 
  435.  
  436. function format_value_for_api($value, $post_id, $field) 
  437. // format value 
  438. if ( empty($value) ) { 
  439.  
  440. if ( empty($field['default_value_1']) ) { 
  441. $default_value_1 = 0; 
  442. } else { 
  443. $default_value_1 = $field['default_value_1']; 
  444.  
  445. if ( empty($field['default_value_2']) ) { 
  446. $default_value_2 = 0; 
  447. } else { 
  448. $default_value_2 = $field['default_value_2']; 
  449.  
  450. if ( $field['slider_type'] == 'range' ) { 
  451. $value = $default_value_1.';'.$default_value_2; 
  452. } else { 
  453. $value = $default_value_1; 
  454.  
  455. $temp = explode(';', $value); 
  456.  
  457. $value_ar = array('min'=>0, 'max'=>0); 
  458.  
  459. if(isset($temp[0])) { 
  460. $value_ar['min'] = floatval($temp[0]); 
  461. if(isset($temp[1])) { 
  462. $value_ar['max'] = floatval($temp[1]); 
  463. }else{ 
  464. if(isset($temp[0])) { 
  465. $value_ar = floatval($temp[0]); 
  466.  
  467. // return value 
  468. return $value_ar; 
  469.  
  470.  
  471. /** 
  472. * load_field() 
  473. * This filter is appied to the $field after it is loaded from the database 
  474. * @type filter 
  475. * @since 3.6 
  476. * @date 23/01/13 
  477. * @param $field - the field array holding all the field options 
  478. * @return $field - the field array holding all the field options 
  479. */ 
  480.  
  481. function load_field($field) 
  482. // Note: This function can be removed if not used 
  483. return $field; 
  484.  
  485.  
  486. /** 
  487. * update_field() 
  488. * This filter is appied to the $field before it is saved to the database 
  489. * @type filter 
  490. * @since 3.6 
  491. * @date 23/01/13 
  492. * @param $field - the field array holding all the field options 
  493. * @param $post_id - the field group ID (post_type = acf) 
  494. * @return $field - the modified field 
  495. */ 
  496.  
  497. function update_field($field, $post_id) 
  498. // Note: This function can be removed if not used 
  499. return $field; 
  500.  
  501.