Shortcode Widget - Version 1.5.1

Version Description

  • Unescaped title back in the code as escaping it was creating issues with other plugins.
Download this release

Release Info

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

Code changes from version 1.4 to 1.5.1

includes/class-shortcode-widget-plugin.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** If this file is called directly, abort. */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ die;
6
+ }
7
+
8
+ if ( !class_exists( 'Shortcode_Widget_Plugin' ) ) {
9
+
10
+ /**
11
+ * Handles most of the interaction of the plugin with WordPress
12
+ *
13
+ * @since 1.5
14
+ */
15
+ class Shortcode_Widget_Plugin {
16
+
17
+ /**
18
+ * The instance of the class Shortcode_Widget_Plugin
19
+ *
20
+ * @since 1.5
21
+ *
22
+ * @access protected
23
+ *
24
+ * @var Shortcode_Widget_Plugin
25
+ */
26
+ protected static $instance = null;
27
+
28
+ /**
29
+ * Require the necessary files and calls register hooks method.
30
+ *
31
+ * @access public
32
+ *
33
+ * @since 1.5
34
+ */
35
+ public function __construct() {
36
+ /** The main widget class */
37
+ require_once( SHORTCODE_WIDGET_PATH . 'includes/class-shortcode-widget.php');
38
+ $this->register_hooks();
39
+ }
40
+
41
+ /**
42
+ * Returns the current instance of the class, in case some other
43
+ * plugin needs to use its public methods.
44
+ *
45
+ * @since 1.5
46
+ *
47
+ * @access public
48
+ *
49
+ * @return Shortcode_Widget_Plugin Returns the current instance of the class
50
+ */
51
+ public static function get_instance() {
52
+
53
+ // If the single instance hasn't been set, set it now.
54
+ if ( null == self::$instance ) {
55
+ self::$instance = new self;
56
+ }
57
+
58
+ return self::$instance;
59
+ }
60
+
61
+ /**
62
+ * Registers the shortcode and actions required for this plugin.
63
+ *
64
+ * @access public
65
+ *
66
+ * @since 1.5
67
+ *
68
+ * @return void
69
+ */
70
+ public function register_hooks() {
71
+ /** Registering our own little test shortcode */
72
+ add_shortcode( 'shortcode_widget_test', array( $this, 'test_widget' ) );
73
+
74
+ /** Will register the Shortcode_Widget */
75
+ add_action( 'widgets_init', array( $this, 'widget_init' ) );
76
+
77
+ /** Lets load translations */
78
+ add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
79
+ }
80
+
81
+ /**
82
+ * Registers the Shortcode_Widget at widget_init
83
+ *
84
+ * @access public
85
+ *
86
+ * @since 1.5
87
+ *
88
+ * @return void
89
+ */
90
+ public function widget_init() {
91
+ register_widget( 'Shortcode_Widget' );
92
+ }
93
+
94
+ /**
95
+ * Loads the text domain for the plugin.
96
+ *
97
+ * @access public
98
+ *
99
+ * @since 1.5
100
+ *
101
+ * @return void
102
+ */
103
+ function load_text_domain() {
104
+ load_plugin_textdomain( 'shortcode-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
105
+ }
106
+
107
+ /**
108
+ * Returns the output of the test shortcode.
109
+ *
110
+ * @access public
111
+ *
112
+ * @since 1.5
113
+ *
114
+ * @return string Returns a string "It works", or a translated string if
115
+ * available for the language of the WordPress site.
116
+ */
117
+ function test_widget() {
118
+ return __( "It works", 'shortcode-widget' );
119
+ }
120
+
121
+ }
122
+
123
+ /** Initialises an object of this class */
124
+ Shortcode_Widget_Plugin::get_instance();
125
+ }
126
+
includes/class-shortcode-widget.php CHANGED
@@ -1,75 +1,110 @@
1
  <?php
 
 
 
 
2
 
3
- /**
4
- * Shortcode Widget Class
5
- *
6
- * @since 0.1
7
- */
8
- class Shortcode_Widget extends WP_Widget {
9
-
10
- public function __construct() {
11
- $widget_ops = array( 'classname' => 'shortcode_widget', 'description' => __( 'Shortcode or HTML or Plain Text.', 'shortcode-widget' ) );
12
- $control_ops = array( 'width' => 400, 'height' => 350 );
13
- parent::__construct( 'shortcode-widget', __( 'Shortcode Widget', 'shortcode-widget' ), $widget_ops, $control_ops );
14
- }
15
 
16
  /**
17
- * @param array $args
18
- * @param array $instance
 
19
  */
20
- public function widget( $args, $instance ) {
21
- /** This filter is documented in wp-includes/default-widgets.php */
22
- $title = apply_filters( 'widget_title', empty( $instance[ 'title' ] ) ? '' : $instance[ 'title' ], $instance, $this->id_base );
23
 
24
  /**
25
- * Filter the content of the Text widget.
26
- *
27
- * @param string $widget_text The widget content.
28
- * @param WP_Widget $instance WP_Widget instance.
 
29
  */
30
- $text = do_shortcode( apply_filters( 'widget_text', empty( $instance[ 'text' ] ) ? '' : $instance[ 'text' ], $instance ) );
31
- echo $args[ 'before_widget' ];
32
- if ( !empty( $title ) ) {
33
- echo $args[ 'before_title' ] . $title . $args[ 'after_title' ];
34
  }
35
- ?>
36
- <div class="textwidget"><?php echo!empty( $instance[ 'filter' ] ) ? wpautop( $text ) : $text; ?></div>
37
- <?php
38
- echo $args[ 'after_widget' ];
39
- }
40
 
41
- /**
42
- * @param array $new_instance
43
- * @param array $old_instance
44
- * @return array
45
- */
46
- public function update( $new_instance, $old_instance ) {
47
- $instance = $old_instance;
48
- $instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
49
- if ( current_user_can( 'unfiltered_html' ) )
50
- $instance[ 'text' ] = $new_instance[ 'text' ];
51
- else
52
- $instance[ 'text' ] = stripslashes( wp_filter_post_kses( addslashes( $new_instance[ 'text' ] ) ) ); // wp_filter_post_kses() expects slashed
53
- $instance[ 'filter' ] = !empty( $new_instance[ 'filter' ] );
54
- return $instance;
55
- }
 
 
56
 
57
- /**
58
- * @param array $instance
59
- */
60
- public function form( $instance ) {
61
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
62
- $title = strip_tags( $instance[ 'title' ] );
63
- $text = esc_textarea( $instance[ 'text' ] );
64
- ?>
65
- <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'shortcode-widget' ); ?></label>
66
- <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>
 
67
 
68
- <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
69
- <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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- <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>
72
- <?php
73
  }
74
 
75
- }
1
  <?php
