1
0

gallery.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: gallery
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_gallery' ) ) {
  11. class CSF_Field_gallery 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. $args = wp_parse_args( $this->field, array(
  17. 'add_title' => esc_html__( 'Add Gallery', 'sakurairo_csf' ),
  18. 'edit_title' => esc_html__( 'Edit Gallery', 'sakurairo_csf' ),
  19. 'clear_title' => esc_html__( 'Clear', 'sakurairo_csf' ),
  20. ) );
  21. $hidden = ( empty( $this->value ) ) ? ' hidden' : '';
  22. echo $this->field_before();
  23. echo '<ul>';
  24. if ( ! empty( $this->value ) ) {
  25. $values = explode( ',', $this->value );
  26. foreach ( $values as $id ) {
  27. $attachment = wp_get_attachment_image_src( $id, 'thumbnail' );
  28. echo '<li><img src="'. esc_url( $attachment[0] ) .'" /></li>';
  29. }
  30. }
  31. echo '</ul>';
  32. echo '<a href="#" class="button button-primary csf-button">'. $args['add_title'] .'</a>';
  33. echo '<a href="#" class="button csf-edit-gallery'. esc_attr( $hidden ) .'">'. $args['edit_title'] .'</a>';
  34. echo '<a href="#" class="button csf-warning-primary csf-clear-gallery'. esc_attr( $hidden ) .'">'. $args['clear_title'] .'</a>';
  35. echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
  36. echo $this->field_after();
  37. }
  38. }
  39. }