PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.3.1.1
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.3.1.1
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 / templates / class-base.php
wpforms-lite / includes / templates Last commit date
class-base.php 9 years ago class-blank.php 9 years ago class-contact.php 9 years ago class-suggestion.php 9 years ago
class-base.php
206 lines
1 <?php
2 /**
3 * Base form template.
4 *
5 * @package WPForms
6 * @author WPForms
7 * @since 1.0.0
8 * @license GPL-2.0+
9 * @copyright Copyright (c) 2016, WPForms LLC
10 */
11 abstract class WPForms_Template {
12
13 /**
14 * Full name of the template, eg "Contact Form".
15 *
16 * @since 1.0.0
17 * @var string
18 */
19 public $name;
20
21 /**
22 * Slug of the template, eg "contact-form" - no spaces.
23 *
24 * @since 1.0.0
25 * @var string
26 */
27 public $slug;
28
29 /**
30 * Short description the template.
31 *
32 * @since 1.0.0
33 * @var string
34 */
35 public $description;
36
37 /**
38 * Short description of the fields included with the template.
39 *
40 * @since 1.0.0
41 * @var string
42 */
43 public $includes;
44
45 /**
46 * URL of the icon to display in the admin area.
47 *
48 * @since 1.0.0
49 * @var string
50 */
51 public $icon;
52
53 /**
54 * Array of data that is assigned to the post_content on form creation.
55 *
56 * @since 1.0.0
57 * @var array
58 */
59 public $data;
60
61 /**
62 * Priority to show in the list of available templates.
63 *
64 * @since 1.0.0
65 * @var int
66 */
67 public $priority = 20;
68
69 /**
70 * Modal message to display when the template is applied.
71 *
72 * @since 1.0.0
73 * @var array
74 */
75 public $modal = '';
76
77 /**
78 * Primary class constructor.
79 *
80 * @since 1.0.0
81 */
82 public function __construct() {
83
84 // Bootstrap
85 $this->init();
86
87 add_filter( 'wpforms_form_templates', array( $this , 'template_details' ), $this->priority );
88 add_filter( 'wpforms_create_form_args', array( $this, 'template_data' ), 10, 2 );
89 add_filter( 'wpforms_save_form_args', array( $this, 'template_replace' ), 10, 4 );
90 add_filter( 'wpforms_builder_template_active', array( $this, 'template_active' ), 10, 2 );
91 }
92
93 /**
94 * Let's get started.
95 *
96 * @since 1.0.0
97 */
98 public function init() {
99
100 }
101
102 /**
103 * Add basic template details to the Add New Form admin screen.
104 *
105 * @since 1.0.0
106 * @param array $templates
107 * @return array
108 */
109 function template_details( $templates ) {
110 $template = array(
111 'name' => $this->name,
112 'slug' => $this->slug,
113 'description' => $this->description,
114 'includes' => $this->includes,
115 'icon' => $this->icon,
116 );
117 $templates[] = $template;
118 return $templates;
119 }
120
121 /**
122 * Add template data when form is created.
123 *
124 * @since 1.0.0
125 * @param array $args
126 * @param array $data
127 * @return array
128 */
129 function template_data( $args, $data ) {
130
131 if ( !empty( $data ) && !empty( $data['template'] ) ) {
132 if ( $data['template'] == $this->slug ) {
133 $args['post_content'] = wp_slash( json_encode( $this->data ) );
134 }
135 }
136 return $args;
137 }
138
139 /**
140 * Replace template on post update if triggered.
141 *
142 * @since 1.0.0
143 * @param array $form
144 * @param array $data
145 * @param array $args
146 * @return array
147 */
148 function template_replace( $form, $data, $args ) {
149
150 if ( !empty( $args['template'] ) ) {
151 if ( $args['template'] == $this->slug ) {
152 $new = $this->data;
153 $new['settings'] = !empty( $form['post_content']['settings'] ) ? $form['post_content']['settings'] : array();
154 $form['post_content'] = wp_slash( json_encode( $new ) );
155 }
156 }
157 return $form;
158 }
159
160 /**
161 * Pass information about the active template back to the builder.
162 *
163 * @since 1.0.0
164 * @param array $details
165 * @param object $form
166 * @return array
167 */
168 function template_active( $details, $form ) {
169
170 if ( empty( $form ) )
171 return;
172
173 $form_data = wpforms_decode( $form->post_content );
174
175 if ( empty( $this->modal ) || empty( $form_data['meta']['template'] ) || $this->slug != $form_data['meta']['template'] ) {
176 return $details;
177 } else {
178 $display = $this->template_modal_conditional( $form_data );
179 }
180
181 $template = array(
182 'name' => $this->name,
183 'slug' => $this->slug,
184 'description' => $this->description,
185 'includes' => $this->includes,
186 'icon' => $this->icon,
187 'modal' => $this->modal,
188 'modal_display' => $display,
189 );
190
191 return $template;
192 }
193
194 /**
195 * Conditional to determine if the template informational modal screens
196 * should display.
197 *
198 * @since 1.0.0
199 * @param array $form_data
200 * @return boolean
201 */
202 function template_modal_conditional( $form_data ) {
203
204 return false;
205 }
206 }