<?php
/**
 * Plugin Name: Minicartbag Widget
 * Description: A widget used for displaying Minicartbag.
 * Version: 1.0
 * Author: Fem Khan
 * Author URI: http://www.aivahthemes.com
 *
 */
	// Register Widget
	function minicartbag_widgets() {
		register_widget( 'minicartbag_widget' );
	}

	// Define the Widget as an extension of WP_Widget
	class minicartbag_widget extends WP_Widget {

		function __construct() {

			/* Widget settings. */
			$widget_ops = array(
				'classname'		=> 'minicartbag-wg',
				'description'	=> __( 'Minicartbag widget for sidebar.', 'storeup' ),
			);

			/* Widget control settings. */
			$control_ops = array(
				'width'		=> 300,
				'height'	=> 390,
				'id_base'	=> 'minicartbag_widget',
			);

			/* Create the widget. */
			parent::__construct( 'minicartbag_widget', STOREUP_THEME_NAME . ' - ' . esc_html__( 'Mini Cart Bag' , 'storeup' ), $widget_ops, $control_ops );
		}

		// outputs the content of the widget
		function widget( $args, $instance ) {
			extract( $args );

			$title = $instance['title'];
			echo wp_kses_post( $before_widget );
			if ( $title ) {
				echo wp_kses_post( $before_title . $title . $after_title );
			}

			if ( class_exists( 'woocommerce' ) ) {
				storeup_minicart();
			}
			echo wp_kses_post( $after_widget );
		}

		//processes widget options to be saved
		function update( $new_instance, $old_instance ) {
			$instance = $old_instance;
			/* Strip tags for title and name to remove HTML (important for text inputs). */
			$instance['title'] = strip_tags( $new_instance['title'] );
			return $instance;
		}
		// outputs the options form on admin
		function form( $instance ) {
			$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
			$title = strip_tags( $instance['title'] );
			?>
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id( 'Title' ) ); ?>"><?php _e( 'Title:', 'storeup' ); ?></label>
				<input type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $title ); ?>" style="width:100%;" />
			</p>
		<?php
		}
	}
	/* Add our function to the widgets_init hook. */
	add_action( 'widgets_init', 'minicartbag_widgets' );
?>
