PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.6.2.3
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.6.2.3
1.10.1.1 1.10.1 1.10.0.5 trunk 1.1.4 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.6.1 1.1.7 1.1.7.1 1.1.7.2 1.1.8 1.1.8.1 1.1.8.2 1.1.8.3 1.1.8.4 1.10.0.1 1.10.0.2 1.10.0.3 1.10.0.4 1.2.0 1.2.0.1 1.2.1 1.2.2 1.2.2.1 1.2.2.2 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.5 1.2.5.1 1.2.6 1.2.7 1.2.8 1.2.8.1 1.2.9 1.3.0 1.3.1 1.3.1.1 1.3.1.2 1.3.2 1.3.3 1.3.5 1.3.6 1.3.6.1 1.3.6.2 1.3.7.2 1.3.7.3 1.3.7.4 1.3.8 1.3.9.1 1.4.0.1 1.4.1.1 1.4.2 1.4.2.1 1.4.2.2 1.4.3 1.4.4 1.4.4.1 1.4.5 1.4.5.1 1.4.5.2 1.4.5.3 1.4.6 1.4.7.1 1.4.7.2 1.4.8.1 1.4.9 1.5.0.1 1.5.0.3 1.5.0.4 1.5.1 1.5.1.1 1.5.1.3 1.5.2.1 1.5.2.2 1.5.2.3 1.5.3 1.5.3.1 1.5.4.1 1.5.4.2 1.5.5 1.5.5.1 1.5.6 1.5.6.2 1.5.7 1.5.8.2 1.5.9.1 1.5.9.4 1.5.9.5 1.6.0.1 1.6.0.2 1.6.1 1.6.2.2 1.6.2.3 1.6.3.1 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 1.6.7.3 1.6.8 1.6.8.1 1.6.9 1.7.0 1.7.1.1 1.7.1.2 1.7.2 1.7.2.1 1.7.3 1.7.4 1.7.4.1 1.7.4.2 1.7.5.1 1.7.5.2 1.7.5.3 1.7.5.5 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.7.9.1 1.8.0.1 1.8.0.2 1.8.1.1 1.8.1.2 1.8.1.3 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.3.1 1.8.4 1.8.4.1 1.8.5.2 1.8.5.3 1.8.5.4 1.8.6.2 1.8.6.3 1.8.6.4 1.8.7.2 1.8.8.2 1.8.8.3 1.8.9.1 1.8.9.2 1.8.9.4 1.8.9.5 1.8.9.6 1.9.0.1 1.9.0.2 1.9.0.3 1.9.0.4 1.9.1.1 1.9.1.2 1.9.1.3 1.9.1.4 1.9.1.5 1.9.1.6 1.9.2.1 1.9.2.2 1.9.2.3 1.9.3.1 1.9.3.2 1.9.4.1 1.9.4.2 1.9.5 1.9.5.1 1.9.5.2 1.9.6 1.9.6.1 1.9.6.2 1.9.7.1 1.9.7.2 1.9.7.3 1.9.8.1 1.9.8.2 1.9.8.4 1.9.8.7 1.9.9.2 1.9.9.3 1.9.9.4
wpforms-lite / includes / class-widget.php
wpforms-lite / includes Last commit date
admin 5 years ago emails 5 years ago fields 5 years ago providers 5 years ago templates 5 years ago class-conditional-logic-core.php 5 years ago class-db.php 5 years ago class-fields.php 5 years ago class-form.php 5 years ago class-frontend.php 5 years ago class-install.php 5 years ago class-logging.php 5 years ago class-process.php 5 years ago class-providers.php 5 years ago class-smart-tags.php 5 years ago class-templates.php 5 years ago class-widget.php 5 years ago deprecated.php 5 years ago functions-list.php 5 years ago functions.php 5 years ago integrations.php 5 years ago
class-widget.php
168 lines
1 <?php
2
3 /**
4 * WPForms widget.
5 *
6 * @since 1.0.2
7 */
8 class WPForms_Widget extends WP_Widget {
9
10 /**
11 * Hold widget settings defaults, populated in constructor.
12 *
13 * @since 1.0.2
14 *
15 * @var array
16 */
17 protected $defaults;
18
19 /**
20 * Constructor
21 *
22 * @since 1.0.2
23 */
24 public function __construct() {
25
26 // Widget defaults.
27 $this->defaults = array(
28 'title' => '',
29 'form_id' => '',
30 'show_title' => false,
31 'show_desc' => false,
32 );
33
34 // Widget Slug.
35 $widget_slug = 'wpforms-widget';
36
37 // Widget basics.
38 $widget_ops = array(
39 'classname' => $widget_slug,
40 'description' => esc_html_x( 'Display a form.', 'Widget', 'wpforms-lite' ),
41 );
42
43 // Widget controls.
44 $control_ops = array(
45 'id_base' => $widget_slug,
46 );
47
48 // Load widget.
49 parent::__construct( $widget_slug, esc_html_x( 'WPForms', 'Widget', 'wpforms-lite' ), $widget_ops, $control_ops );
50 }
51
52 /**
53 * Output the HTML for this widget.
54 *
55 * @since 1.0.2
56 *
57 * @param array $args An array of standard parameters for widgets in this theme.
58 * @param array $instance An array of settings for this widget instance.
59 */
60 public function widget( $args, $instance ) {
61
62 // Merge with defaults.
63 $instance = wp_parse_args( (array) $instance, $this->defaults );
64
65 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
66
67 // Title.
68 if ( ! empty( $instance['title'] ) ) {
69 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
70 }
71
72 // Form.
73 if ( ! empty( $instance['form_id'] ) ) {
74 wpforms()->frontend->output( absint( $instance['form_id'] ), $instance['show_title'], $instance['show_desc'] );
75 }
76
77 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
78 }
79
80 /**
81 * Deal with the settings when they are saved by the admin. Here is
82 * where any validation should be dealt with.
83 *
84 * @since 1.0.2
85 *
86 * @param array $new_instance An array of new settings as submitted by the admin.
87 * @param array $old_instance An array of the previous settings.
88 *
89 * @return array The validated and (if necessary) amended settings
90 */
91 public function update( $new_instance, $old_instance ) {
92
93 $new_instance['title'] = wp_strip_all_tags( $new_instance['title'] );
94 $new_instance['form_id'] = ! empty( $new_instance['form_id'] ) ? (int) $new_instance['form_id'] : 0;
95 $new_instance['show_title'] = isset( $new_instance['show_title'] ) ? '1' : false;
96 $new_instance['show_desc'] = isset( $new_instance['show_desc'] ) ? '1' : false;
97
98 return $new_instance;
99 }
100
101 /**
102 * Display the form for this widget on the Widgets page of the WP Admin area.
103 *
104 * @since 1.0.2
105 *
106 * @param array $instance An array of the current settings for this widget.
107 */
108 public function form( $instance ) {
109
110 // Merge with defaults.
111 $instance = wp_parse_args( (array) $instance, $this->defaults );
112 ?>
113 <p>
114 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
115 <?php echo esc_html( _x( 'Title:', 'Widget', 'wpforms-lite' ) ); ?>
116 </label>
117 <input type="text"
118 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
119 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
120 value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat"/>
121 </p>
122 <p>
123 <label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>">
124 <?php echo esc_html( _x( 'Form:', 'Widget', 'wpforms-lite' ) ); ?>
125 </label>
126 <select class="widefat"
127 id="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>"
128 name="<?php echo esc_attr( $this->get_field_name( 'form_id' ) ); ?>">
129 <?php
130 $forms = wpforms()->form->get();
131 if ( ! empty( $forms ) ) {
132 echo '<option value="" selected disabled>' . esc_html_x( 'Select your form', 'Widget', 'wpforms-lite' ) . '</option>';
133
134 foreach ( $forms as $form ) {
135 echo '<option value="' . esc_attr( $form->ID ) . '" ' . selected( $instance['form_id'], $form->ID, false ) . '>' . esc_html( $form->post_title ) . '</option>';
136 }
137 } else {
138 echo '<option value="">' . esc_html_x( 'No forms', 'Widget', 'wpforms-lite' ) . '</option>';
139 }
140 ?>
141 </select>
142 </p>
143 <p>
144 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>"
145 name="<?php echo esc_attr( $this->get_field_name( 'show_title' ) ); ?>" <?php checked( '1', $instance['show_title'] ); ?>>
146 <label for="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>">
147 <?php echo esc_html( _x( 'Display form name', 'Widget', 'wpforms-lite' ) ); ?>
148 </label>
149 <br>
150 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>"
151 name="<?php echo esc_attr( $this->get_field_name( 'show_desc' ) ); ?>" <?php checked( '1', $instance['show_desc'] ); ?>>
152 <label for="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>">
153 <?php echo esc_html( _x( 'Display form description', 'Widget', 'wpforms-lite' ) ); ?>
154 </label>
155 </p>
156 <?php
157 }
158 }
159
160 /**
161 * Register WPForms plugin widgets.
162 */
163 function wpforms_register_widgets() {
164 register_widget( 'WPForms_Widget' );
165 }
166
167 add_action( 'widgets_init', 'wpforms_register_widgets' );
168