'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 ''; echo $after_widget; } function form( $instance ) { $instance = wp_parse_args( (array) $instance ); $widget_id = esc_attr( $instance['widget_id'] ); ?>