tabbed.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: tabbed
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_tabbed' ) ) {
  11. class CSF_Field_tabbed 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( 'tabbed' );
  17. echo $this->field_before();
  18. echo '<div class="csf-tabbed-nav" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
  19. foreach ( $this->field['tabs'] as $key => $tab ) {
  20. $tabbed_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="csf--icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';
  21. $tabbed_active = ( empty( $key ) ) ? 'csf-tabbed-active' : '';
  22. echo '<a href="#" class="'. esc_attr( $tabbed_active ) .'"">'. $tabbed_icon . esc_attr( $tab['title'] ) .'</a>';
  23. }
  24. echo '</div>';
  25. echo '<div class="csf-tabbed-contents">';
  26. foreach ( $this->field['tabs'] as $key => $tab ) {
  27. $tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : '';
  28. echo '<div class="csf-tabbed-content'. esc_attr( $tabbed_hidden ) .'">';
  29. foreach ( $tab['fields'] as $field ) {
  30. if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
  31. $field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
  32. $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
  33. $field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
  34. $unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
  35. Sakurairo_CSF::field( $field, $field_value, $unique_id, 'field/tabbed' );
  36. }
  37. echo '</div>';
  38. }
  39. echo '</div>';
  40. echo $this->field_after();
  41. }
  42. }
  43. }