Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

shortcode text

class WP_Widget_Junkasia_Text_Widget extends WP_Widget {

	public function __construct() {

		parent::__construct(
			'junkasia_text_widget',
			__( 'Text Widget', 'junkasia' ),
			array(
				'description' => __( 'Shortcode or Text Content', 'junkasia' ),
				'classname'   => 'widget_text',
			)
		);

	}

	public function widget( $args, $instance ) {

		$title  = apply_filters( 'widget_title',  empty( $instance['generatewp_title']  ) ? '' : $instance['generatewp_title'],  $instance, $this->id_base );
		$content = apply_filters( 'widget_oembed', empty( $instance['generatewp_oembed'] ) ? '' : $instance['generatewp_oembed'], $instance );
		
		// Before widget tag
		echo $args['before_widget'];
		
		// Title
		if ( ! empty( $title ) ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}
		
		// Embedded Content
		echo '<div class="oembed_widget">' . wp_oembed_get( $oembed, array( 'width' => 250 ) ) . '</div>';
		
		// After widget tag
		echo $args['after_widget'];

	}

	public function form( $instance ) {

		// Set default values
		$instance = wp_parse_args( (array) $instance, array( 
			'junkasia_title' => '',
			'junkasia_content' => '',
		) );

		// Retrieve an existing value from the database
		$junkasia_title = !empty( $instance['junkasia_title'] ) ? $instance['junkasia_title'] : '';
		$junkasia_content = !empty( $instance['junkasia_content'] ) ? $instance['junkasia_content'] : '';

		// Form fields
		echo '<p>';
		echo '	<label for="' . $this->get_field_id( 'junkasia_title' ) . '" class="junkasia_title_label">' . __( 'Title', 'junkasia' ) . '</label>';
		echo '	<input type="text" id="' . $this->get_field_id( 'junkasia_title' ) . '" name="' . $this->get_field_name( 'junkasia_title' ) . '" class="widefat" placeholder="' . esc_attr__( '', 'junkasia' ) . '" value="' . esc_attr( $junkasia_title ) . '">';
		echo '</p>';

		echo '<p>';
		echo '	<label for="' . $this->get_field_id( 'junkasia_content' ) . '" class="junkasia_content_label">' . __( 'Content', 'junkasia' ) . '</label>';
		echo '	<textarea id="' . $this->get_field_id( 'junkasia_content' ) . '" name="' . $this->get_field_name( 'junkasia_content' ) . '" class="widefat" placeholder="' . esc_attr__( '', 'junkasia' ) . '">' . $junkasia_content . '</textarea>';
		echo '	<span class="description">' . __( 'Shortcode or html or text', 'junkasia' ) . '</span>';
		echo '</p>';

	}

	public function update( $new_instance, $old_instance ) {

		$instance = $old_instance;

		$instance['junkasia_title'] = !empty( $new_instance['junkasia_title'] ) ? strip_tags( $new_instance['junkasia_title'] ) : '';
		$instance['junkasia_content'] = !empty( $new_instance['junkasia_content'] ) ? strip_tags( $new_instance['junkasia_content'] ) : '';

		return $instance;

	}

}

function junkasia_register_widgets() {
	register_widget( 'WP_Widget_Junkasia_Text_Widget' );
}
add_action( 'widgets_init', 'junkasia_register_widgets' );