2
+ /** If this file is called directly, abort. */
3
+ if ( !defined( 'ABSPATH' ) ) {
4
+ die;
5
+ }
6
 
7
+ if ( !class_exists( 'Shortcode_Widget' ) ) {
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  /**
10
+ * Shortcode Widget Class
11
+ *
12
+ * @since 0.1
13
  */
14
+ class Shortcode_Widget extends WP_Widget {
 
 
15
 
16
  /**
17
+ * Defines this widgets arguments and calls parent class constructor
18
+ *
19
+ * @access public
20
+ *
21
+ * @since 0.1
22
  */
23
+ public function __construct() {
24
+ $widget_ops = array( 'classname' => 'shortcode_widget', 'description' => __( 'Shortcode or HTML or Plain Text.', 'shortcode-widget' ) );
25
+ $control_ops = array( 'width' => 400, 'height' => 350 );
26
+ parent::__construct( 'shortcode-widget', __( 'Shortcode Widget', 'shortcode-widget' ), $widget_ops, $control_ops );
27
  }
 
 
 
 
 
28
 
29
+ /**
30
+ * Echoes the widget content.
31
+ *
32
+ * @access public
33
+ *
34
+ * @since 0.1
35
+ *
36
+ * @param array $args Display arguments including 'before_title', 'after_title',
37
+ * 'before_widget', and 'after_widget'.
38
+ *
39
+ * @param array $instance The settings for the particular instance of the widget.
40
+ *
41
+ * @return void
42
+ */
43
+ public function widget( $args, $instance ) {
44
+ /** This filter is documented in wp-includes/default-widgets.php */
45
+ $title = apply_filters( 'widget_title', empty( $instance[ 'title' ] ) ? '' : $instance[ 'title' ], $instance, $this->id_base );
46
 
47
+ /** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
48
+ $text = do_shortcode( apply_filters( 'widget_text', empty( $instance[ 'text' ] ) ? '' : $instance[ 'text' ], $instance, $this ) );
49
+ echo $args[ 'before_widget' ];
50
+ if ( !empty( $title ) ) {
51
+ echo $args[ 'before_title' ] . $title . $args[ 'after_title' ];
52
+ }
53
+ ?>
54
+ <div class="textwidget"><?php echo!empty( $instance[ 'filter' ] ) ? wpautop( $text ) : $text; ?></div>
55
+ <?php
56
+ echo $args[ 'after_widget' ];
57
+ }
58
 
59
+ /**
60
+ * Updates a particular instance of a widget.
61
+ *
62
+ * @access public
63
+ *
64
+ * @since 0.1
65
+ *
66
+ * @param array $new_instance New settings for this instance as input by the user via
67
+ * WP_Widget::form().
68
+ * @param array $old_instance Old settings for this instance.
69
+ *
70
+ * @return array|false Settings to save or bool false to cancel saving.
71
+ */
72
+ public function update( $new_instance, $old_instance ) {
73
+ $instance = $old_instance;
74
+ $instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
75
+ if ( current_user_can( 'unfiltered_html' ) ) {
76
+ $instance[ 'text' ] = $new_instance[ 'text' ];
77
+ } else {
78
+ $instance[ 'text' ] = stripslashes( wp_filter_post_kses( addslashes( $new_instance[ 'text' ] ) ) ); // wp_filter_post_kses() expects slashed
79
+ }
80
+ $instance[ 'filter' ] = !empty( $new_instance[ 'filter' ] );
81
+ return $instance;
82
+ }
83
+
84
+ /**
85
+ * Outputs the settings update form.
86
+ *
87
+ * @access public
88
+ *
89
+ * @since 0.1
90
+ *
91
+ * @param array $instance Current settings.
92
+ *
93
+ * @return void
94
+ */
95
+ public function form( $instance ) {
96
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
97
+ ?>
98
+ <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'shortcode-widget' ); ?></label>
99
+ <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( $instance[ 'title' ] ); ?>" /></p>
100
+
101
+ <p><label for="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>"><?php esc_html_e( 'Content:', 'shortcode-widget' ); ?></label>
102
+ <textarea class="widefat" rows="16" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"><?php echo esc_textarea( $instance[ 'text' ] ) ?></textarea></p>
103
+
104
+ <p><input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox" <?php checked( isset( $instance[ 'filter' ] ) ? $instance[ 'filter' ] : 0 ); ?> />&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php esc_html_e( 'Automatically add paragraphs', 'shortcode-widget' ); ?></label></p>
105
+ <?php
106
+ }
107
 
 
 
108
  }
109
 
110
+ }
languages/shortcode-widget.pot ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2017 Gagan Deep Singh
2
+ # This file is distributed under the GPLv2.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Shortcode Widget 1.5.1\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shortcode-widget\n"
7
+ "POT-Creation-Date: 2017-09-05 08:56:33+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "Poedit: \n"
15
+ "X-Generator: grunt-wp-i18n1.0.0\n"
16
+
17
+ #: includes/class-shortcode-widget-plugin.php:122
18
+ msgid "It works"
19
+ msgstr ""
20
+
21
+ #: includes/class-shortcode-widget.php:31
22
+ msgid "Shortcode or HTML or Plain Text."
23
+ msgstr ""
24
+
25
+ #. Plugin Name of the plugin/theme
26
+ msgid "Shortcode Widget"
27
+ msgstr ""
28
+
29
+ #: includes/class-shortcode-widget.php:114
30
+ msgid "Title:"
31
+ msgstr ""
32
+
33
+ #: includes/class-shortcode-widget.php:117
34
+ msgid "Content:"
35
+ msgstr ""
36
+
37
+ #: includes/class-shortcode-widget.php:120
38
+ msgid "Automatically add paragraphs"
39
+ msgstr ""
40
+
41
+ #. Plugin URI of the plugin/theme
42
+ msgid "https://wordpress.org/plugins/shortcode-widget/"
43
+ msgstr ""
44
+
45
+ #. Description of the plugin/theme
46
+ msgid ""
47
+ "Adds a text-like widget that allows you to write shortcode in it. (Just "
48
+ "whats missing in the default text widget)"
49
+ msgstr ""
50
+
51
+ #. Author of the plugin/theme
52
+ msgid "Gagan Deep Singh"
53
+ msgstr ""
54
+
55
+ #. Author URI of the plugin/theme
56
+ msgid "https://gagan0123.com"
57
+ msgstr ""
readme.txt CHANGED
@@ -1,9 +1,10 @@
1
  === Shortcode Widget ===
