| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) | |
| 3 | + exit; | |
| 3 | 4 | /** |
| 4 | 5 | * XYZScripts Insert HTML Snippet Widget Class |
| 5 | 6 | */ |
| 6 | 7 | |
| @@ -9,10 +10,10 @@ | ||
| 9 | 10 | class Xyz_Insert_Html_Widget extends WP_Widget { |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | /** constructor -- name this the same as the class above */ |
| 13 | - function Xyz_Insert_Html_Widget() { | |
| 14 | - parent::WP_Widget(false, $name = 'Insert Html Snippet'); | |
| 14 | + function __construct() { | |
| 15 | + parent::__construct(false, $name = 'Insert Html Snippet'); | |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | /** @see WP_Widget::widget -- do not rename this */ |
| 18 | 19 | function widget($args, $instance) { |
| @@ -19,10 +20,10 @@ | ||
| 19 | 20 | extract( $args ); |
| 20 | 21 | global $wpdb; |
| 21 | 22 | $title = apply_filters('widget_title', $instance['title']); |
| 22 | 23 | $xyz_ihs_id = $instance['message']; |
| 23 | - //echo "SELECT content FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE id='$xyz_ihs_title'";die; | |
| 24 | - $entries = $wpdb->get_results( "SELECT content FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE id='$xyz_ihs_id'" ); | |
| 24 | + | |
| 25 | + $entries = $wpdb->get_results($wpdb->prepare( "SELECT content FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE id=%d",$xyz_ihs_id )); | |
| 25 | 26 | |
| 26 | 27 | $entry = $entries[0]; |
| 27 | 28 | |
| 28 | 29 | echo $before_widget; |
| @@ -27,9 +28,9 @@ | ||
| 27 | 28 | |
| 28 | 29 | echo $before_widget; |
| 29 | 30 | if ( $title ) |
| 30 | 31 | echo $before_title . $title . $after_title; |
| 31 | - echo $entry->content; | |
| 32 | + echo do_shortcode($entry->content); | |
| 32 | 33 | |
| 33 | 34 | echo $after_widget; |
| 34 | 35 | |
| 35 | 36 | } |
| @@ -44,9 +45,9 @@ | ||
| 44 | 45 | |
| 45 | 46 | /** @see WP_Widget::form -- do not rename this */ |
| 46 | 47 | function form($instance) { |
| 47 | 48 | global $wpdb; |
| 48 | - $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE status='1' ORDER BY id DESC" ); | |
| 49 | + $entries = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE status=%d ORDER BY id DESC",1 )); | |
| 49 | 50 | |
| 50 | 51 | |
| 51 | 52 | if(isset($instance['title'])){ |
| 52 | 53 | $title = esc_attr($instance['title']); |
| @@ -70,9 +71,9 @@ | ||
| 70 | 71 | |
| 71 | 72 | <!-- <input class="widefat" id="<?php echo $this->get_field_id('message'); ?>" name="<?php echo $this->get_field_name('message'); ?>" type="text" value="<?php echo $message; ?>" />--> |
| 72 | 73 | <select name="<?php echo $this->get_field_name('message'); ?>"> |
| 73 | 74 | <?php |
| 74 | - if( count($entries)>0 ) { | |
| 75 | + if(!empty($entries)){ //if( count($entries)>0 ) | |
| 75 | 76 | $count=1; |
| 76 | 77 | $class = ''; |
| 77 | 78 | foreach( $entries as $entry ) { |
| 78 | 79 | ?> |
| @@ -87,6 +88,11 @@ | ||
| 87 | 88 | } |
| 88 | 89 | |
| 89 | 90 | |
| 90 | 91 | } // end class Xyz_Insert_Html_Widget |
| 91 | -add_action('widgets_init', create_function('', 'return register_widget("Xyz_Insert_Html_Widget");')); | |
| 92 | + | |
| 93 | +function xyz_ihs_add_snippet_widget(){ | |
| 94 | + register_widget("Xyz_Insert_Html_Widget"); | |
| 95 | +} | |
| 96 | +add_action('widgets_init','xyz_ihs_add_snippet_widget'); | |
| 97 | + | |
| 92 | 98 | ?> |