
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

add_action( 'widgets_init', 'presso_widgets_init_custom_text' );
if ( ! function_exists( 'presso_widgets_init_custom_text' ) ) {
	function presso_widgets_init_custom_text() {
		register_widget( 'Presso__widget_custom_text' );
	}
}

if ( ! class_exists( 'Presso__widget_custom_text' ) ) {
	class Presso__widget_custom_text extends WP_Widget {
		private $default = array(
			'supertitle' => '',
			'title' => '',
			'subtitle' => '',
			'content' => '',
		);

		public function __construct() {
			// widget actual processes
			parent::__construct(
		 		'vw_widget_custom_text', // Base ID
				PRESSO_THEME_NAME.': Custom Text', // Name
				array( 'description' => esc_html__( "Display a custom text in theme's style", 'presso' ) ) // Args
			);
		}

		function widget( $args, $instance ) {
			extract($args);

			$instance['supertitle'] = apply_filters( 'wpml_translate_single_string', $instance['supertitle'], 'Widgets', $this->id.'_supertitle' );
			$instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
			$instance['subtitle'] = apply_filters( 'wpml_translate_single_string', $instance['subtitle'], 'Widgets', $this->id.'_subtitle' );

			$supertitle_html = '';
			if ( ! empty( $instance['supertitle'] ) ) {
				$supertitle_html = '<span class="vw-super-title">'.wp_kses_post( $instance['supertitle'] ).'</span>';
			}

			$title_html = '';
			if ( ! empty( $instance['title'] ) ) {
				$title_html = wp_kses_post( $instance['title'] );
			}

			$subtitle_html = '';
			if ( ! empty( $instance['subtitle'] ) ) {
				$subtitle_html = '<span class="vwspc-section-subtitle">'.wp_kses_post( $instance['subtitle'] ).'</span>';
			}

			echo wp_kses_post( $before_widget );
			if ( $instance['title'] ) echo wp_kses_post( $supertitle_html . $before_title . $title_html . $after_title . $subtitle_html );

			echo '<div>';
			echo do_shortcode( $instance['content'] );
			echo '</div>';

			echo wp_kses_post( $after_widget );
		}

		function update( $new_instance, $old_instance ) {
			$instance = $old_instance;
			$new_instance = wp_parse_args( (array) $new_instance, $this->default );
			$instance['supertitle'] = sanitize_text_field( $new_instance['supertitle'] );
			$instance['title'] = sanitize_text_field( $new_instance['title'] );
			$instance['subtitle'] = sanitize_text_field( $new_instance['subtitle'] );
			$instance['content'] = wp_kses_post( $new_instance['content'] );

			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_supertitle', $instance['supertitle'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_title', $instance['title'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_subtitle', $instance['subtitle'] );

			return $instance;
		}

		function form( $instance ) {
			$instance = wp_parse_args( (array) $instance, $this->default );

			$supertitle = $instance['supertitle'];
			$title = $instance['title'];
			$subtitle = $instance['subtitle'];
			$content = strip_tags( $instance['content'] );
			?>

			<!-- supertitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>"><?php esc_html_e( 'Super-title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('supertitle') ); ?>" type="text" value="<?php echo esc_attr($supertitle); ?>" />
			</p>

			<!-- title -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e( 'Title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
			</p>

			<!-- subtitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>"><?php esc_html_e( 'Subtitle:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('subtitle') ); ?>" type="text" value="<?php echo esc_attr($subtitle); ?>" />
			</p>

			<!-- content -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('content') ); ?>"><?php esc_html_e( 'Content:', 'presso' ); ?></label>
				<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id('content') ); ?>" name="<?php echo esc_attr( $this->get_field_name('content') ); ?>" rows="16" cols="20"><?php echo esc_textarea( $content ); ?></textarea>
			</p>

			<?php
		}
	}
}