2
  Contributors: gagan0123
 
3
  Tags: Shortcode, Widget
4
  Requires at least: 3.3
5
- Tested up to: 4.8
6
- Stable tag: 1.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -21,22 +22,36 @@ To test the widget you can add the widget and use the shortcode "[shortcode_widg
21
  1. You are now ready to use the Shortcode Widget from the Widgets section.
22
  1. 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.
23
 
 
 
 
 
 
24
  == Changelog ==
25
 
 
 
 
 
 
 
 
 
 
26
  = 1.4 =
27
  * Updated compatibility with WordPress 4.8
28
- * Reversed the order of changelog
29
 
30
  = 1.3 =
31
- * Minor bug fix
32
- * Changed tested up to version number
33
  * Made it translation ready, constant was being used for text domains, silly error, I know :)
34
 
35
  = 1.2 =
36
- * Corrections in text domain and added one more string as translatable
37
 
38
  = 1.1 =
39
- * Reflecting the changes that have been done to the default text widget over the years
40
 
41
  = 1.0 =
42
  * Tested with WP 4.0
@@ -45,7 +60,7 @@ To test the widget you can add the widget and use the shortcode "[shortcode_widg
45
  * Added a shortcode for testing the plugin '[shortcode_widget_test]'
46
 
47
  = 0.2 =
