<?php
/*
Theme Designed By: Meysam Hosseinkhani
Email: Meysam98@Gmail.com
Author Website: Hosseinkhani.ir
*/
   // Exit if accessed directly
   if (!defined('ABSPATH')) {
    exit;
}

class Logo_Namad_widget extends WP_Widget {
      public function __construct() {
         $widget_ops = array('classname' => 'logo-namad_widget', 'description' => 'نمایش لوگو ساماندهی و اینماد' );
         parent::__construct('logo-namad', 'نمادهای سایت (آذین فایل)', $widget_ops);
         $this->alt_option_name = 'logo-namad_widget';
      }
      function widget($args, $instance) {
        extract( $args );
            $title = apply_filters( 'widget_title', empty($instance['title']) ? 'نمادهای سایت' : $instance['title'], $instance, $this->id_base); 
            $logo_one = $instance['logo_one'];
            $logo_two = $instance['logo_two'];
            echo $before_widget;
   			// Widget title
   			echo $before_title;
   			echo $instance["title"];
   			echo $after_title;
   		?>
<div class="row logo-namad" id="logo-namad">
    <?php if($logo_one!='') {echo '<div class="col-6 logo-one">'.$logo_one.'</div>'; }?>
    <?php if($logo_two!='') {echo '<div class="col-6 logo-two">'.$logo_two.'</div>'; }?>
</div>

<?php   echo $after_widget;
   }
   public function update( $new_instance, $old_instance ) {
   $instance = $old_instance;
   $instance['title'] = sanitize_text_field( $new_instance['title'] );
   $instance['logo_one'] = $new_instance['logo_one'];
   $instance['logo_two'] = $new_instance['logo_two'];
   return $instance;
   }
   public function form( $instance ) {
   $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   $logo_one     = isset( $instance['logo_one'] ) ? $instance['logo_one'] : '';
   $logo_two     = isset( $instance['logo_two'] ) ? $instance['logo_two'] : '';
   ?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p><label for="<?php echo $this->get_field_id( 'logo_one' ); ?>"><?php _e( 'لوگو اول:' ); ?></label>
    <textarea class="widefat code" rows="5" cols="20" id="<?php echo $this->get_field_id( 'logo_one' ); ?>" name="<?php echo $this->get_field_name( 'logo_one' ); ?>"><?php echo $logo_one; ?></textarea>
</p>
<p><label for="<?php echo $this->get_field_id( 'logo_two' ); ?>"><?php _e( 'لوگو دوم:' ); ?></label>
    <textarea class="widefat code" rows="5" cols="20" id="<?php echo $this->get_field_id( 'logo_two' ); ?>" name="<?php echo $this->get_field_name( 'logo_two' ); ?>"><?php echo $logo_two; ?></textarea>
</p>
<?php
   }
   }
   // register LOGO SLIDER Widget
   add_action( 'widgets_init', function() {return register_widget("Logo_Namad_widget");} );
      