| 1 |
<?php |
| 2 |
|
| 3 |
class WP_Widget_Taboola extends WP_Widget { |
| 4 |
|
| 5 |
function __construct() { |
| 6 |
$widget_ops = array('classname' => 'widget_taboola', 'description' => __( "A taboola widget for your site.") ); |
| 7 |
parent::__construct( 'taboola', _x( 'Taboola Widget', 'Taboola Widget' ), $widget_ops ); |
| 8 |
$this->plugin_directory = plugin_dir_path(__FILE__); |
| 9 |
} |
| 10 |
|
| 11 |
function widget( $args, $instance ) { |
| 12 |
if (trim($instance['widget_id']) == ''){ |
| 13 |
return; |
| 14 |
} |
| 15 |
extract($args); |
| 16 |
|
| 17 |
/** This filter is documented in wp-includes/default-widgets.php */ |
| 18 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
| 19 |
|
| 20 |
$widget_id = ! empty( $instance['widget_id'] ) ? $instance['widget_id'] : ''; |
| 21 |
$placement = ! empty( $instance['placement'] ) ? $instance['placement'] : ''; |
| 22 |
|
| 23 |
echo $before_widget; |
| 24 |
|
| 25 |
if ( $title ) |
| 26 |
echo $before_title . $title . $after_title; |
| 27 |
|
| 28 |
//widget content |
| 29 |
$script2_content = str_replace('{{WIDGET_ID}}', $widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); |
| 30 |
$script2_content = str_replace('{{CONTAINER}}', $this->id, $script2_content); |
| 31 |
$script2_content = str_replace('{{PLACEMENT}}', $placement, $script2_content); |
| 32 |
echo '<script type="text/javascript">'.$script2_content.'</script>'; |
| 33 |
|
| 34 |
echo $after_widget; |
| 35 |
} |
| 36 |
|
| 37 |
function form( $instance ) { |
| 38 |
$instance = wp_parse_args( (array) $instance ); |
| 39 |
$widget_id = esc_attr( $instance['widget_id'] ); |
| 40 |
$placement = esc_attr( $instance['placement'] ); |
| 41 |
?> |
| 42 |
<p> |
| 43 |
<label for="<?php echo $this->get_field_id('widget_id'); ?>"><?php _e('Widget ID:'); ?> |
| 44 |
<input class="widefat" id="<?php echo $this->get_field_id('widget_id'); ?>" name="<?php echo $this->get_field_name('widget_id'); ?>" type="text" value="<?php echo esc_attr($widget_id); ?>" /> |
| 45 |
</label> |
| 46 |
</p> |
| 47 |
<p> |
| 48 |
<label for="<?php echo $this->get_field_id('placement'); ?>"><?php _e('Placement:'); ?> |
| 49 |
<input class="widefat" id="<?php echo $this->get_field_id('placement'); ?>" name="<?php echo $this->get_field_name('placement'); ?>" type="text" value="<?php echo esc_attr($placement); ?>" /> |
| 50 |
</label> |
| 51 |
</p> |
| 52 |
<?php |
| 53 |
} |
| 54 |
|
| 55 |
function update( $new_instance, $old_instance ) { |
| 56 |
$instance = $old_instance; |
| 57 |
$instance['widget_id'] = strip_tags($new_instance['widget_id']); |
| 58 |
$instance['placement'] = strip_tags($new_instance['placement']); |
| 59 |
|
| 60 |
return $instance; |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|