# taboola/1.0.1/widget.php

Taboola, version 1.0.1. 78 lines.

- Page: https://pluginprobe.com/plugins/taboola/1.0.1/code/widget.php
- Raw: https://pluginprobe.com/plugins/taboola/1.0.1/raw/widget.php
- Modified: 2014-07-09T12:56:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/taboola/1.0.1/code/widget.php#L10-L20`.

```php
<?php
define ("TABOOLA_WIDGET_BASE_ID","taboola");
class WP_Widget_Taboola extends WP_Widget {

    private static $counter;
    function __construct() {


        $widget_ops = array('classname' => 'widget_taboola', 'description' => __( "A taboola widget for your site.") );
        parent::__construct( TABOOLA_WIDGET_BASE_ID, _x( 'Taboola Widget', 'Taboola Widget' ), $widget_ops );
        $this->plugin_directory = plugin_dir_path(__FILE__);
    }

    function widget( $args, $instance ) {
        if (!isset(WP_Widget_Taboola::$counter)){
            WP_Widget_Taboola::$counter = 1;
        }
        else{
            WP_Widget_Taboola::$counter = WP_Widget_Taboola::$counter + 1;
        }
        if (trim($instance['widget_id']) == ''){
            return;
        }
        extract($args);

        /** This filter is documented in wp-includes/default-widgets.php */
        $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );

        $tmp_id = explode("-",$args["widget_id"]);
        $widget_num = $tmp_id[1];

        $widget_id = ! empty( $instance['widget_id'] ) ? $instance['widget_id'] : '';

        // use the widget container name as the placement, suffix the widget_id to make it unique
        $placement=$args["id"]."-".$widget_num;

        echo $before_widget;

        if ( $title ){
            echo $before_title . $title . $after_title;
        }

        //widget content
        $script2_content = str_replace('{{WIDGET_ID}}', $widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
        $script2_content = str_replace('{{CONTAINER}}', $this->id, $script2_content);
        $script2_content = str_replace('{{PLACEMENT}}', $placement, $script2_content);
        echo '<script type="text/javascript">'.$script2_content.'</script>';

        echo $after_widget;
    }

    function form( $instance ) {
        $instance = wp_parse_args( (array) $instance );
        $widget_id = esc_attr( $instance['widget_id'] );
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('widget_id'); ?>"><?php _e('Widget ID:'); ?>
                <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); ?>" />
            </label>
        </p>
    <?php
    }

    function update( $new_instance, $old_instance ) {

        // canceling save if the field is empty
        if (strip_tags($new_instance['widget_id']) == ""){
            return false;
	    }

        $instance = $old_instance;
        $instance['widget_id'] = strip_tags($new_instance['widget_id']);

        return $instance;
    }

}

```
