Skip to content

Instantly share code, notes, and snippets.

@crumina
Created September 9, 2013 14:22
Show Gist options
  • Save crumina/6496278 to your computer and use it in GitHub Desktop.
Save crumina/6496278 to your computer and use it in GitHub Desktop.
Siteorigin widget gallery fix
class SiteOrigin_Panels_Widgets_Gallery extends WP_Widget {
function __construct() {
parent::__construct(
'siteorigin-panels-gallery',
__( 'Gallery (PB)', 'so-panels' ),
array(
'description' => __( 'Displays a gallery.', 'so-panels' ),
)
);
}
function widget( $args, $instance ) {
echo $args['before_widget'];
$shortcode_attr = array();
foreach($instance as $k => $v){
if(empty($v)) continue;
$shortcode_attr[] = $k.'="'.esc_attr($v).'"';
}
echo do_shortcode('[gallery '.implode(' ', $shortcode_attr).' link="file"]');
echo $args['after_widget'];
}
function update( $new, $old ) {
return $new;
}
function form( $instance ) {
global $_wp_additional_image_sizes;
$types = apply_filters('siteorigin_panels_gallery_types', array());
$instance = wp_parse_args($instance, array(
'ids' => '',
'image_size' => apply_filters('siteorigin_panels_gallery_default_size', ''),
'type' => apply_filters('siteorigin_panels_gallery_default_type', ''),
'columns' => 3,
'link' => 'file'
));
?>
<p>
<label for="<?php echo $this->get_field_id( 'ids' ) ?>"><?php _e( 'Gallery Images', 'so-panels' ) ?></label>
<a href="#" onclick="return false;" class="so-gallery-widget-select-attachments show-in-panels hidden"><?php _e('edit gallery', 'so-panels') ?></a>
<input type="text" class="widefat" value="<?php echo esc_attr($instance['ids']) ?>" name="<?php echo $this->get_field_name('ids') ?>" />
</p>
<p class="description">
<?php _e("Comma separated attachment IDs. Defaults to all current page's attachments.") ?>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'size' ) ?>"><?php _e( 'Image Size', 'so-panels' ) ?></label>
<select name="<?php echo $this->get_field_name( 'size' ) ?>" id="<?php echo $this->get_field_id( 'size' ) ?>">
<option value="" <?php selected(empty($instance['image_size'])) ?>><?php esc_html_e('Default', 'so-panels') ?></option>
<option value="large" <?php selected('large', $instance['image_size']) ?>><?php esc_html_e( 'Large', 'so-panels' ) ?></option>
<option value="medium" <?php selected('medium', $instance['image_size']) ?>><?php esc_html_e( 'Medium', 'so-panels' ) ?></option>
<option value="thumbnail" <?php selected('thumbnail', $instance['image_size']) ?>><?php esc_html_e( 'Thumbnail', 'so-panels' ) ?></option>
<option value="full" <?php selected('full', $instance['image_size']) ?>><?php esc_html_e( 'Full', 'so-panels' ) ?></option>
<?php if(!empty($_wp_additional_image_sizes)) : foreach ( $_wp_additional_image_sizes as $name => $info ) : ?>
<option value="<?php echo esc_attr( $name ) ?>" <?php selected($name, $instance['image_size']) ?>><?php echo esc_html( $name ) ?></option>
<?php endforeach; endif; ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'type' ) ?>"><?php _e( 'Gallery Type', 'so-panels' ) ?></label>
<input type="text" class="regular" value="<?php echo esc_attr($instance['type']) ?>" name="<?php echo $this->get_field_name('type') ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'columns' ) ?>"><?php _e( 'Columns', 'so-panels' ) ?></label>
<input type="text" class="regular" value="<?php echo esc_attr($instance['columns']) ?>" name="<?php echo $this->get_field_name('columns') ?>" />
</p>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment