PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.10.0.5
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.10.0.5
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 2 weeks ago emails 4 months ago fields 2 weeks ago functions 2 months ago providers 10 months ago templates 4 months ago class-db.php 1 year ago class-fields.php 1 year ago class-form.php 4 months ago class-install.php 1 year ago class-process.php 4 months ago class-providers.php 1 year ago class-templates.php 2 years ago class-widget.php 1 year ago deprecated.php 8 months ago functions-list.php 3 years ago functions.php 11 months ago integrations.php 4 months ago
class-widget.php
193 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * WPForms widget.
9 *
10 * @since 1.0.2
11 */
12 class WPForms_Widget extends WP_Widget {
13
14 /**
15 * Hold widget settings defaults, populated in constructor.
16 *
17 * @since 1.0.2
18 *
19 * @var array
20 */
21 protected $defaults;
22
23 /**
24 * Constructor.
25 *
26 * @since 1.0.2
27 */
28 public function __construct() {
29
30 // Widget defaults.
31 $this->defaults = [
32 'title' => '',
33 'form_id' => '',
34 'show_title' => false,
35 'show_desc' => false,
36 ];
37
38 // Widget Slug.
39 $widget_slug = 'wpforms-widget';
40
41 // Widget basics.
42 $widget_ops = [
43 'classname' => $widget_slug,
44 'description' => esc_html_x( 'Display a form.', 'Widget', 'wpforms-lite' ),
45 'show_instance_in_rest' => false,
46 ];
47
48 // Widget controls.
49 $control_ops = [
50 'id_base' => $widget_slug,
51 ];
52
53 // Load widget.
54 parent::__construct( $widget_slug, esc_html_x( 'WPForms', 'Widget', 'wpforms-lite' ), $widget_ops, $control_ops );
55 }
56
57 /**
58 * Output the HTML for this widget.
59 *
60 * @since 1.0.2
61 *
62 * @param array $args An array of standard parameters for widgets in this theme.
63 * @param array $instance An array of settings for this widget instance.
64 */
65 public function widget( $args, $instance ) {
66
67 // Merge with defaults.
68 $instance = wp_parse_args( (array) $instance, $this->defaults );
69 $args = wp_parse_args(
70 $args,
71 [
72 'before_widget' => '',
73 'after_widget' => '',
74 'before_title' => '',
75 'after_title' => '',
76 ]
77 );
78
79 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
80 echo $args['before_widget'];
81
82 if ( ! empty( $instance['title'] ) ) {
83 // phpcs:ignore
84 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
85 }
86
87 if ( ! empty( $instance['form_id'] ) ) {
88 wpforms()->obj( 'frontend' )->output( absint( $instance['form_id'] ), (bool) $instance['show_title'], (bool) $instance['show_desc'] );
89 }
90
91 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
92 echo $args['after_widget'];
93 }
94
95 /**
96 * Deal with the settings when they are saved by the admin. Here is
97 * where any validation should be dealt with.
98 *
99 * @since 1.0.2
100 *
101 * @param array $new_instance An array of new settings as submitted by the admin.
102 * @param array $old_instance An array of the previous settings.
103 *
104 * @return array The validated and (if necessary) amended settings
105 */
106 public function update( $new_instance, $old_instance ) {
107
108 $new_instance['title'] = wp_strip_all_tags( $new_instance['title'] );
109 $new_instance['form_id'] = ! empty( $new_instance['form_id'] ) ? (int) $new_instance['form_id'] : 0;
110 $new_instance['show_title'] = isset( $new_instance['show_title'] ) && $new_instance['show_title'] ? '1' : false;
111 $new_instance['show_desc'] = isset( $new_instance['show_desc'] ) && $new_instance['show_desc'] ? '1' : false;
112
113 return $new_instance;
114 }
115
116 /**
117 * Display the form for this widget on the Widgets page of the WP Admin area.
118 *
119 * @since 1.0.2
120 *
121 * @param array $instance An array of the current settings for this widget.
122 */
123 public function form( $instance ) {
124
125 // Merge with defaults.
126 $instance = wp_parse_args( (array) $instance, $this->defaults );
127 ?>
128 <p>
129 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
130 <?php echo esc_html( _x( 'Title:', 'Widget', 'wpforms-lite' ) ); ?>
131 </label>
132 <input type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat"/>
133 </p>
134 <p>
135 <label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>">
136 <?php echo esc_html( _x( 'Form:', 'Widget', 'wpforms-lite' ) ); ?>
137 </label>
138 <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'form_id' ) ); ?>">
139 <?php
140 $forms = wpforms()->obj( 'form' )->get();
141
142 if ( ! empty( $forms ) ) {
143 echo '<option value="" selected disabled>' . esc_html_x( 'Select your form', 'Widget', 'wpforms-lite' ) . '</option>';
144
145 foreach ( $forms as $form ) {
146 echo '<option value="' . esc_attr( $form->ID ) . '" ' . selected( $instance['form_id'], $form->ID, false ) . '>' . esc_html( $form->post_title ) . '</option>';
147 }
148 } else {
149 echo '<option value="">' . esc_html_x( 'No forms', 'Widget', 'wpforms-lite' ) . '</option>';
150 }
151 ?>
152 </select>
153 </p>
154 <p>
155 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_title' ) ); ?>" <?php checked( '1', $instance['show_title'] ); ?>>
156 <label for="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>">
157 <?php echo esc_html( _x( 'Display form name', 'Widget', 'wpforms-lite' ) ); ?>
158 </label>
159 <br>
160 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_desc' ) ); ?>" <?php checked( '1', $instance['show_desc'] ); ?>>
161 <label for="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>">
162 <?php echo esc_html( _x( 'Display form description', 'Widget', 'wpforms-lite' ) ); ?>
163 </label>
164 </p>
165 <?php
166 }
167 }
168
169 /**
170 * Register the WPForms widget.
171 *
172 * @since 1.0.2
173 */
174 function wpforms_register_widgets() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
175
176 // Hide legacy widget. This filter is available from WP 5.8.
177 // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
178 add_filter(
179 'widget_types_to_hide_from_legacy_widget_block',
180 static function ( $widget_types ) {
181
182 $widget_types[] = 'wpforms-widget';
183
184 return $widget_types;
185 }
186 );
187 // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
188
189 register_widget( 'WPForms_Widget' );
190 }
191
192 add_action( 'widgets_init', 'wpforms_register_widgets' );
193