PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.9.1.2
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.9.1.2
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 1 year ago emails 1 year ago fields 1 year ago functions 1 year ago providers 1 year ago templates 1 year ago class-db.php 1 year ago class-fields.php 1 year ago class-form.php 1 year ago class-install.php 1 year ago class-process.php 1 year ago class-providers.php 1 year ago class-templates.php 1 year ago class-widget.php 1 year ago deprecated.php 1 year ago functions-list.php 1 year ago functions.php 1 year ago integrations.php 1 year ago
class-widget.php
183 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
70 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
71
72 // Title.
73 if ( ! empty( $instance['title'] ) ) {
74 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; // phpcs:ignore
75 }
76
77 // Form.
78 if ( ! empty( $instance['form_id'] ) ) {
79 wpforms()->obj( 'frontend' )->output( absint( $instance['form_id'] ), $instance['show_title'], $instance['show_desc'] );
80 }
81
82 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
83 }
84
85 /**
86 * Deal with the settings when they are saved by the admin. Here is
87 * where any validation should be dealt with.
88 *
89 * @since 1.0.2
90 *
91 * @param array $new_instance An array of new settings as submitted by the admin.
92 * @param array $old_instance An array of the previous settings.
93 *
94 * @return array The validated and (if necessary) amended settings
95 */
96 public function update( $new_instance, $old_instance ) {
97
98 $new_instance['title'] = wp_strip_all_tags( $new_instance['title'] );
99 $new_instance['form_id'] = ! empty( $new_instance['form_id'] ) ? (int) $new_instance['form_id'] : 0;
100 $new_instance['show_title'] = isset( $new_instance['show_title'] ) && $new_instance['show_title'] ? '1' : false;
101 $new_instance['show_desc'] = isset( $new_instance['show_desc'] ) && $new_instance['show_desc'] ? '1' : false;
102
103 return $new_instance;
104 }
105
106 /**
107 * Display the form for this widget on the Widgets page of the WP Admin area.
108 *
109 * @since 1.0.2
110 *
111 * @param array $instance An array of the current settings for this widget.
112 */
113 public function form( $instance ) {
114
115 // Merge with defaults.
116 $instance = wp_parse_args( (array) $instance, $this->defaults );
117 ?>
118 <p>
119 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
120 <?php echo esc_html( _x( 'Title:', 'Widget', 'wpforms-lite' ) ); ?>
121 </label>
122 <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"/>
123 </p>
124 <p>
125 <label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>">
126 <?php echo esc_html( _x( 'Form:', 'Widget', 'wpforms-lite' ) ); ?>
127 </label>
128 <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' ) ); ?>">
129 <?php
130 $forms = wpforms()->obj( 'form' )->get();
131
132 if ( ! empty( $forms ) ) {
133 echo '<option value="" selected disabled>' . esc_html_x( 'Select your form', 'Widget', 'wpforms-lite' ) . '</option>';
134
135 foreach ( $forms as $form ) {
136 echo '<option value="' . esc_attr( $form->ID ) . '" ' . selected( $instance['form_id'], $form->ID, false ) . '>' . esc_html( $form->post_title ) . '</option>';
137 }
138 } else {
139 echo '<option value="">' . esc_html_x( 'No forms', 'Widget', 'wpforms-lite' ) . '</option>';
140 }
141 ?>
142 </select>
143 </p>
144 <p>
145 <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'] ); ?>>
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' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_desc' ) ); ?>" <?php checked( '1', $instance['show_desc'] ); ?>>
151 <label for="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>">
152 <?php echo esc_html( _x( 'Display form description', 'Widget', 'wpforms-lite' ) ); ?>
153 </label>
154 </p>
155 <?php
156 }
157 }
158
159 /**
160 * Register the WPForms widget.
161 *
162 * @since 1.0.2
163 */
164 function wpforms_register_widgets() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
165
166 // Hide legacy widget. This filter is available from WP 5.8.
167 // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
168 add_filter(
169 'widget_types_to_hide_from_legacy_widget_block',
170 static function ( $widget_types ) {
171
172 $widget_types[] = 'wpforms-widget';
173
174 return $widget_types;
175 }
176 );
177 // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
178
179 register_widget( 'WPForms_Widget' );
180 }
181
182 add_action( 'widgets_init', 'wpforms_register_widgets' );
183