wp-china-yes/framework/fields/gallery/gallery.php
2025-01-02 10:36:40 +08:00

52 lines
1.7 KiB
PHP
Executable file

<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: gallery
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'WP_CHINA_YES_Field_gallery' ) ) {
class WP_CHINA_YES_Field_gallery extends WP_CHINA_YES_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'add_title' => esc_html__( 'Add Gallery', 'wp_china_yes' ),
'edit_title' => esc_html__( 'Edit Gallery', 'wp_china_yes' ),
'clear_title' => esc_html__( 'Clear', 'wp_china_yes' ),
) );
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
echo $this->field_before();
echo '<ul>';
if ( ! empty( $this->value ) ) {
$values = explode( ',', $this->value );
foreach ( $values as $id ) {
$attachment = wp_get_attachment_image_src( $id, 'thumbnail' );
echo '<li><img src="'. esc_url( $attachment[0] ) .'" /></li>';
}
}
echo '</ul>';
echo '<a href="#" class="button button-primary wp_china_yes-button">'. $args['add_title'] .'</a>';
echo '<a href="#" class="button wp_china_yes-edit-gallery'. esc_attr( $hidden ) .'">'. $args['edit_title'] .'</a>';
echo '<a href="#" class="button wp_china_yes-warning-primary wp_china_yes-clear-gallery'. esc_attr( $hidden ) .'">'. $args['clear_title'] .'</a>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
echo $this->field_after();
}
}
}