acf_field_row

The Advanced Custom Fields: Row Field acf field row class.

Defined (2)

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

/acf-row-v4.php  
  1. class acf_field_row extends acf_field 
  2.  
  3. var $settings; 
  4.  
  5.  
  6. /** 
  7. * __construct 
  8. * Set name / label needed for actions / filters 
  9. * @since 3.6 
  10. * @date 23/01/13 
  11. */ 
  12.  
  13. function __construct() 
  14. // vars 
  15. $this->name = 'row'; 
  16. $this->label = __("Row", 'acf-row'); 
  17. $this->category = __("Layout", 'acf-row'); 
  18. $this->defaults = array( 
  19. 'col_num' => 2,  
  20. 'row_type' => 'row_open',  
  21. ); 
  22.  
  23. // do not delete! 
  24. parent::__construct(); 
  25.  
  26.  
  27. // settings 
  28. $this->settings = array( 
  29. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  30. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  31. 'version' => '1.0.0' 
  32. ); 
  33.  
  34.  
  35. function input_admin_enqueue_scripts() 
  36. // register acf scripts 
  37. wp_register_style( 'acf-input-row', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] ); 
  38. wp_register_script( 'acf-input-row', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] ); 
  39.  
  40.  
  41. // scripts 
  42. wp_enqueue_script(array( 
  43. 'acf-input-row',  
  44. )); 
  45.  
  46. // styles 
  47. wp_enqueue_style(array( 
  48. 'acf-input-row',  
  49. )); 
  50.  
  51.  
  52.  
  53. function create_options( $field ) 
  54. // defaults? 
  55.  
  56. $field = array_merge($this->defaults, $field); 
  57.  
  58.  
  59. // key is needed in the field names to correctly save the data 
  60. $key = $field['name']; 
  61.  
  62.  
  63. // Create Field Options HTML 
  64. ?> 
  65. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  66. <td class="label"> 
  67. <label><?php _e("Type", 'acf-row'); ?></label> 
  68. </td> 
  69. <td> 
  70. <?php 
  71.  
  72. do_action('acf/create_field', array( 
  73. 'type' => 'radio',  
  74. 'name' => 'fields['.$key.'][row_type]',  
  75. 'value' => $field['row_type'],  
  76. 'layout' => 'horizontal',  
  77. 'choices' => array( 
  78. 'row_open' => __('Row Open', 'acf-row'),  
  79. 'row_close' => __('Row Close', 'acf-row'),  
  80. )); 
  81.  
  82. ?> 
  83. </td> 
  84. </tr> 
  85. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  86. <td class="label"> 
  87. <label><?php _e("Column", 'acf-row'); ?></label> 
  88. </td> 
  89. <td> 
  90. <?php 
  91.  
  92. do_action('acf/create_field', array( 
  93. 'type' => 'radio',  
  94. 'name' => 'fields['.$key.'][col_num]',  
  95. 'value' => $field['col_num'],  
  96. 'layout' => 'horizontal',  
  97. 'choices' => array( 
  98. '2' => __('2'),  
  99. '3' => __('3'),  
  100. '4' => __('4'),  
  101. )); 
  102.  
  103. ?> 
  104. </td> 
  105. </tr> 
  106. <?php 
  107.  
  108.  
  109.  
  110. function create_field( $field ) 
  111.  
  112. echo '<div class="acf-row" data-row_type="'.$field['row_type'].'" data-col_num="'.$field['col_num'].'">' . $field['label'] . '</div>'; 
  113.  
  114.  
  115.  
/acf-row-v5.php  
  1. class acf_field_row 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 = 'row'; 
  21.  
  22.  
  23. /** 
  24. * label (string) Multiple words, can include spaces, visible when selecting a field type 
  25. */ 
  26.  
  27. $this->label = __('Row', 'acf-row'); 
  28.  
  29.  
  30. /** 
  31. * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME 
  32. */ 
  33.  
  34. $this->category = 'layout'; 
  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.  
  43. 'col_num' => 2,  
  44. 'row_type' => 'row_open',  
  45.  
  46. ); 
  47.  
  48.  
  49. /** 
  50. * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via: 
  51. * var message = acf._e('row', 'error'); 
  52. */ 
  53.  
  54. $this->l10n = array( 
  55. // 'error' => __('Error! Please enter a higher value', 'acf-row'),  
  56. ); 
  57.  
  58.  
  59. // do not delete! 
  60. parent::__construct(); 
  61.  
  62.  
  63.  
  64. /** 
  65. * render_field_settings() 
  66. * Create extra settings for your field. These are visible when editing a field 
  67. * @type action 
  68. * @since 3.6 
  69. * @date 23/01/13 
  70. * @param $field (array) the $field being edited 
  71. * @return n/a 
  72. */ 
  73.  
  74. function render_field_settings( $field ) { 
  75.  
  76. /** 
  77. * acf_render_field_setting 
  78. * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 
  79. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 
  80. * More than one setting can be added by copy/paste the above code. 
  81. * Please note that you must also have a matching $defaults value for the field name (font_size) 
  82. */ 
  83.  
  84. acf_render_field_setting( $field, array( 
  85. 'label' => __('Type', 'acf-row'),  
  86. 'instructions' => __('Choose Type', 'acf-row'),  
  87. 'type' => 'radio',  
  88. 'name' => 'row_type',  
  89. 'layout' => 'horizontal',  
  90. 'choices' => array( 
  91. 'row_open' => __('Row Open', 'acf-row'),  
  92. 'row_close' => __('Row Close', 'acf-row'),  
  93. )); 
  94. acf_render_field_setting( $field, array( 
  95. 'label' => __('Column', 'acf-row'),  
  96. 'instructions' => __('Choose Column', 'acf-row'),  
  97. 'type' => 'radio',  
  98. 'name' => 'col_num',  
  99. 'layout' => 'horizontal',  
  100. 'choices' => array( 
  101. '2' => __('2'),  
  102. '3' => __('3'),  
  103. '4' => __('4'),  
  104.  
  105. )); 
  106.  
  107.  
  108.  
  109.  
  110.  
  111. /** 
  112. * render_field() 
  113. * Create the HTML interface for your field 
  114. * @param $field (array) the $field being rendered 
  115. * @type action 
  116. * @since 3.6 
  117. * @date 23/01/13 
  118. * @param $field (array) the $field being edited 
  119. * @return n/a 
  120. */ 
  121.  
  122. function render_field( $field ) { 
  123.  
  124.  
  125. /** 
  126. * Review the data of $field. 
  127. * This will show what data is available 
  128. */ 
  129.  
  130. echo '<div class="acf-row" data-row_type="'.$field['row_type'].'" data-col_num="'.$field['col_num'].'">' . $field['label'] . '</div>'; 
  131.  
  132.  
  133.  
  134.  
  135.  
  136. /** 
  137. * input_admin_enqueue_scripts() 
  138. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  139. * Use this action to add CSS + JavaScript to assist your render_field() action. 
  140. * @type action (admin_enqueue_scripts) 
  141. * @since 3.6 
  142. * @date 23/01/13 
  143. * @param n/a 
  144. * @return n/a 
  145. */ 
  146.  
  147.  
  148.  
  149. function input_admin_enqueue_scripts() { 
  150.  
  151. $dir = plugin_dir_url( __FILE__ ); 
  152.  
  153.  
  154. // register & include JS 
  155. wp_register_script( 'acf-input-row', "{$dir}js/input.js" ); 
  156. wp_enqueue_script('acf-input-row'); 
  157.  
  158.  
  159. // register & include CSS 
  160. wp_register_style( 'acf-input-row', "{$dir}css/input.css" ); 
  161. wp_enqueue_style('acf-input-row'); 
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. /** 
  169. * input_admin_head() 
  170. * This action is called in the admin_head action on the edit screen where your field is created. 
  171. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  172. * @type action (admin_head) 
  173. * @since 3.6 
  174. * @date 23/01/13 
  175. * @param n/a 
  176. * @return n/a 
  177. */ 
  178.  
  179. /** 
  180.   
  181. function input_admin_head() { 
  182.   
  183.   
  184.   
  185.   
  186. */ 
  187.  
  188.  
  189. /** 
  190. * input_form_data() 
  191. * This function is called once on the 'input' page between the head and footer 
  192. * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and 
  193. * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 
  194. * seen on comments / user edit forms on the front end. This function will always be called, and includes 
  195. * $args that related to the current screen such as $args['post_id'] 
  196. * @type function 
  197. * @date 6/03/2014 
  198. * @since 5.0.0 
  199. * @param $args (array) 
  200. * @return n/a 
  201. */ 
  202.  
  203. /** 
  204.   
  205. function input_form_data( $args ) { 
  206.   
  207.   
  208.   
  209.   
  210. */ 
  211.  
  212.  
  213. /** 
  214. * input_admin_footer() 
  215. * This action is called in the admin_footer action on the edit screen where your field is created. 
  216. * Use this action to add CSS and JavaScript to assist your render_field() action. 
  217. * @type action (admin_footer) 
  218. * @since 3.6 
  219. * @date 23/01/13 
  220. * @param n/a 
  221. * @return n/a 
  222. */ 
  223.  
  224. /** 
  225.   
  226. function input_admin_footer() { 
  227.   
  228.   
  229.   
  230.   
  231. */ 
  232.  
  233.  
  234. /** 
  235. * field_group_admin_enqueue_scripts() 
  236. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  237. * Use this action to add CSS + JavaScript to assist your render_field_options() action. 
  238. * @type action (admin_enqueue_scripts) 
  239. * @since 3.6 
  240. * @date 23/01/13 
  241. * @param n/a 
  242. * @return n/a 
  243. */ 
  244.  
  245. /** 
  246.   
  247. function field_group_admin_enqueue_scripts() { 
  248.   
  249.   
  250. */ 
  251.  
  252.  
  253. /** 
  254. * field_group_admin_head() 
  255. * This action is called in the admin_head action on the edit screen where your field is edited. 
  256. * Use this action to add CSS and JavaScript to assist your render_field_options() action. 
  257. * @type action (admin_head) 
  258. * @since 3.6 
  259. * @date 23/01/13 
  260. * @param n/a 
  261. * @return n/a 
  262. */ 
  263.  
  264. /** 
  265.   
  266. function field_group_admin_head() { 
  267.   
  268.   
  269. */ 
  270.  
  271.  
  272. /** 
  273. * load_value() 
  274. * This filter is applied to the $value after it is loaded from the db 
  275. * @type filter 
  276. * @since 3.6 
  277. * @date 23/01/13 
  278. * @param $value (mixed) the value found in the database 
  279. * @param $post_id (mixed) the $post_id from which the value was loaded 
  280. * @param $field (array) the field array holding all the field options 
  281. * @return $value 
  282. */ 
  283.  
  284. /** 
  285.   
  286. function load_value( $value, $post_id, $field ) { 
  287.   
  288. return $value; 
  289.   
  290.   
  291. */ 
  292.  
  293.  
  294. /** 
  295. * update_value() 
  296. * This filter is applied to the $value before it is saved in the db 
  297. * @type filter 
  298. * @since 3.6 
  299. * @date 23/01/13 
  300. * @param $value (mixed) the value found in the database 
  301. * @param $post_id (mixed) the $post_id from which the value was loaded 
  302. * @param $field (array) the field array holding all the field options 
  303. * @return $value 
  304. */ 
  305.  
  306. /** 
  307.   
  308. function update_value( $value, $post_id, $field ) { 
  309.   
  310. return $value; 
  311.   
  312.   
  313. */ 
  314.  
  315.  
  316. /** 
  317. * format_value() 
  318. * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 
  319. * @type filter 
  320. * @since 3.6 
  321. * @date 23/01/13 
  322. * @param $value (mixed) the value which was loaded from the database 
  323. * @param $post_id (mixed) the $post_id from which the value was loaded 
  324. * @param $field (array) the field array holding all the field options 
  325. * @return $value (mixed) the modified value 
  326. */ 
  327.  
  328. /** 
  329.   
  330. function format_value( $value, $post_id, $field ) { 
  331.   
  332. // bail early if no value 
  333. if( empty($value) ) { 
  334.   
  335. return $value; 
  336.   
  337.   
  338.   
  339. // apply setting 
  340. if( $field['font_size'] > 12 ) { 
  341.   
  342. // format the value 
  343. // $value = 'something'; 
  344.   
  345.   
  346.   
  347. // return 
  348. return $value; 
  349.   
  350. */ 
  351.  
  352.  
  353. /** 
  354. * validate_value() 
  355. * This filter is used to perform validation on the value prior to saving. 
  356. * All values are validated regardless of the field's required setting. This allows you to validate and return 
  357. * messages to the user if the value is not correct 
  358. * @type filter 
  359. * @date 11/02/2014 
  360. * @since 5.0.0 
  361. * @param $valid (boolean) validation status based on the value and the field's required setting 
  362. * @param $value (mixed) the $_POST value 
  363. * @param $field (array) the field array holding all the field options 
  364. * @param $input (string) the corresponding input name for $_POST value 
  365. * @return $valid 
  366. */ 
  367.  
  368. /** 
  369.   
  370. function validate_value( $valid, $value, $field, $input ) { 
  371.   
  372. // Basic usage 
  373. if( $value < $field['custom_minimum_setting'] ) 
  374. $valid = false; 
  375.   
  376.   
  377. // Advanced usage 
  378. if( $value < $field['custom_minimum_setting'] ) 
  379. $valid = __('The value is too little!', 'acf-row'),  
  380.   
  381.   
  382. // return 
  383. return $valid; 
  384.   
  385.   
  386. */ 
  387.  
  388.  
  389. /** 
  390. * delete_value() 
  391. * This action is fired after a value has been deleted from the db. 
  392. * Please note that saving a blank value is treated as an update, not a delete 
  393. * @type action 
  394. * @date 6/03/2014 
  395. * @since 5.0.0 
  396. * @param $post_id (mixed) the $post_id from which the value was deleted 
  397. * @param $key (string) the $meta_key which the value was deleted 
  398. * @return n/a 
  399. */ 
  400.  
  401. /** 
  402.   
  403. function delete_value( $post_id, $key ) { 
  404.   
  405.   
  406.   
  407.   
  408. */ 
  409.  
  410.  
  411. /** 
  412. * load_field() 
  413. * This filter is applied to the $field after it is loaded from the database 
  414. * @type filter 
  415. * @date 23/01/2013 
  416. * @since 3.6.0 
  417. * @param $field (array) the field array holding all the field options 
  418. * @return $field 
  419. */ 
  420.  
  421. /** 
  422.   
  423. function load_field( $field ) { 
  424.   
  425. return $field; 
  426.   
  427.   
  428. */ 
  429.  
  430.  
  431. /** 
  432. * update_field() 
  433. * This filter is applied to the $field before it is saved to the database 
  434. * @type filter 
  435. * @date 23/01/2013 
  436. * @since 3.6.0 
  437. * @param $field (array) the field array holding all the field options 
  438. * @return $field 
  439. */ 
  440.  
  441. /** 
  442.   
  443. function update_field( $field ) { 
  444.   
  445. return $field; 
  446.   
  447.   
  448. */ 
  449.  
  450.  
  451. /** 
  452. * delete_field() 
  453. * This action is fired after a field is deleted from the database 
  454. * @type action 
  455. * @date 11/02/2014 
  456. * @since 5.0.0 
  457. * @param $field (array) the field array holding all the field options 
  458. * @return n/a 
  459. */ 
  460.  
  461. /** 
  462.   
  463. function delete_field( $field ) { 
  464.   
  465.   
  466.   
  467.   
  468. */ 
  469.  
  470.