accordion.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: accordion
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_accordion' ) ) {
  11. class CSF_Field_accordion extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $unallows = array( 'accordion' );
  17. echo $this->field_before();
  18. echo '<div class="csf-accordion-items" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
  19. foreach ( $this->field['accordions'] as $key => $accordion ) {
  20. echo '<div class="csf-accordion-item">';
  21. $icon = ( ! empty( $accordion['icon'] ) ) ? 'csf--icon '. $accordion['icon'] : 'csf-accordion-icon fas fa-angle-right';
  22. echo '<h4 class="csf-accordion-title">';
  23. echo '<i class="'. esc_attr( $icon ) .'"></i>';
  24. echo esc_html( $accordion['title'] );
  25. echo '</h4>';
  26. echo '<div class="csf-accordion-content">';
  27. foreach ( $accordion['fields'] as $field ) {
  28. if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
  29. $field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
  30. $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
  31. $field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
  32. $unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
  33. Sakurairo_CSF::field( $field, $field_value, $unique_id, 'field/accordion' );
  34. }
  35. echo '</div>';
  36. echo '</div>';
  37. }
  38. echo '</div>';
  39. echo $this->field_after();
  40. }
  41. }
  42. }