| 1 |
<?php |
| 2 |
add_action('widgets_init', 'osc_ebsp_content_widget'); |
| 3 |
|
| 4 |
function osc_ebsp_content_widget() { |
| 5 |
register_widget('Ebs_Custom_Widget'); |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class Ebs_Custom_Widget extends WP_Widget { |
| 11 |
|
| 12 |
function Ebs_Custom_Widget() { |
| 13 |
$widget_ops = array('classname' => 'ebs_custom_widget', 'description' => __('EBS widget to show EBS/other shortcodes in sidebar.','ebs')); |
| 14 |
|
| 15 |
$control_ops = array('id_base' => 'ebsp-widget'); |
| 16 |
|
| 17 |
$this->WP_Widget('ebsp-widget', __('EBS Shortcode Compiler','ebs'), $widget_ops, $control_ops); |
| 18 |
} |
| 19 |
|
| 20 |
function widget($args, $instance) { |
| 21 |
extract($args); |
| 22 |
|
| 23 |
$title = apply_filters('widget_title', $instance['title']); |
| 24 |
$ebs_content = $instance['ebs_content']; |
| 25 |
|
| 26 |
|
| 27 |
echo $before_widget; |
| 28 |
|
| 29 |
if ($title) { |
| 30 |
echo $before_title . $title . $after_title; |
| 31 |
} |
| 32 |
|
| 33 |
if ($ebs_content) { |
| 34 |
|
| 35 |
?> |
| 36 |
<div class="ebs_widget_content"> |
| 37 |
<?php echo do_shortcode($ebs_content);?> |
| 38 |
</div> |
| 39 |
<div class="clear"></div> |
| 40 |
<?php |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
echo $after_widget; |
| 46 |
} |
| 47 |
|
| 48 |
function update($new_instance, $old_instance) { |
| 49 |
$instance = $old_instance; |
| 50 |
|
| 51 |
$instance['title'] = strip_tags($new_instance['title']); |
| 52 |
$instance['ebs_content'] = $new_instance['ebs_content']; |
| 53 |
|
| 54 |
|
| 55 |
return $instance; |
| 56 |
} |
| 57 |
|
| 58 |
function form($instance) { |
| 59 |
$defaults = array('title' => 'EBS Shortcode', 'ebs_content' => ''); |
| 60 |
$instance = wp_parse_args((array) $instance, $defaults); |
| 61 |
?> |
| 62 |
|
| 63 |
<p> |
| 64 |
<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label> |
| 65 |
<input class="osc_ebs_input" style=" width: 100%; display: block;" id="<?php echo $this->get_field_id('title'); ?>" type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" /> |
| 66 |
</p> |
| 67 |
|
| 68 |
<p> |
| 69 |
<label for="<?php echo $this->get_field_id('ebs_content'); ?>">Shortcode:</label> |
| 70 |
<textarea class="osc_ebs_input" style=" height: 250px; |
| 71 |
width: 100%; display: block;" id="<?php echo $this->get_field_id('ebs_content'); ?>" name="<?php echo $this->get_field_name('ebs_content'); ?>" ><?php echo $instance['ebs_content']; ?></textarea> |
| 72 |
</p> |
| 73 |
|
| 74 |
|
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
?> |