Example #1
0
function wpsight_add_image_sizes()
{
    foreach (wpsight_image_sizes() as $image_size => $v) {
        if ($image_size == 'post-thumbnail') {
            set_post_thumbnail_size($v['size']['w'], $v['size']['h'], $v['crop']);
        } else {
            add_image_size($image_size, $v['size']['w'], $v['size']['h'], $v['crop']);
        }
    }
}
Example #2
0
function wpsight_get_image_size($image_size)
{
    $image_sizes = wpsight_image_sizes();
    return $image_sizes[$image_size];
}
Example #3
0
    function form($instance)
    {
        $defaults = array('remove' => false, 'center' => false, 'link' => false, 'position' => false);
        $instance = wp_parse_args((array) $instance, $defaults);
        $icon = isset($instance['icon']) ? strip_tags($instance['icon']) : false;
        $title = isset($instance['title']) ? strip_tags($instance['title']) : false;
        $image = isset($instance['image']) ? $instance['image'] : false;
        $imageurl = isset($instance['imageurl']) ? $instance['imageurl'] : false;
        $imagewidth = isset($instance['imagewidth']) ? $instance['imagewidth'] : false;
        $title_icon = isset($instance['title_icon']) ? strip_tags($instance['title_icon']) : false;
        $image_link = !empty($instance['image']) ? __('Change image', 'wpsight') : __('Add image', 'wpsight');
        $size = isset($instance['size']) ? $instance['size'] : 'post-thumbnail';
        $align = isset($instance['align']) ? $instance['align'] : 'none';
        $text = isset($instance['text']) ? wp_kses_post($instance['text']) : false;
        $link_space = isset($instance['link_space']) ? strip_tags($instance['link_space']) : false;
        $width = isset($instance['width']) ? $instance['width'] : 'full';
        ?>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('icon');
        ?>
"><?php 
        _e('Icon', 'wpsight');
        ?>
:</label><br />
			<select class="widefat" id="<?php 
        echo $this->get_field_id('icon');
        ?>
" name="<?php 
        echo $this->get_field_name('icon');
        ?>
">
			    <option value=""<?php 
        selected('icon', $icon);
        ?>
><?php 
        _e('none', 'wpsight');
        ?>
</option>
			    <?php 
        foreach (wpsight_bootstrap_icons() as $k) {
            echo '<option value="' . $k . '"' . selected($k, $icon) . '>' . $k . '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'wpsight');
        ?>
:</label><br />
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />	
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('title_icon');
        ?>
"><?php 
        _e('Title Icon', 'wpsight');
        ?>
:</label><br />
			<select class="widefat" id="<?php 
        echo $this->get_field_id('title_icon');
        ?>
" name="<?php 
        echo $this->get_field_name('title_icon');
        ?>
">
			    <option value=""<?php 
        selected('title_icon', $title_icon);
        ?>
><?php 
        _e('none', 'wpsight');
        ?>
</option>
			    <?php 
        foreach (wpsight_bootstrap_icons() as $k) {
            echo '<option value="' . $k . '"' . selected($k, $title_icon) . '>' . $k . '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('image');
        ?>
"><?php 
        _e('Image', 'wpsight');
        ?>
:</label>
		</p>
		<p>
			<?php 
        $media_upload_iframe_src = 'media-upload.php?type=image&widget_id=' . $this->id;
        $image_upload_iframe_src = apply_filters('image_upload_iframe_src', $media_upload_iframe_src);
        ?>
			<a href="<?php 
        echo $image_upload_iframe_src;
        ?>
&TB_iframe=true" id="add_image-<?php 
        echo $this->get_field_id('image');
        ?>
" class="thickbox-image-widget" onClick="set_active_widget('<?php 
        echo $this->id;
        ?>
');return false;"><?php 
        echo $image_link;
        ?>
</a>

			<div id="display-<?php 
        echo $this->get_field_id('image');
        ?>
" class="wpsight-spaces-image<?php 
        if (empty($instance['imageurl'])) {
            echo ' no-image';
        }
        ?>
">
				<?php 
        if ($imageurl) {
            if ($instance['size'] == 'custom') {
                echo "<img src=\"{$imageurl}\" alt=\"{$title}\" />";
            } else {
                echo wp_get_attachment_image($image, 'post-thumbnail');
            }
        }
        ?>
			</div>
			
			<input id="<?php 
        echo $this->get_field_id('image');
        ?>
" name="<?php 
        echo $this->get_field_name('image');
        ?>
" type="hidden" value="<?php 
        echo $image;
        ?>
" />
		</p>
		
		<div id="settings-<?php 
        echo $this->get_field_id('image');
        ?>
" class="<?php 
        if (empty($imageurl)) {
            echo 'no-image';
        }
        ?>
">
		
			<p>
				<input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('remove');
        ?>
" name="<?php 
        echo $this->get_field_name('remove');
        ?>
" <?php 
        checked($instance['remove'], true);
        ?>
 />
				<label for="<?php 
        echo $this->get_field_id('remove');
        ?>
"><?php 
        _e('Remove image', 'wpsight');
        ?>
</label>		
			</p>	
		
			<p>
				<label for="<?php 
        echo $this->get_field_id('size');
        ?>
"><?php 
        _e('Image size', 'wpsight');
        ?>
:</label>
				<select class="widefat" id="<?php 
        echo $this->get_field_id('size');
        ?>
" name="<?php 
        echo $this->get_field_name('size');
        ?>
">
					<option value="custom"<?php 
        selected('custom', $size);
        ?>
><?php 
        _e('custom', 'wpsight');
        ?>
</option>
					<?php 
        foreach (wpsight_image_sizes() as $k => $v) {
            echo '<option value="' . $k . '"' . selected($k, $size) . '>' . $v['label'] . ' (' . $v['size']['w'] . 'x' . $v['size']['h'] . ')</option>';
        }
        ?>
				</select><br />
				<span class="description"<?php 
        if ($size == 'custom') {
            echo ' style="display:none"';
        }
        ?>
><?php 
        _e('Image size is also limited by the box width you select below', 'wpsight');
        ?>
</span>
			</p>
			
			<div <?php 
        if ($size != 'custom') {
            echo ' style="display:none"';
        }
        ?>
>
			
				<p>
					<label for="<?php 
        echo $this->get_field_id('imagewidth');
        ?>
"><?php 
        _e('Image width', 'wpsight');
        ?>
:</label><br />
					<input class="widefat" id="<?php 
        echo $this->get_field_id('imagewidth');
        ?>
" name="<?php 
        echo $this->get_field_name('imagewidth');
        ?>
" type="text" value="<?php 
        echo esc_attr(strip_tags($imagewidth));
        ?>
" onchange="changeImgWidth('<?php 
        echo $this->id;
        ?>
')" />
					<input id="<?php 
        echo $this->get_field_id('height');
        ?>
" name="<?php 
        echo $this->get_field_name('height');
        ?>
" type="hidden" value="<?php 
        echo esc_attr(strip_tags($imagewidth));
        ?>
" onchange="changeImgHeight('<?php 
        echo $this->id;
        ?>
')" />
				</p>
			
			</div>
		
			<p>
				<label for="<?php 
        echo $this->get_field_id('align');
        ?>
"><?php 
        _e('Image align', 'wpsight');
        ?>
:</label>
				<select class="widefat" id="<?php 
        echo $this->get_field_id('align');
        ?>
" name="<?php 
        echo $this->get_field_name('align');
        ?>
">
					<option value="none"<?php 
        selected('none', $align);
        ?>
><?php 
        _e('none', 'wpsight');
        ?>
</option>
					<option value="left"<?php 
        selected('left', $align);
        ?>
><?php 
        _e('left', 'wpsight');
        ?>
</option>
					<option value="right"<?php 
        selected('right', $align);
        ?>
><?php 
        _e('right', 'wpsight');
        ?>
</option>
					<option value="center"<?php 
        selected('center', $align);
        ?>
><?php 
        _e('center', 'wpsight');
        ?>
</option>
				</select>
			</p>
			
			<p>
				<input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('link');
        ?>
" name="<?php 
        echo $this->get_field_name('link');
        ?>
" <?php 
        checked($instance['link'], true);
        ?>
 />
				<label for="<?php 
        echo $this->get_field_id('link');
        ?>
"><?php 
        _e('Link image', 'wpsight');
        ?>
</label><br />
				<span class="description"><?php 
        _e('Click on image opens lightbox', 'wpsight');
        ?>
</span>
			</p>
		
		</div>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('text');
        ?>
"><?php 
        _e('Text', 'wpsight');
        ?>
:</label>
			<textarea class="widefat" rows="10" cols="10" id="<?php 
        echo $this->get_field_id('text');
        ?>
" name="<?php 
        echo $this->get_field_name('text');
        ?>
"><?php 
        echo esc_textarea($text);
        ?>
</textarea><br />
		</p>
		
		<p>
		    <input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('center');
        ?>
" name="<?php 
        echo $this->get_field_name('center');
        ?>
" <?php 
        checked($instance['center'], true);
        ?>
 />
		    <label for="<?php 
        echo $this->get_field_id('center');
        ?>
"><?php 
        _e('Center widget content', 'wpsight');
        ?>
</label>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('link_space');
        ?>
"><?php 
        _e('Link', 'wpsight');
        ?>
:</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('link_space');
        ?>
" name="<?php 
        echo $this->get_field_name('link_space');
        ?>
" type="text" value="<?php 
        echo esc_attr($link_space);
        ?>
" /><br />
			<span class="description"><?php 
        _e('Adds links to title and image (enter a URL or post/page ID)', 'wpsight');
        ?>
</span>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('width');
        ?>
"><?php 
        _e('Width', 'wpsight');
        ?>
:</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('width');
        ?>
" name="<?php 
        echo $this->get_field_name('width');
        ?>
">
				<?php 
        foreach (wpsight_widget_widths() as $k => $v) {
            echo '<option value="' . $k . '"' . selected($k, $width, false) . '>' . $v . '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
		    <input type="checkbox" class="checkbox" id="<?php 
        echo $this->get_field_id('position');
        ?>
" name="<?php 
        echo $this->get_field_name('position');
        ?>
" <?php 
        checked($instance['position'], true);
        ?>
 />
		    <label for="<?php 
        echo $this->get_field_id('position');
        ?>
"><?php 
        _e('First widget', 'wpsight');
        ?>
</label><br />
		    <span class="description"><?php 
        _e('Position of the widget in the row.', 'wpsight');
        ?>
</span>
		</p><?php 
    }
Example #4
0
 function wpsight_meta_box_post_layouts()
 {
     // Post layouts labels
     $labels_layouts = array('image_size_label' => __('Image Size', 'wpsight'), 'image_size_description' => __('Keep in mind that the image size is limited by the layout', 'wpsight'), 'image_align_label' => __('Image Align', 'wpsight'), 'image_align_description' => __('Select your preferred image alignment', 'wpsight'));
     $labels_layouts = apply_filters('wpsight_meta_box_post_layouts_labels', $labels_layouts);
     $layouts = array('sidebar-right' => __('Right sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/sidebar-right.png' . '" class="layout-img" />', 'full-width' => __('No sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/full-width.png' . '" class="layout-img" />', 'sidebar-left' => __('Left sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/sidebar-left.png' . '" class="layout-img" />');
     $layouts = apply_filters('wpsight_meta_box_post_layouts_layouts', $layouts);
     if (empty($layouts)) {
         return;
     }
     // Get image sizes and create select data
     $image_sizes = array();
     foreach (wpsight_image_sizes() as $k => $v) {
         $image_sizes[$k] = $v['label'] . ' (' . $v['size']['w'] . 'x' . $v['size']['h'] . 'px)';
     }
     // Set image aligns
     $image_aligns = array('left' => __('left', 'wpsight'), 'right' => __('right', 'wpsight'), 'none' => __('none', 'wpsight'));
     $image_aligns = apply_filters('wpsight_meta_box_post_layouts_aligns', $image_aligns);
     // Set meta box
     $meta_box = array('id' => 'listing_layout', 'title' => wpsight_listing_layout_options('title'), 'pages' => array('post', 'page'), 'context' => 'normal', 'priority' => 'high', 'fields' => array('layout' => array('name' => wpsight_listing_layout_options('sidebar_label'), 'id' => '_layout', 'type' => 'radio', 'options' => $layouts, 'std' => 'sidebar-right'), 'size' => array('name' => $labels_layouts['image_size_label'], 'id' => '_image_size', 'type' => 'select', 'options' => $image_sizes, 'std' => 'big'), 'align' => array('name' => $labels_layouts['image_align_label'], 'id' => '_image_align', 'type' => 'select', 'options' => $image_aligns, 'std' => wpsight_get_layout_image('align_single'))));
     // Apply filter to array
     $meta_box = apply_filters('wpsight_meta_box_post_layouts', $meta_box);
     return $meta_box;
 }