Version Description
- Reflecting the changes that have been done to the default text widget over the years
Download this release
Release Info
Developer | gagan0123 |
Plugin | Shortcode Widget |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- class-shortcode-widget.php +33 -12
- index.php +2 -2
- readme.txt +7 -3
class-shortcode-widget.php
CHANGED
@@ -6,35 +6,56 @@
|
|
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_TEXT_DOMAIN));
|
11 |
$control_ops = array('width' => 400, 'height' => 350);
|
12 |
parent::__construct('shortcode-widget', __('Shortcode Widget', SHORTCODE_WIDGET_TEXT_DOMAIN), $widget_ops, $control_ops);
|
13 |
}
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
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 ) ) {
|
|
|
|
|
21 |
<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
|
22 |
<?php
|
23 |
-
echo $after_widget;
|
24 |
}
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
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'] =
|
34 |
return $instance;
|
35 |
}
|
36 |
|
37 |
-
|
|
|
|
|
|
|
38 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
|
39 |
$title = strip_tags($instance['title']);
|
40 |
$text = esc_textarea($instance['text']);
|
@@ -42,10 +63,10 @@ class Shortcode_Widget extends WP_Widget {
|
|
42 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', SHORTCODE_WIDGET_TEXT_DOMAIN); ?></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 |
-
<
|
|
|
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); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs', SHORTCODE_WIDGET_TEXT_DOMAIN); ?></label></p>
|
48 |
<?php
|
49 |
}
|
50 |
}
|
51 |
-
?>
|
6 |
*/
|
7 |
class Shortcode_Widget extends WP_Widget {
|
8 |
|
9 |
+
public function __construct() {
|
10 |
+
$widget_ops = array('classname' => 'shortcode_widget', 'description' => __('Shortcode or HTML or Plain Text.', SHORTCODE_WIDGET_TEXT_DOMAIN));
|
11 |
$control_ops = array('width' => 400, 'height' => 350);
|
12 |
parent::__construct('shortcode-widget', __('Shortcode Widget', SHORTCODE_WIDGET_TEXT_DOMAIN), $widget_ops, $control_ops);
|
13 |
}
|
14 |
|
15 |
+
/**
|
16 |
+
* @param array $args
|
17 |
+
* @param array $instance
|
18 |
+
*/
|
19 |
+
public function widget( $args, $instance ) {
|
20 |
+
/** This filter is documented in wp-includes/default-widgets.php */
|
21 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Filter the content of the Text widget.
|
25 |
+
*
|
26 |
+
* @param string $widget_text The widget content.
|
27 |
+
* @param WP_Widget $instance WP_Widget instance.
|
28 |
+
*/
|
29 |
$text = do_shortcode(apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ));
|
30 |
+
echo $args['before_widget'];
|
31 |
+
if ( ! empty( $title ) ) {
|
32 |
+
echo $args['before_title'] . $title . $args['after_title'];
|
33 |
+
} ?>
|
34 |
<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
|
35 |
<?php
|
36 |
+
echo $args['after_widget'];
|
37 |
}
|
38 |
|
39 |
+
/**
|
40 |
+
* @param array $new_instance
|
41 |
+
* @param array $old_instance
|
42 |
+
* @return array
|
43 |
+
*/
|
44 |
+
public function update( $new_instance, $old_instance ) {
|
45 |
$instance = $old_instance;
|
46 |
$instance['title'] = strip_tags($new_instance['title']);
|
47 |
if ( current_user_can('unfiltered_html') )
|
48 |
$instance['text'] = $new_instance['text'];
|
49 |
else
|
50 |
$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
|
51 |
+
$instance['filter'] = ! empty( $new_instance['filter'] );
|
52 |
return $instance;
|
53 |
}
|
54 |
|
55 |
+
/**
|
56 |
+
* @param array $instance
|
57 |
+
*/
|
58 |
+
public function form( $instance ) {
|
59 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
|
60 |
$title = strip_tags($instance['title']);
|
61 |
$text = esc_textarea($instance['text']);
|
63 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', SHORTCODE_WIDGET_TEXT_DOMAIN); ?></label>
|
64 |
<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>
|
65 |
|
66 |
+
<p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
|
67 |
+
<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></p>
|
68 |
|
69 |
<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); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs', SHORTCODE_WIDGET_TEXT_DOMAIN); ?></label></p>
|
70 |
<?php
|
71 |
}
|
72 |
}
|
|
index.php
CHANGED
@@ -3,9 +3,9 @@
|
|
3 |
Plugin Name: Shortcode Widget
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/shortcode-widget/
|
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:
|
7 |
Author URI: http://gagan.pro/
|
8 |
-
Version: 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 |
*/
|
3 |
Plugin Name: Shortcode Widget
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/shortcode-widget/
|
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: Gagan Deep Singh
|
7 |
Author URI: http://gagan.pro/
|
8 |
+
Version: 1.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 |
*/
|
readme.txt
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
=== Shortcode Widget ===
|
2 |
Contributors: gagan0123
|
3 |
Tags: Shortcode, Widget
|
|
|
|
|
4 |
Requires at least: 3.3
|
5 |
Tested up to: 4.0
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -12,8 +14,7 @@ Adds a text-like widget that allows you to write shortcode in it.
|
|
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 |
-
To test the widget you can add the widget and use the shortcode "[shortcode_widget_test]", it will display "It works" on the
|
16 |
-
nd and this will confirm the widget does work.
|
17 |
|
18 |
== Installation ==
|
19 |
|
@@ -35,3 +36,6 @@ nd and this will confirm the widget does work.
|
|
35 |
|
36 |
= 1.0 =
|
37 |
* Tested with WP 4.0
|
|
|
|
|
|
1 |
=== Shortcode Widget ===
|
2 |
Contributors: gagan0123
|
3 |
Tags: Shortcode, Widget
|
4 |
+
Requires at least: 3.1
|
5 |
+
Tested up to: 4.2.2
|
6 |
Requires at least: 3.3
|
7 |
Tested up to: 4.0
|
8 |
+
Stable tag: 1.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
14 |
== Description ==
|
15 |
|
16 |
Adds a text-like widget that allows you to write shortcode in it. (Just whats missing in the default text widget)
|
17 |
+
To test the widget you can add the widget and use the shortcode "[shortcode_widget_test]", it will display "It works" on the frontend and this will confirm the widget does work.
|
|
|
18 |
|
19 |
== Installation ==
|
20 |
|
36 |
|
37 |
= 1.0 =
|
38 |
* Tested with WP 4.0
|
39 |
+
|
40 |
+
= 1.1 =
|
41 |
+
* Reflecting the changes that have been done to the default text widget over the years
|