class-acf-field-tab.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. if ( ! class_exists( 'acf_field_tab' ) ) :
  3. class acf_field_tab extends acf_field {
  4. public $show_in_rest = false;
  5. /*
  6. * __construct
  7. *
  8. * This function will setup the field type data
  9. *
  10. * @type function
  11. * @date 5/03/2014
  12. * @since 5.0.0
  13. *
  14. * @param n/a
  15. * @return n/a
  16. */
  17. function initialize() {
  18. // vars
  19. $this->name = 'tab';
  20. $this->label = __( 'Tab', 'acf' );
  21. $this->category = 'layout';
  22. $this->defaults = array(
  23. 'placement' => 'top',
  24. 'endpoint' => 0, // added in 5.2.8
  25. );
  26. }
  27. /*
  28. * render_field()
  29. *
  30. * Create the HTML interface for your field
  31. *
  32. * @param $field - an array holding all the field's data
  33. *
  34. * @type action
  35. * @since 3.6
  36. * @date 23/01/13
  37. */
  38. function render_field( $field ) {
  39. // vars
  40. $atts = array(
  41. 'href' => '',
  42. 'class' => 'acf-tab-button',
  43. 'data-placement' => $field['placement'],
  44. 'data-endpoint' => $field['endpoint'],
  45. 'data-key' => $field['key'],
  46. );
  47. if ( isset( $field['settings-type'] ) ) {
  48. $atts['class'] .= ' acf-settings-type-' . acf_slugify( $field['settings-type'] );
  49. }
  50. ?>
  51. <a <?php echo acf_esc_attrs( $atts ); ?>><?php echo acf_esc_html( $field['label'] ); ?></a>
  52. <?php
  53. }
  54. /*
  55. * render_field_settings()
  56. *
  57. * Create extra options for your field. This is rendered when editing a field.
  58. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  59. *
  60. * @param $field - an array holding all the field's data
  61. *
  62. * @type action
  63. * @since 3.6
  64. * @date 23/01/13
  65. */
  66. function render_field_settings( $field ) {
  67. /*
  68. // message
  69. $message = '';
  70. $message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>';
  71. $message .= '<p>' . __( 'All fields following this "tab field" (or until another "tab field" is defined) will be grouped together using this field\'s label as the tab heading.','acf') . '</p>';
  72. // default_value
  73. acf_render_field_setting( $field, array(
  74. 'label' => __('Instructions','acf'),
  75. 'instructions' => '',
  76. 'name' => 'notes',
  77. 'type' => 'message',
  78. 'message' => $message,
  79. ));
  80. */
  81. // preview_size
  82. acf_render_field_setting(
  83. $field,
  84. array(
  85. 'label' => __( 'Placement', 'acf' ),
  86. 'type' => 'select',
  87. 'name' => 'placement',
  88. 'choices' => array(
  89. 'top' => __( 'Top aligned', 'acf' ),
  90. 'left' => __( 'Left aligned', 'acf' ),
  91. ),
  92. )
  93. );
  94. // endpoint
  95. acf_render_field_setting(
  96. $field,
  97. array(
  98. 'label' => __( 'New Tab Group', 'acf' ),
  99. 'instructions' => __( 'Start a new group of tabs at this tab.', 'acf' ),
  100. 'name' => 'endpoint',
  101. 'type' => 'true_false',
  102. 'ui' => 1,
  103. )
  104. );
  105. }
  106. /*
  107. * load_field()
  108. *
  109. * This filter is appied to the $field after it is loaded from the database
  110. *
  111. * @type filter
  112. * @since 3.6
  113. * @date 23/01/13
  114. *
  115. * @param $field - the field array holding all the field options
  116. *
  117. * @return $field - the field array holding all the field options
  118. */
  119. function load_field( $field ) {
  120. // remove name to avoid caching issue
  121. $field['name'] = '';
  122. // remove instructions
  123. $field['instructions'] = '';
  124. // remove required to avoid JS issues
  125. $field['required'] = 0;
  126. // set value other than 'null' to avoid ACF loading / caching issue
  127. $field['value'] = false;
  128. // return
  129. return $field;
  130. }
  131. }
  132. // initialize
  133. acf_register_field_type( 'acf_field_tab' );
  134. endif; // class_exists check
  135. ?>