暫無描述

class-acf-field-tab.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. ?>
  48. <a <?php acf_esc_attr_e( $atts ); ?>><?php echo acf_esc_html( $field['label'] ); ?></a>
  49. <?php
  50. }
  51. /*
  52. * render_field_settings()
  53. *
  54. * Create extra options for your field. This is rendered when editing a field.
  55. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  56. *
  57. * @param $field - an array holding all the field's data
  58. *
  59. * @type action
  60. * @since 3.6
  61. * @date 23/01/13
  62. */
  63. function render_field_settings( $field ) {
  64. /*
  65. // message
  66. $message = '';
  67. $message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>';
  68. $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>';
  69. // default_value
  70. acf_render_field_setting( $field, array(
  71. 'label' => __('Instructions','acf'),
  72. 'instructions' => '',
  73. 'name' => 'notes',
  74. 'type' => 'message',
  75. 'message' => $message,
  76. ));
  77. */
  78. // preview_size
  79. acf_render_field_setting(
  80. $field,
  81. array(
  82. 'label' => __( 'Placement', 'acf' ),
  83. 'type' => 'select',
  84. 'name' => 'placement',
  85. 'choices' => array(
  86. 'top' => __( 'Top aligned', 'acf' ),
  87. 'left' => __( 'Left aligned', 'acf' ),
  88. ),
  89. )
  90. );
  91. // endpoint
  92. acf_render_field_setting(
  93. $field,
  94. array(
  95. 'label' => __( 'Endpoint', 'acf' ),
  96. 'instructions' => __( 'Define an endpoint for the previous tabs to stop. This will start a new group of tabs.', 'acf' ),
  97. 'name' => 'endpoint',
  98. 'type' => 'true_false',
  99. 'ui' => 1,
  100. )
  101. );
  102. }
  103. /*
  104. * load_field()
  105. *
  106. * This filter is appied to the $field after it is loaded from the database
  107. *
  108. * @type filter
  109. * @since 3.6
  110. * @date 23/01/13
  111. *
  112. * @param $field - the field array holding all the field options
  113. *
  114. * @return $field - the field array holding all the field options
  115. */
  116. function load_field( $field ) {
  117. // remove name to avoid caching issue
  118. $field['name'] = '';
  119. // remove instructions
  120. $field['instructions'] = '';
  121. // remove required to avoid JS issues
  122. $field['required'] = 0;
  123. // set value other than 'null' to avoid ACF loading / caching issue
  124. $field['value'] = false;
  125. // return
  126. return $field;
  127. }
  128. }
  129. // initialize
  130. acf_register_field_type( 'acf_field_tab' );
  131. endif; // class_exists check
  132. ?>