48
- * Added translation support
49
 
50
  = 0.1 =
51
- * Added the shortcode widget
1
  === Shortcode Widget ===
2
  Contributors: gagan0123
3
+ Donate Link: PayPal.me/gagan0123
4
  Tags: Shortcode, Widget
5
  Requires at least: 3.3
6
+ Tested up to: 4.8.1
7
+ Stable tag: 1.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
22
  1. You are now ready to use the Shortcode Widget from the Widgets section.
23
  1. 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.
24
 
25
+ == Screenshots ==
26
+ 1. Shortcode Widget that can be found in Widgets section
27
+ 2. Adding the widget to the sidebar
28
+ 3. Widget with the output of the shortcode
29
+
30
  == Changelog ==
31
 
32
+ = 1.5.1 =
33
+ * Unescaped title back in the code as escaping it was creating issues with other plugins.
34
+
35
+ = 1.5 =
36
+ * Added icon and screenshots.
37
+ * Escaping some values that could have been overridden by the translations.
38
+ * Added pot file for translations.
39
+ * Change in calling of widget_text filter with new parameter that was added in WordPress 4.4.1
40
+
41
  = 1.4 =
42
  * Updated compatibility with WordPress 4.8
43
+ * Reversed the order of changelog.
44
 
45
  = 1.3 =
46
+ * Minor bug fix.
47
+ * Changed tested up to version number.
48
  * Made it translation ready, constant was being used for text domains, silly error, I know :)
49
 
50
  = 1.2 =
51
+ * Corrections in text domain and added one more string as translatable.
52
 
53
  = 1.1 =
54
+ * Reflecting the changes that have been done to the default text widget over the years.
55
 
56
  = 1.0 =
57
  * Tested with WP 4.0
60
  * Added a shortcode for testing the plugin '[shortcode_widget_test]'
61
 
62
  = 0.2 =
63
+ * Added translation support.
64
 
65
  = 0.1 =
66
+ * Added the shortcode widget.
shortcode-widget.php CHANGED
@@ -2,31 +2,31 @@
2
 
3
  /*
4
  Plugin Name: Shortcode Widget
5
- Plugin URI: http://wordpress.org/extend/plugins/shortcode-widget/
6
  Description: Adds a text-like widget that allows you to write shortcode in it. (Just whats missing in the default text widget)
7
- Author: Gagan Deep Singh
8
- Author URI: http://gagan.pro/
9
- Version: 1.4
 
 
10
  Text Domain: shortcode-widget
11
- License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
  */
13
 
14
- require_once('includes/class-shortcode-widget.php');
15
-
16
- function shortcode_widget_init() {
17
- register_widget( 'Shortcode_Widget' );
18
  }
19
 
20
- add_action( 'widgets_init', 'shortcode_widget_init' );
21
-
22
- function shortcode_widget_load_text_domain() {
23
- load_plugin_textdomain( 'shortcode-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 
 
 
24
  }
25
 
26
- add_action( 'plugins_loaded', 'shortcode_widget_load_text_domain' );
 
27
 
28
- add_shortcode( 'shortcode_widget_test', 'shortcode_widget_test_output' );
29
-
30
- function shortcode_widget_test_output( $args ) {
31
- return __( "It works", 'shortcode-widget' );
32
- }
2
 
3
  /*
4
  Plugin Name: Shortcode Widget
5
+ Plugin URI: https://wordpress.org/plugins/shortcode-widget/
6
  Description: Adds a text-like widget that allows you to write shortcode in it. (Just whats missing in the default text widget)
7
+ Version: 1.5.1
8
+ Author: Gagan Deep Singh
9
+ Author URI: https://gagan0123.com
10
+ License: GPLv2
11
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
12
  Text Domain: shortcode-widget
13
+ Domain Path: /languages
14
  */
15
 
16
+ /** If this file is called directly, abort. */
17
+ if ( !defined( 'ABSPATH' ) ) {
18
+ die;
 
19
  }
20
 
21
+ if ( !defined( 'SHORTCODE_WIDGET_PATH' ) ) {
22
+ /**
23
+ * Absolute path of this plugin
24
+ *
25
+ * @since 1.5
26
+ */
27
+ define( 'SHORTCODE_WIDGET_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
28
  }
29
 
30
+ /** Loading the core plugin class */
31
+ require_once SHORTCODE_WIDGET_PATH . 'includes/class-shortcode-widget-plugin.php';
32