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