value)) { return $images; } $images = explode(',', $this->value); return $images; } /** * Returns an array that holds the field data, suitable for JSON representation. * This data will be available in the Underscore template and the Backbone Model. * * @since 0.8 * @param bool $load Should the value be loaded from the database or use the value from the current instance. * @return array */ public function to_json($load) { $field_data = parent::to_json($load); $images = array(); $image_values = $this->get_images(); if(!empty($image_values)) { foreach ($image_values as $image_value) { $image_url = is_numeric($image_value) ? wp_get_attachment_url($image_value) : $image_value; $file_type = wp_check_filetype($image_url); $file_type = preg_replace( '~\/.+$~', '', $file_type['type']); // image, video, etc.. if ($file_type == 'image') { if ($this->value_type == 'id') { $image_src = wp_get_attachment_image_src($image_value, 'thumbnail'); $image_url = $image_src[0]; } $images[] = array( 'value' => $image_value, 'url' => $image_url, ); } } } $field_data = wp_parse_args(array( 'images' => $images, 'button_label' => $this->button_label, 'window_button_label' => $this->window_button_label, 'window_label' => $this->window_label, 'type_filter' => $this->field_type, 'value_type' => $this->value_type, 'value' => $this->value, ), $field_data); return $field_data; } /** * Underscore template of the image gallery section. * * @since 0.8 */ public function template() { ?>
{{{ button_label }}}
{{{ description }}}