PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.16
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.16
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-form-widget.php

class-form-widget.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.16, at includes/class-form-widget.php

95 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class weForms_Widget
5 *
6 * Widget class for weForms Form widget
7 *
8 * @since 1.2.7
9 */
10 class weForms_Widget extends WP_Widget {
11
12 /**
13 * weForms_Widget constructor.
14 */
15 public function __construct() {
16 parent::__construct(
17 'weforms_widget',
18 __( 'weForms Widget', 'weforms' ),
19 [ 'description' => __( 'Add weForms Form to Sidebar', 'weforms' )]
20 );
21 }
22
23 /**
24 * Render widget
25 *
26 * @return void
27 */
28 public function widget( $args, $instance ) {
29 $title = apply_filters( 'widget_title', $instance['title'] );
30 $form_id = apply_filters( 'weforms_widget_form_id', $instance['form_id'] );
31
32 echo wp_kses_post( $args['before_widget'] );
33
34 if ( ! empty( $title ) ) {
35 echo wp_kses_post( $args['before_title'] ) . wp_kses_post( $title ) . wp_kses_post( $args['after_title'] );
36 }
37
38 echo do_shortcode( sprintf( '[weforms id ="%s" ]', $form_id ) );
39
40 echo wp_kses_post( $args['after_widget'] );
41 }
42
43 /**
44 * weForms widget backend
45 *
46 * @return void
47 */
48 public function form( $instance ) {
49 $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Form', 'weforms' );
50 $form_id = isset( $instance[ 'form_id' ] ) ? $instance[ 'form_id' ] : 0;
51
52 $all_forms = weforms()->form->all();
53 $options = sprintf( "<option value='%s'>%s</option>", 0, __( 'Select Form', 'weforms' ) );
54
55 foreach ( $all_forms['forms'] as $form ) {
56 $options .= sprintf( "<option value='%s' %s >%s</option>", $form->id, selected( $form_id, $form->id, false ), $form->name );
57 } ?>
58
59 <p>
60 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'weforms' ); ?></label>
61 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo wp_kses_post( $title ); ?>" />
62 </p>
63 <p>
64 <label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>"> <?php esc_html_e( 'Form:', 'weforms' ); ?></label>
65 <select id="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'form_id' ) ); ?>">
66 <?php echo $options; ?> // WPCS: sanitization ok.
67 </select>
68 </p>
69
70 <?php
71 }
72
73 /**
74 * Updating widget replacing old instances with new
75 *
76 * @return $instance
77 */
78 public function update( $new_instance, $old_instance ) {
79 $instance = [];
80 $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
81 $instance['form_id'] = ( !empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : '';
82
83 return $instance;
84 }
85 }
86 /**
87 * Register weForms widget
88 *
89 * @return void
90 */
91 function weforms_register_widget() {
92 register_widget( 'weforms_widget' );
93 }
94 add_action( 'widgets_init', 'weforms_register_widget' );
95