Shortcode Widget - Version 1.3

Version Description

  • Minor bug fix
  • Changed tested up to version number
  • Made it translation ready, constant was being used for text domains, silly error, I know :)
Download this release

Release Info

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

Code changes from version 1.2 to 1.3

includes/class-shortcode-widget.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
index.php CHANGED
@@ -1,31 +1,3 @@
1
  <?php
2
- /*
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.2
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
- define('SHORTCODE_WIDGET_TEXT_DOMAIN','shortcode-widget');
14
-
15
- require_once('class-shortcode-widget.php');
16
-
17
- function shortcode_widget_init(){
18
- register_widget('Shortcode_Widget');
19
- }
20
- add_action('widgets_init','shortcode_widget_init');
21
-
22
- function shortcode_widget_load_text_domain(){
23
- load_plugin_textdomain( SHORTCODE_WIDGET_TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
24
- }
25
- add_action('plugins_loaded','shortcode_widget_load_text_domain');
26
-
27
- add_shortcode('shortcode_widget_test', 'shortcode_widget_test_output');
28
- function shortcode_widget_test_output($args){
29
- return __( "It works" , SHORTCODE_WIDGET_TEXT_DOMAIN );
30
- }
31
- ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
2
 
3
+ //Silence is golden
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,11 +1,9 @@
1
  === Shortcode Widget ===
2
  Contributors: gagan0123
3
  Tags: Shortcode, Widget
4
- Requires at least: 3.1
5
- Tested up to: 4.3.1
6
  Requires at least: 3.3
7
- Tested up to: 4.0
8
- Stable tag: 1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -41,4 +39,9 @@ To test the widget you can add the widget and use the shortcode "[shortcode_widg
41
  * Reflecting the changes that have been done to the default text widget over the years
42
 
43
  = 1.2 =
44
- * Corrections in text domain and added one more string as translatable
 
 
 
 
 
1
  === Shortcode Widget ===
2
  Contributors: gagan0123
3
  Tags: Shortcode, Widget
 
 
4
  Requires at least: 3.3
5
+ Tested up to: 4.7.5
6
+ Stable tag: 1.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
39
  * Reflecting the changes that have been done to the default text widget over the years
40
 
41
  = 1.2 =
42
+ * Corrections in text domain and added one more string as translatable
43
+
44
+ = 1.3 =
45
+ * Minor bug fix
46
+ * Changed tested up to version number
47
+ * Made it translation ready, constant was being used for text domains, silly error, I know :)
shortcode-widget.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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.3
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
+ }