| @@ -1,17 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | +if ( ! defined( 'ABSPATH' ) ) | |
| 3 | + exit; | |
| 2 | 4 | /** |
| 3 | 5 | * XYZScripts Insert HTML Snippet Widget Class |
| 4 | 6 | */ |
| 5 | -require( dirname( __FILE__ ) . '../../../../wp-load.php' ); | |
| 6 | 7 | |
| 8 | +////*****************************Sidebar Widget**********************************//// | |
| 7 | 9 | |
| 8 | 10 | class Xyz_Insert_Html_Widget extends WP_Widget { |
| 9 | 11 | |
| 10 | 12 | |
| 11 | 13 | /** constructor -- name this the same as the class above */ |
| 12 | - function Xyz_Insert_Html_Widget() { | |
| 13 | - parent::WP_Widget(false, $name = 'Insert Html Snippet'); | |
| 14 | + function __construct() { | |
| 15 | + parent::__construct(false, $name = 'Insert Html Snippet'); | |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | 18 | /** @see WP_Widget::widget -- do not rename this */ |
| 17 | 19 | function widget($args, $instance) { |
| @@ -18,10 +20,10 @@ | ||
| 18 | 20 | extract( $args ); |
| 19 | 21 | global $wpdb; |
| 20 | 22 | $title = apply_filters('widget_title', $instance['title']); |
| 21 | 23 | $xyz_ihs_id = $instance['message']; |
| 22 | - //echo "SELECT content FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE id='$xyz_ihs_title'";die; | |
| 23 | - $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 )); | |
| 24 | 26 | |
| 25 | 27 | $entry = $entries[0]; |
| 26 | 28 | |
| 27 | 29 | echo $before_widget; |
| @@ -26,9 +28,9 @@ | ||
| 26 | 28 | |
| 27 | 29 | echo $before_widget; |
| 28 | 30 | if ( $title ) |
| 29 | 31 | echo $before_title . $title . $after_title; |
| 30 | - echo $entry->content; | |
| 32 | + echo do_shortcode($entry->content); | |
| 31 | 33 | |
| 32 | 34 | echo $after_widget; |
| 33 | 35 | |
| 34 | 36 | } |
| @@ -43,12 +45,23 @@ | ||
| 43 | 45 | |
| 44 | 46 | /** @see WP_Widget::form -- do not rename this */ |
| 45 | 47 | function form($instance) { |
| 46 | 48 | global $wpdb; |
| 47 | - $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 )); | |
| 48 | 50 | |
| 49 | - $title = esc_attr($instance['title']); | |
| 50 | - $message = esc_attr($instance['message']); | |
| 51 | + | |
| 52 | + if(isset($instance['title'])){ | |
| 53 | + $title = esc_attr($instance['title']); | |
| 54 | + }else{ | |
| 55 | + $title = ''; | |
| 56 | + } | |
| 57 | + | |
| 58 | + if(isset($instance['message'])){ | |
| 59 | + $message = esc_attr($instance['message']); | |
| 60 | + }else{ | |
| 61 | + $message = ''; | |
| 62 | + } | |
| 63 | + | |
| 51 | 64 | ?> |
| 52 | 65 | <p> |
| 53 | 66 | <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
| 54 | 67 | <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> |
| @@ -58,9 +71,9 @@ | ||
| 58 | 71 | |
| 59 | 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; ?>" />--> |
| 60 | 73 | <select name="<?php echo $this->get_field_name('message'); ?>"> |
| 61 | 74 | <?php |
| 62 | - if( count($entries)>0 ) { | |
| 75 | + if(!empty($entries)){ //if( count($entries)>0 ) | |
| 63 | 76 | $count=1; |
| 64 | 77 | $class = ''; |
| 65 | 78 | foreach( $entries as $entry ) { |
| 66 | 79 | ?> |
| @@ -75,6 +88,11 @@ | ||
| 75 | 88 | } |
| 76 | 89 | |
| 77 | 90 | |
| 78 | 91 | } // end class Xyz_Insert_Html_Widget |
| 79 | -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 | + | |
| 80 | 98 | ?> |