PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.1.8.4
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.1.8.4
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 10 years ago emails 10 years ago fields 10 years ago templates 10 years ago class-db.php 10 years ago class-fields.php 10 years ago class-form.php 10 years ago class-frontend.php 10 years ago class-install.php 10 years ago class-logging.php 10 years ago class-preview.php 10 years ago class-process.php 10 years ago class-smart-tags.php 10 years ago class-templates.php 10 years ago class-widget.php 10 years ago functions.php 10 years ago
class-widget.php
142 lines
1 <?php
2 /**
3 * WPForms widget.
4 *
5 * @package WPForms
6 * @author WPForms
7 * @since 1.0.2
8 * @license GPL-2.0+
9 * @copyright Copyright (c) 2016, WPForms LLC
10 */
11 class WPForms_Widget extends WP_Widget {
12
13 /**
14 * Holds widget settings defaults, populated in constructor.
15 *
16 * @since 1.0.2
17 * @var array
18 */
19 protected $defaults;
20
21 /**
22 * Constructor
23 *
24 * @since 1.0.2
25 */
26 function __construct() {
27
28 // widget defaults
29 $this->defaults = array(
30 'title' => '',
31 'form_id' => '',
32 'show_title' => false,
33 'show_desc' => false,
34 );
35
36 // Widget Slug
37 $widget_slug = 'wpforms-widget';
38
39 // widget basics
40 $widget_ops = array(
41 'classname' => $widget_slug,
42 'description' => 'Display a form.'
43 );
44
45 // widget controls
46 $control_ops = array(
47 'id_base' => $widget_slug,
48 );
49
50 // load widget
51 parent::__construct( $widget_slug, 'WPForms', $widget_ops, $control_ops );
52 }
53
54 /**
55 * Outputs the HTML for this widget.
56 *
57 * @since 1.0.2
58 * @param array $args An array of standard parameters for widgets in this theme
59 * @param array $instance An array of settings for this widget instance
60 */
61 function widget( $args, $instance ) {
62
63 extract( $args );
64
65 // Merge with defaults
66 $instance = wp_parse_args( (array) $instance, $this->defaults );
67
68 echo $before_widget;
69
70 // Title
71 if ( !empty( $instance['title'] ) ) {
72 echo $before_title . apply_filters( 'widget_title' , $instance['title'] ) . $after_title;
73 }
74
75 // Form
76 if ( !empty( $instance['form_id'] ) ) {
77 wpforms()->frontend->output( absint( $instance['form_id'] ), $instance['show_title'], $instance['show_desc'] );
78 }
79
80 echo $after_widget;
81 }
82
83 /**
84 * Deals with the settings when they are saved by the admin. Here is
85 * where any validation should be dealt with.
86 *
87 * @since 1.0.2
88 * @param array $new_instance An array of new settings as submitted by the admin
89 * @param array $old_instance An array of the previous settings
90 * @return array The validated and (if necessary) amended settings
91 */
92 function update( $new_instance, $old_instance ) {
93
94 $new_instance['title'] = strip_tags( $new_instance['title'] );
95 $new_instance['form_id'] = absint( $new_instance['form_id'] );
96 $new_instance['show_title'] = isset( $new_instance['show_title'] ) ? '1' : false;
97 $new_instance['show_desc'] = isset( $new_instance['show_desc'] ) ? '1' : false;
98
99 return $new_instance;
100 }
101
102 /**
103 * Displays the form for this widget on the Widgets page of the WP Admin area.
104 *
105 * @since 1.0.2
106 * @param array $instance An array of the current settings for this widget
107 */
108 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 $this->get_field_id( 'title' ); ?>">Title:</label>
115 <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" />
116 </p>
117 <p>
118 <label for="<?php echo $this->get_field_id( 'form_id' ); ?>">Form:</label>
119 <select id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>" class="widefat">
120 <?php
121 $forms = wpforms()->form->get();
122 if ( !empty( $forms ) ) {
123 foreach ( $forms as $form ) {
124 printf( '<option value="%d" %s>%s</option>', $form->ID, selected( $instance['form_id'], $form->ID, false ), esc_html( $form->post_title ) );
125 }
126 } else {
127 printf( '<option value="">%s</option>', __( 'No forms', 'wpforms' ) );
128 }
129 ?>
130 </select>
131 </p>
132 <p>
133 <input type="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" <?php checked( '1', $instance['show_title'] ); ?>>
134 <label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Display form title', 'wpforms' ); ?></label>
135 <br>
136 <input type="checkbox" id="<?php echo $this->get_field_id( 'show_desc' ); ?>" name="<?php echo $this->get_field_name( 'show_desc' ); ?>" <?php checked( '1', $instance['show_desc'] ); ?>>
137 <label for="<?php echo $this->get_field_id( 'show_desc' ); ?>"><?php _e( 'Display form description', 'wpforms' ); ?></label>
138 </p>
139 <?php
140 }
141 }
142 add_action( 'widgets_init', create_function( '', "register_widget('WPForms_Widget');" ) );