/acf-row-v4.php

  1. <?php 
  2.  
  3. class acf_field_row extends acf_field 
  4.  
  5. var $settings; 
  6.  
  7.  
  8. /** 
  9. * __construct 
  10. * 
  11. * Set name / label needed for actions / filters 
  12. * 
  13. * @since 3.6 
  14. * @date 23/01/13 
  15. */ 
  16.  
  17. function __construct() 
  18. // vars 
  19. $this->name = 'row'; 
  20. $this->label = __("Row", 'acf-row'); 
  21. $this->category = __("Layout", 'acf-row'); 
  22. $this->defaults = array( 
  23. 'col_num' => 2,  
  24. 'row_type' => 'row_open',  
  25. ); 
  26.  
  27. // do not delete! 
  28. parent::__construct(); 
  29.  
  30.  
  31. // settings 
  32. $this->settings = array( 
  33. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  34. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  35. 'version' => '1.0.0' 
  36. ); 
  37.  
  38.  
  39. function input_admin_enqueue_scripts() 
  40. // register acf scripts 
  41. wp_register_style( 'acf-input-row', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] ); 
  42. wp_register_script( 'acf-input-row', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] ); 
  43.  
  44.  
  45. // scripts 
  46. wp_enqueue_script(array( 
  47. 'acf-input-row',  
  48. )); 
  49.  
  50. // styles 
  51. wp_enqueue_style(array( 
  52. 'acf-input-row',  
  53. )); 
  54.  
  55.  
  56.  
  57. function create_options( $field ) 
  58. // defaults? 
  59.  
  60. $field = array_merge($this->defaults, $field); 
  61.  
  62.  
  63. // key is needed in the field names to correctly save the data 
  64. $key = $field['name']; 
  65.  
  66.  
  67. // Create Field Options HTML 
  68. ?> 
  69. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  70. <td class="label"> 
  71. <label><?php _e("Type", 'acf-row'); ?></label> 
  72. </td> 
  73. <td> 
  74. <?php 
  75.  
  76. do_action('acf/create_field', array( 
  77. 'type' => 'radio',  
  78. 'name' => 'fields['.$key.'][row_type]',  
  79. 'value' => $field['row_type'],  
  80. 'layout' => 'horizontal',  
  81. 'choices' => array( 
  82. 'row_open' => __('Row Open', 'acf-row'),  
  83. 'row_close' => __('Row Close', 'acf-row'),  
  84. )); 
  85.  
  86. ?> 
  87. </td> 
  88. </tr> 
  89. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  90. <td class="label"> 
  91. <label><?php _e("Column", 'acf-row'); ?></label> 
  92. </td> 
  93. <td> 
  94. <?php 
  95.  
  96. do_action('acf/create_field', array( 
  97. 'type' => 'radio',  
  98. 'name' => 'fields['.$key.'][col_num]',  
  99. 'value' => $field['col_num'],  
  100. 'layout' => 'horizontal',  
  101. 'choices' => array( 
  102. '2' => __('2'),  
  103. '3' => __('3'),  
  104. '4' => __('4'),  
  105. )); 
  106.  
  107. ?> 
  108. </td> 
  109. </tr> 
  110. <?php 
  111.  
  112.  
  113.  
  114. function create_field( $field ) 
  115.  
  116. echo '<div class="acf-row" data-row_type="'.$field['row_type'].'" data-col_num="'.$field['col_num'].'">' . $field['label'] . '</div>'; 
  117.  
  118.  
  119.  
  120.  
  121. new acf_field_row(); 
.