PluginProbe
Insert PHP Code Snippet / 1.2.1
Insert PHP Code Snippet v1.2.1
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / widget.php

widget.php in Insert PHP Code Snippet 1.2.1, at widget.php

96 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4 /**
5 * XYZScripts Insert PHP Snippet Widget Class
6 */
7
8 ////*****************************Sidebar Widget**********************************////
9
10 class Xyz_Insert_Php_Widget extends WP_Widget {
11
12
13 /** constructor -- name this the same as the class above */
14 function __construct() {
15 parent::__construct(false, $name = 'Insert PHP Snippet');
16 }
17
18 /** @see WP_Widget::widget -- do not rename this */
19 function widget($args, $instance) {
20 extract( $args );
21 global $wpdb;
22 $title = apply_filters('widget_title', $instance['title']);
23 $xyz_ips_id = $instance['message'];
24
25 $entries = $wpdb->get_results($wpdb->prepare( "SELECT content FROM ".$wpdb->prefix."xyz_ips_short_code WHERE id=%d",$xyz_ips_id ));
26
27 $entry = $entries[0];
28
29 echo $before_widget;
30 if ( $title )
31 echo $before_title . $title . $after_title;
32 $content_to_eval=$entry->content;
33 if(substr($content_to_eval, 0,5)=='<?php')
34 $content_to_eval='?>'.$content_to_eval;
35 eval($content_to_eval);
36
37 echo $after_widget;
38
39 }
40
41 /** @see WP_Widget::update -- do not rename this */
42 function update($new_instance, $old_instance) {
43 $instance = $old_instance;
44 $instance['title'] = strip_tags($new_instance['title']);
45 $instance['message'] = strip_tags($new_instance['message']);
46 return $instance;
47 }
48
49 /** @see WP_Widget::form -- do not rename this */
50 function form($instance) {
51 global $wpdb;
52 $entries = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d ORDER BY id DESC",1 ));
53
54
55 if(isset($instance['title'])){
56 $title = esc_attr($instance['title']);
57 }else{
58 $title = '';
59 }
60
61 if(isset($instance['message'])){
62 $message = esc_attr($instance['message']);
63 }else{
64 $message = '';
65 }
66
67 ?>
68 <p>
69 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
70 <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; ?>" />
71 </p>
72 <p>
73 <label for="<?php echo $this->get_field_id('message'); ?>"><?php _e('Choose Snippet :'); ?></label>
74
75 <!-- <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; ?>" />-->
76 <select name="<?php echo $this->get_field_name('message'); ?>">
77 <?php
78 if( count($entries)>0 ) {
79 $count=1;
80 $class = '';
81 foreach( $entries as $entry ) {
82 ?>
83 <option value="<?php echo $entry->id;?>" <?php if($message==$entry->id)echo "selected"; ?>><?php echo $entry->title;?></option>
84 <?php
85 }
86 }
87 ?>
88 </select>
89 </p>
90 <?php
91 }
92
93
94 } // end class Xyz_Insert_Php_Widget
95 add_action('widgets_init', create_function('', 'return register_widget("Xyz_Insert_Php_Widget");'));
96 ?>