class-redux-gallery.php (2555B)
1 <?php 2 /** 3 * Gallery Field. 4 * 5 * @package ReduxFramework/Fields 6 * @author Dovy Paukstys & Kevin Provance (kprovance) 7 * @version 4.0.0 8 */ 9 10 defined( 'ABSPATH' ) || exit; 11 12 // Don't duplicate me! 13 if ( ! class_exists( 'Redux_Gallery', false ) ) { 14 15 /** 16 * Main Redux_gallery class 17 * 18 * @since 3.0.0 19 */ 20 class Redux_Gallery extends Redux_Field { 21 22 /** 23 * Field Render Function. 24 * Takes the vars and outputs the HTML for the field in the settings 25 * 26 * @since 1.0.0 27 * @access public 28 * @return void 29 */ 30 public function render() { 31 echo '<div class="screenshot">'; 32 33 if ( ! empty( $this->value ) ) { 34 $ids = explode( ',', $this->value ); 35 36 foreach ( $ids as $attachment_id ) { 37 $img = wp_get_attachment_image_src( $attachment_id ); 38 $alt = wp_prepare_attachment_for_js( $attachment_id ); 39 $alt = $alt['alt'] ?? ''; 40 41 echo '<a class="of-uploaded-image" href="' . esc_url( $img[0] ) . '">'; 42 echo '<img class="redux-option-image" id="image_' . esc_attr( $this->field['id'] ) . '_' . esc_attr( $attachment_id ) . '" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />'; 43 echo '</a>'; 44 } 45 } 46 47 echo '</div>'; 48 echo '<a href="#" onclick="return false;" id="edit-gallery" class="gallery-attachments button button-primary">' . esc_html__( 'Add/Edit Gallery', 'redux-framework' ) . '</a> '; 49 echo '<a href="#" onclick="return false;" id="clear-gallery" class="gallery-attachments button">' . esc_html__( 'Clear Gallery', 'redux-framework' ) . '</a>'; 50 echo '<input type="hidden" class="gallery_values ' . esc_attr( $this->field['class'] ) . '" value="' . esc_attr( $this->value ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" />'; 51 } 52 53 /** 54 * Enqueue Function. 55 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 56 * 57 * @since 1.0.0 58 * @access public 59 * @return void 60 */ 61 public function enqueue() { 62 63 if ( function_exists( 'wp_enqueue_media' ) ) { 64 wp_enqueue_media(); 65 } else { 66 wp_enqueue_script( 'media-upload' ); 67 wp_enqueue_script( 'thickbox' ); 68 wp_enqueue_style( 'thickbox' ); 69 } 70 71 wp_enqueue_script( 72 'redux-field-gallery-js', 73 Redux_Core::$url . 'inc/fields/gallery/redux-gallery' . Redux_Functions::is_min() . '.js', 74 array( 'jquery', 'redux-js' ), 75 $this->timestamp, 76 true 77 ); 78 } 79 } 80 } 81 82 class_alias( 'Redux_Gallery', 'ReduxFramework_Gallery' );