name = esc_html__( 'Property Gallery', 'propertyhive' ); $this->icon = "'"; } public function get_fields() { $fields = array( 'gallery_layout' => array( 'label' => __( 'Layout', 'propertyhive' ), 'type' => 'select', 'options' => [ 'grid' => __( 'Six Images', 'propertyhive' ), 'one_large_four_small' => __( 'One Large Image, Four Small', 'propertyhive' ), ], 'default' => 'grid', 'toggle_slug' => 'main_content', ), 'start_at_image' => array( 'label' => __( 'Start at Image #', 'propertyhive' ), 'type' => 'number', 'toggle_slug' => 'main_content', ), ); return $fields; } public function render( $attrs, $content, $render_slug ) { $post_id = get_the_ID(); $property = new PH_Property($post_id); if ( !isset($property->id) ) { return; } ob_start(); $start_at_image = ( isset($this->props['start_at_image']) && !empty($this->props['start_at_image']) && is_numeric($this->props['start_at_image']) ) ? ($this->props['start_at_image'] - 1) : 0; $images = array(); $images_hidden = array(); if ( get_option('propertyhive_images_stored_as', '') == 'urls' ) { $photo_urls = $property->_photo_urls; if ( !is_array($photo_urls) ) { $photo_urls = array(); } if ( $start_at_image > 0 ) { $photo_urls_hidden = array_slice($photo_urls, 0, $start_at_image); foreach ( $photo_urls_hidden as $photo ) { $images_hidden[] = array( 'title' => isset($photo['title']) ? $photo['title'] : '', 'url' => isset($photo['url']) ? $photo['url'] : '', 'image' => '' . ( isset($photo['title']) ? $photo['title'] : '' ) . '', ); } } $photo_urls = array_slice($photo_urls, $start_at_image); foreach ( $photo_urls as $photo ) { $images[] = array( 'title' => isset($photo['title']) ? $photo['title'] : '', 'url' => isset($photo['url']) ? $photo['url'] : '', 'image' => '' . ( isset($photo['title']) ? $photo['title'] : '' ) . '', ); } } else { $gallery_attachments = $property->get_gallery_attachment_ids(); if ( !empty($gallery_attachments) ) { if ( $start_at_image > 0 ) { $gallery_attachments_hidden = array_slice($gallery_attachments, 0, $start_at_image); foreach ($gallery_attachments_hidden as $gallery_attachment) { $images_hidden[] = array( 'title' => esc_attr( get_the_title( $gallery_attachment ) ), 'url' => wp_get_attachment_url( $gallery_attachment ), 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ), 'attachment_id' => $gallery_attachment, ); } } $gallery_attachments = array_slice($gallery_attachments, $start_at_image); foreach ($gallery_attachments as $gallery_attachment) { $images[] = array( 'title' => esc_attr( get_the_title( $gallery_attachment ) ), 'url' => wp_get_attachment_url( $gallery_attachment ), 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ), 'attachment_id' => $gallery_attachment, ); } } } if ( isset($images) && is_array($images) && !empty($images) ) { $this->props['padding'] = 0; // hardcode to 0 for now. Make an option going forward. ?> '; ++$image_number; } ?> '; ++$image_number; } while ( count($images) > ($image_number) ) { echo ''; ++$image_number; } // Code second layout, for one main photo } ?> _render_module_wrapper( ob_get_clean(), $render_slug ); } }