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