Shortcode Widget - Version 0.1

Version Description

Download this release

Release Info

Developer gagan0123
Plugin Icon 128x128 Shortcode Widget
Version 0.1
Comparing to
See all releases

Version 0.1

Files changed (3) hide show
  1. class-shortcode-widget.php +51 -0
  2. index.php +20 -0
  3. readme.txt +23 -0
class-shortcode-widget.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shortcode Widget Class
4
+ *
5
+ * @since 0.1
6
+ */
7
+ class Shortcode_Widget extends WP_Widget {
8
+
9
+ function __construct() {
10
+ $widget_ops = array('classname' => 'shortcode_widget', 'description' => __('Shortcode or HTML or Plain Text','shortcode-widget'));
11
+ $control_ops = array('width' => 400, 'height' => 350);
12
+ parent::__construct('shortcode-widget', __('Shortcode Widget','shortcode-widget'), $widget_ops, $control_ops);
13
+ }
14
+
15
+ function widget( $args, $instance ) {
16
+ extract($args);
17
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
18
+ $text = do_shortcode(apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ));
19
+ echo $before_widget;
20
+ if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
21
+ <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
22
+ <?php
23
+ echo $after_widget;
24
+ }
25
+
26
+ function update( $new_instance, $old_instance ) {
27
+ $instance = $old_instance;
28
+ $instance['title'] = strip_tags($new_instance['title']);
29
+ if ( current_user_can('unfiltered_html') )
30
+ $instance['text'] = $new_instance['text'];
31
+ else
32
+ $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
33
+ $instance['filter'] = isset($new_instance['filter']);
34
+ return $instance;
35
+ }
36
+
37
+ function form( $instance ) {
38
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
39
+ $title = strip_tags($instance['title']);
40
+ $text = esc_textarea($instance['text']);
41
+ ?>
42
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','shortcode-widget'); ?></label>
43
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
44
+
45
+ <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
46
+
47
+ <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs','shortcode-widget'); ?></label></p>
48
+ <?php
49
+ }
50
+ }
51
+ ?>
index.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Shortcode Widget
4
+ Plugin URI: http://www.IaMmE.in
5
+ Description: Adds a text-like widget that allows you to write shortcode in it. (Just whats missing in the default text widget)
6
+ Author: gagan0123
7
+ Author URI: http://gagan.pro/
8
+ Version: 0.1
9
+ Text Domain: shortcode-widget
10
+ License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ require_once('class-shortcode-widget.php');
14
+
15
+ function shortcode_widget_init(){
16
+ register_widget('Shortcode_Widget');
17
+ }
18
+ add_action('widgets_init','shortcode_widget_init');
19
+
20
+ ?>
readme.txt ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Shortcode Widget ===
2
+ Contributors: gagan0123
3
+ Tags: Shortcode, Widget
4
+ Requires at least: 3.3
5
+ Tested up to: 3.5
6
+ Stable tag: 0.1
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Adds a text-like widget that allows you to write shortcode in it.
11
+
12
+ == Description ==
13
+
14
+ Adds a text-like widget that allows you to write shortcode in it. (Just whats missing in the default text widget)
15
+
16
+ == Installation ==
17
+
18
+ 1. Add the plugin's folder in the WordPress' plugin directory.
19
+ 1. Activate the plugin.
20
+ 1. You are now ready to use the Shortcode Widget from the Widgets section.
21
+
22
+ == Changelog ==
23
+ 0.1 Added the shortcode widget