PluginProbe
WPBot – ChatBot Conversational Forms / 1.4.7
WPBot – ChatBot Conversational Forms v1.4.7
1.5.0 1.4.8 1.4.7 trunk 0.9.2 0.9.3 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.6 1.1.7 1.1.8 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 All 36 releases
conversational-forms / classes / widget.php

widget.php in WPBot – ChatBot Conversational Forms 1.4.7, at classes/widget.php

111 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 class Qcformbuilder_Forms_Widget extends WP_Widget {
5
6 /**
7 * Create widget
8 *
9 * @since unknown
10 */
11 function __construct() {
12 // Instantiate the parent object
13 parent::__construct( false, __('Qcformbuilder Form', 'qcformbuilder-forms' ) );
14
15 /**
16 * Runs after Qcformbuilder Forms widget is initialized
17 *
18 * @since 1.4.0
19 */
20 do_action( 'qcformbuilder_forms_widget_init' );
21 }
22
23 /**
24 * Widget output
25 *
26 * @since unknown
27 *
28 * @param array $args
29 * @param array $instance
30 */
31 function widget( $args, $instance ) {
32
33 if(!empty($instance['form'])){
34
35 extract($args, EXTR_SKIP);
36
37 echo $before_widget;
38
39 $title = empty($instance['title']) ? ' ' : apply_filters( 'widget_title', $instance['title']);
40 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
41
42 echo Qcformbuilder_Forms::render_form( $instance[ 'form' ] );
43
44 echo $after_widget;
45
46 }
47 }
48
49 /**
50 * Update widget settings
51 *
52 * @since unknown
53 *
54 * @param array $new_instance
55 * @param array $old_instance
56 *
57 * @return array
58 */
59 function update( $new_instance, $old_instance ) {
60 // Save widget options
61 return $new_instance;
62 }
63
64 /**
65 * Widget UI form
66 *
67 * @since unknown
68 *
69 * @param array $instance
70 */
71 function form( $instance ) {
72
73 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
74 $title = strip_tags($instance['title']);
75
76 do_action( 'qcformbuilder_forms_widget_form_start', $instance );
77
78 echo "<p><label for=\" " . $this->get_field_id('title') . "\">" . esc_html__('Title', 'qcformbuilder-forms') . ": <input class=\"widefat\" id=\"" . $this->get_field_id('title') . "\" name=\"" . $this->get_field_name('title') . "\" type=\"text\" value=\"" . esc_attr($title). "\" /></label></p>\r\n";
79
80 // get forms
81 $forms = Qcformbuilder_Forms_Forms::get_forms( true );
82
83 echo "<p><label for=\" " . $this->get_field_id('title') . "\">" . esc_html__('Form', 'qcformbuilder-forms') . ": </label><select style=\"width:100%;\" name=\"" . $this->get_field_name('form') . "\">\r\n";
84 echo "<option value=\"\"></option>\r\n";
85 if(!empty($forms)){
86
87 foreach($forms as $formid=>$form){
88 $sel = "";
89 if(!empty($instance['form'])){
90 if($instance['form'] == $formid){
91 $sel = ' selected="selected"';
92 }
93 }
94 echo "<option value=\"" . esc_attr( $formid ). "\"". esc_attr( $sel ).">" . esc_html( $form['name'] ) ."</option>\r\n";
95 }
96 }
97
98 echo "</select></p>\r\n";
99 do_action( 'qcformbuilder_forms_widget_form_end', $instance, $this );
100 }
101 }
102
103 function qcformbuilder_forms_register_widget() {
104 if( ! did_action( 'qcformbuilder_forms_widget_init' ) ){
105 register_widget( 'Qcformbuilder_Forms_Widget' );
106 }
107
108 }
109
110 add_action( 'widgets_init', 'qcformbuilder_forms_register_widget' );
111