class-acf-field-accordion.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. if ( ! class_exists( 'acf_field__accordion' ) ) :
  3. class acf_field__accordion extends acf_field {
  4. public $show_in_rest = false;
  5. /**
  6. * initialize
  7. *
  8. * This function will setup the field type data
  9. *
  10. * @date 30/10/17
  11. * @since 5.6.3
  12. *
  13. * @param n/a
  14. * @return n/a
  15. */
  16. function initialize() {
  17. // vars
  18. $this->name = 'accordion';
  19. $this->label = __( 'Accordion', 'acf' );
  20. $this->category = 'layout';
  21. $this->defaults = array(
  22. 'open' => 0,
  23. 'multi_expand' => 0,
  24. 'endpoint' => 0,
  25. );
  26. }
  27. /**
  28. * render_field
  29. *
  30. * Create the HTML interface for your field
  31. *
  32. * @date 30/10/17
  33. * @since 5.6.3
  34. *
  35. * @param array $field
  36. * @return n/a
  37. */
  38. function render_field( $field ) {
  39. // vars
  40. $atts = array(
  41. 'class' => 'acf-fields',
  42. 'data-open' => $field['open'],
  43. 'data-multi_expand' => $field['multi_expand'],
  44. 'data-endpoint' => $field['endpoint'],
  45. );
  46. ?>
  47. <div <?php echo acf_esc_attrs( $atts ); ?>></div>
  48. <?php
  49. }
  50. /*
  51. * render_field_settings()
  52. *
  53. * Create extra options for your field. This is rendered when editing a field.
  54. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  55. *
  56. * @param $field - an array holding all the field's data
  57. *
  58. * @type action
  59. * @since 3.6
  60. * @date 23/01/13
  61. */
  62. function render_field_settings( $field ) {
  63. acf_render_field_setting(
  64. $field,
  65. array(
  66. 'label' => __( 'Open', 'acf' ),
  67. 'instructions' => __( 'Display this accordion as open on page load.', 'acf' ),
  68. 'name' => 'open',
  69. 'type' => 'true_false',
  70. 'ui' => 1,
  71. )
  72. );
  73. acf_render_field_setting(
  74. $field,
  75. array(
  76. 'label' => __( 'Multi-expand', 'acf' ),
  77. 'instructions' => __( 'Allow this accordion to open without closing others.', 'acf' ),
  78. 'name' => 'multi_expand',
  79. 'type' => 'true_false',
  80. 'ui' => 1,
  81. )
  82. );
  83. acf_render_field_setting(
  84. $field,
  85. array(
  86. 'label' => __( 'Endpoint', 'acf' ),
  87. 'instructions' => __( 'Define an endpoint for the previous accordion to stop. This accordion will not be visible.', 'acf' ),
  88. 'name' => 'endpoint',
  89. 'type' => 'true_false',
  90. 'ui' => 1,
  91. )
  92. );
  93. }
  94. /*
  95. * load_field()
  96. *
  97. * This filter is appied to the $field after it is loaded from the database
  98. *
  99. * @type filter
  100. * @since 3.6
  101. * @date 23/01/13
  102. *
  103. * @param $field - the field array holding all the field options
  104. *
  105. * @return $field - the field array holding all the field options
  106. */
  107. function load_field( $field ) {
  108. // remove name to avoid caching issue
  109. $field['name'] = '';
  110. // remove required to avoid JS issues
  111. $field['required'] = 0;
  112. // set value other than 'null' to avoid ACF loading / caching issue
  113. $field['value'] = false;
  114. // return
  115. return $field;
  116. }
  117. }
  118. // initialize
  119. acf_register_field_type( 'acf_field__accordion' );
  120. endif; // class_exists check
  121. ?>