PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmField.php +502 -302 6.25 → trunk View file →
@@ -4,73 +4,87 @@
4 4 }
5 5
6 6 class FrmField {
7 7
8 - public static $use_cache = true;
8 + /**
9 + * @var bool
10 + */
11 + public static $use_cache = true;
12 +
13 + /**
14 + * @var int
15 + */
9 16 public static $transient_size = 200;
10 17
18 + /**
19 + * @return array
20 + */
11 21 public static function field_selection() {
12 22 $fields = array(
13 23 'text' => array(
14 24 'name' => __( 'Text', 'formidable' ),
15 - 'icon' => 'frm_icon_font frm_text2_icon',
25 + 'icon' => 'frmfont frm_text2_icon',
16 26 ),
17 27 'textarea' => array(
18 28 'name' => __( 'Paragraph', 'formidable' ),
19 - 'icon' => 'frm_icon_font frm_paragraph_icon',
29 + 'icon' => 'frmfont frm_paragraph_icon',
20 30 ),
21 31 'checkbox' => array(
22 32 'name' => __( 'Checkboxes', 'formidable' ),
23 - 'icon' => 'frm_icon_font frm_check_square_icon',
33 + 'icon' => 'frmfont frm_check_square_icon',
24 34 ),
25 35 'radio' => array(
26 36 'name' => __( 'Radio Buttons', 'formidable' ),
27 - 'icon' => 'frm_icon_font frm_radio_checked_icon',
37 + 'icon' => 'frmfont frm_radio_checked_icon',
28 38 ),
29 39 'select' => array(
30 40 'name' => __( 'Dropdown', 'formidable' ),
31 - 'icon' => 'frm_icon_font frm_dropdown_icon',
41 + 'icon' => 'frmfont frm_dropdown_icon',
32 42 ),
33 43 'email' => array(
34 44 'name' => __( 'Email', 'formidable' ),
35 - 'icon' => 'frm_icon_font frm_email2_icon',
45 + 'icon' => 'frmfont frm_email2_icon',
36 46 ),
37 47 'url' => array(
38 48 'name' => __( 'Website/URL', 'formidable' ),
39 - 'icon' => 'frm_icon_font frm_link2_icon',
49 + 'icon' => 'frmfont frm_link2_icon',
40 50 ),
41 51 'number' => array(
42 52 'name' => __( 'Number', 'formidable' ),
43 - 'icon' => 'frm_icon_font frm_hashtag_icon',
53 + 'icon' => 'frmfont frm_hashtag_icon',
44 54 ),
45 55 'name' => array(
46 56 'name' => __( 'Name', 'formidable' ),
47 - 'icon' => 'frm_icon_font frm_user_name_icon',
57 + 'icon' => 'frmfont frm_user_name_icon',
48 58 ),
49 59 'phone' => array(
50 60 'name' => __( 'Phone', 'formidable' ),
51 - 'icon' => 'frm_icon_font frm_phone_icon',
61 + 'icon' => 'frmfont frm_phone_icon',
52 62 ),
53 63 'html' => array(
54 64 'name' => __( 'HTML', 'formidable' ),
55 - 'icon' => 'frm_icon_font frm_code2_icon',
65 + 'icon' => 'frmfont frm_code2_icon',
56 66 ),
57 67 'hidden' => array(
58 68 'name' => __( 'Hidden', 'formidable' ),
59 - 'icon' => 'frm_icon_font frm_eye_slash2_icon',
69 + 'icon' => 'frmfont frm_eye_slash2_icon',
60 70 ),
61 71 'user_id' => array(
62 72 'name' => __( 'User ID', 'formidable' ),
63 - 'icon' => 'frm_icon_font frm_user2_icon',
73 + 'icon' => 'frmfont frm_user2_icon',
64 74 ),
65 75 'captcha' => array(
66 76 'name' => self::get_captcha_field_name(),
67 - 'icon' => 'frm_icon_font frm_shield_check2_icon',
77 + 'icon' => 'frmfont frm_shield_check2_icon',
68 78 ),
69 79 'credit_card' => array(
70 80 'name' => __( 'Payment', 'formidable' ),
71 - 'icon' => 'frm_icon_font frm_credit_card2_icon',
81 + 'icon' => 'frmfont frm_credit_card2_icon',
72 82 ),
83 + 'address' => array(
84 + 'name' => __( 'Address', 'formidable' ),
85 + 'icon' => 'frmfont frm_location2_icon',
86 + ),
73 87 FrmSubmitHelper::FIELD_TYPE => array(
74 88 'name' => __( 'Submit', 'formidable' ),
75 89 'hide' => true,
76 90 ),
@@ -75,11 +89,26 @@
75 89 'hide' => true,
76 90 ),
77 91 FrmFieldGdprHelper::FIELD_TYPE => array(
78 92 'name' => __( 'GDPR', 'formidable' ),
79 - 'icon' => 'frm_icon_font frm-gdpr-icon',
93 + 'icon' => 'frmfont frm-gdpr-icon',
80 94 'hide' => FrmFieldGdprHelper::hide_gdpr_field(),
81 95 ),
96 + 'product' => array(
97 + 'name' => __( 'Product', 'formidable' ),
98 + 'icon' => 'frmfont frm_product2_icon',
99 + 'section' => 'pricing',
100 + ),
101 + 'quantity' => array(
102 + 'name' => __( 'Quantity', 'formidable' ),
103 + 'icon' => 'frmfont frm_quantity_icon',
104 + 'section' => 'pricing',
105 + ),
106 + 'total' => array(
107 + 'name' => __( 'Total', 'formidable' ),
108 + 'icon' => 'frmfont frm_total2_icon',
109 + 'section' => 'pricing',
110 + ),
82 111 );
83 112
84 113 /**
85 114 * @param array $fields
@@ -95,60 +124,98 @@
95 124 private static function get_captcha_field_name() {
96 125 return 'Captcha';
97 126 }
98 127
128 + /**
129 + * @return array
130 + */
99 131 public static function pro_field_selection() {
100 - $images_url = FrmAppHelper::plugin_url() . '/images/';
101 - $fields = array(
132 + $upsell_images_url = FrmAppHelper::plugin_url() . '/images/upsell/';
133 + $fields = array(
102 134 'file' => array(
103 - 'name' => __( 'File Upload', 'formidable' ),
104 - 'icon' => 'frm_icon_font frm_upload3_icon',
105 - 'message' => __( 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.', 'formidable' ),
135 + 'name' => __( 'File Upload', 'formidable' ),
136 + 'icon' => 'frmfont frm_upload3_icon',
137 + 'message' => __( 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.', 'formidable' ),
138 + 'upsell_image' => $upsell_images_url . 'file-upload-field-preview.webp',
139 + 'learn-more' => 'features/wordpress-multiple-file-upload-form',
106 140 ),
107 - 'ranking' => array(),
141 + 'ranking' => array(
142 + 'name' => __( 'Ranking', 'formidable' ),
143 + 'icon' => 'frmfont frm_chart_bar_icon frm_show_upgrade',
144 + 'message' => __( 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.', 'formidable' ),
145 + 'upsell_image' => $upsell_images_url . 'ranking-field-preview.webp',
146 + 'addon' => 'surveys',
147 + 'learn-more' => 'ranking-survey',
148 + ),
108 149 'rte' => array(
109 - 'name' => __( 'Rich Text', 'formidable' ),
110 - 'icon' => 'frm_icon_font frm_align_right_icon',
150 + 'name' => __( 'Rich Text', 'formidable' ),
151 + 'icon' => 'frmfont frm_align_right_icon',
152 + 'message' => __( 'Go beyond plain text, let your users format their content with bolding, italics, links, lists and more.', 'formidable' ),
153 + 'upsell_image' => $upsell_images_url . 'rich-text-field-preview.webp',
154 + 'learn-more' => 'rich-text',
111 155 ),
112 156 'date' => array(
113 - 'name' => __( 'Date', 'formidable' ),
114 - 'icon' => 'frm_icon_font frm_calendar2_icon',
157 + 'name' => __( 'Date', 'formidable' ),
158 + 'icon' => 'frmfont frm_calendar2_icon',
159 + 'message' => __( 'Capture exact calendar dates effortlessly with a sleek pop-up date picker, ensuring clarity and consistency for scheduling, tracking deadlines, and more.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
160 + 'upsell_image' => $upsell_images_url . 'date-field-preview.webp',
161 + 'learn-more' => 'date',
115 162 ),
116 163 'time' => array(
117 - 'name' => __( 'Time', 'formidable' ),
118 - 'icon' => 'frm_icon_font frm_clock_icon',
164 + 'name' => __( 'Time', 'formidable' ),
165 + 'icon' => 'frmfont frm_clock_icon',
166 + 'message' => __( 'Precisely log important moments with an intuitive time selection tool, perfect for managing events, availability, or operational hours.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
167 + 'upsell_image' => $upsell_images_url . 'time-field-preview.webp',
168 + 'learn-more' => 'time',
119 169 ),
120 170 'scale' => array(
121 - 'name' => __( 'Scale', 'formidable' ),
122 - 'icon' => 'frm_icon_font frm_linear_scale_icon',
123 - 'message' => esc_html__( 'Add a set of radio buttons with whatever range you choose.', 'formidable' ) . '<img src="' . esc_url( $images_url ) . 'scale_field.png" alt="' . esc_attr__( 'Scale Field', 'formidable' ) . '" />',
171 + 'name' => __( 'Scale', 'formidable' ),
172 + 'icon' => 'frmfont frm_linear_scale_icon',
173 + 'message' => esc_html__( 'Easily measure satisfaction or quantity using a simple, clear numerical scale, giving you fast, quantifiable insights into user feedback.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
174 + 'upsell_image' => $upsell_images_url . 'scale-field-preview.webp',
175 + 'learn-more' => 'scale',
124 176 ),
125 177 'star' => array(
126 - 'name' => __( 'Star Rating', 'formidable' ),
127 - 'icon' => 'frm_icon_font frm_star2_icon',
178 + 'name' => __( 'Star Rating', 'formidable' ),
179 + 'icon' => 'frmfont frm_star2_icon',
180 + 'message' => esc_html__( 'Capture instant, appealing feedback with a familiar visual star system, providing immediate and engaging quality assessments from your users.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
181 + 'upsell_image' => $upsell_images_url . 'star-field-preview.webp',
182 + 'learn-more' => 'star-ratings',
128 183 ),
129 184 'range' => array(
130 - 'name' => __( 'Slider', 'formidable' ),
131 - 'icon' => 'frm_icon_font frm_code_commit_icon',
185 + 'name' => __( 'Slider', 'formidable' ),
186 + 'icon' => 'frmfont frm_code_commit_icon',
187 + 'message' => esc_html__( 'Let users quickly select values within a range using a dynamic, interactive slider, creating a modern and enjoyable data input experience.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
188 + 'upsell_image' => $upsell_images_url . 'slider-field-preview.webp',
189 + 'learn-more' => 'slider',
132 190 ),
133 191 'toggle' => array(
134 - 'name' => __( 'Toggle', 'formidable' ),
135 - 'icon' => 'frm_icon_font frm_toggle_on_icon',
192 + 'name' => __( 'Toggle', 'formidable' ),
193 + 'icon' => 'frmfont frm_toggle_on_icon',
194 + 'message' => esc_html__( 'Quickly and easily create cascading fields, populate fields by search and more.', 'formidable' ),
195 + 'upsell_image' => $upsell_images_url . 'toggle-field-preview.webp',
196 + 'learn-more' => 'toggle',
136 197 ),
137 198 'data' => array(
138 - 'name' => __( 'Dynamic', 'formidable' ),
139 - 'icon' => 'frm_icon_font frm_dynamic_icon',
140 - 'message' => __( 'Create relationships between multiple forms. You can link a member to a team, a rating to a product, a comment to a submission, and much more.', 'formidable' ),
199 + 'name' => __( 'Dynamic', 'formidable' ),
200 + 'icon' => 'frmfont frm_dynamic_icon',
201 + 'message' => __( 'Link entries together, dynamic display information, and even make selections from data entered on another form.', 'formidable' ),
202 + 'upsell_image' => $upsell_images_url . 'dynamic-field-preview.webp',
203 + 'learn-more' => 'dynamic',
141 204 ),
142 205 'lookup' => array(
143 - 'name' => __( 'Lookup', 'formidable' ),
144 - 'icon' => 'frm_icon_font frm_search_icon',
145 - 'message' => esc_html__( 'Filter the options in the next field and automatically add values to other fields. Upgrade to Pro to get Lookup fields and more.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'look-up_year-make-model.gif" alt="' . esc_attr__( 'cascading lookup fields', 'formidable' ) . '" />',
206 + 'name' => __( 'Lookup', 'formidable' ),
207 + 'icon' => 'frmfont frm_search_icon',
208 + 'message' => esc_html__( 'Link entries together, dynamic display information, and even make selections from data entered on another form.', 'formidable' ),
209 + 'upsell_image' => $upsell_images_url . 'lookup-field-preview.webp',
210 + 'learn-more' => 'lookup',
146 211 ),
147 212 'divider|repeat' => array(
148 - 'name' => __( 'Repeater', 'formidable' ),
149 - 'icon' => 'frm_icon_font frm_refresh_icon',
150 - 'message' => esc_html__( 'Allow your visitors to add new sets of fields while filling out forms. Increase conversions while saving building time and server resources.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'repeatable-section_frontend.gif" alt="' . esc_attr__( 'Dynamically Add Form Fields with repeatable sections', 'formidable' ) . '" />',
213 + 'name' => __( 'Repeater', 'formidable' ),
214 + 'icon' => 'frmfont frm_refresh_icon',
215 + 'message' => esc_html__( 'Allow users to add rows of fields dynamically as needed (like for multiple attendees or items), making complex data entry flexible and intuitive.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
216 + 'upsell_image' => $upsell_images_url . 'repeater-field-preview.webp',
217 + 'learn-more' => 'repeatable-section',
151 218 ),
152 219 'end_divider' => array(
153 220 'name' => __( 'Section Buttons', 'formidable' ),
154 221 'switch_from' => 'divider',
@@ -153,37 +220,57 @@
153 220 'name' => __( 'Section Buttons', 'formidable' ),
154 221 'switch_from' => 'divider',
155 222 ),
156 223 'divider' => array(
157 - 'name' => __( 'Section', 'formidable' ),
158 - 'icon' => 'frm_icon_font frm_header_icon',
224 + 'name' => __( 'Section', 'formidable' ),
225 + 'icon' => 'frmfont frm_header_icon',
226 + 'message' => esc_html__( 'Enhance the user experience and improve completion rates by dividing long surveys into clean, manageable steps with distinct pages.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
227 + 'upsell_image' => $upsell_images_url . 'section-field-preview.webp',
228 + 'learn-more' => 'section-heading',
159 229 ),
160 230 'break' => array(
161 - 'name' => __( 'Page Break', 'formidable' ),
162 - 'icon' => 'frm_icon_font frm_page_break_icon',
163 - 'message' => __( 'Get multi-paged forms with progress bars. Did you know you can upgrade to PRO to unlock multi-step forms with more awesome features?', 'formidable' ),
231 + 'name' => __( 'Page Break', 'formidable' ),
232 + 'icon' => 'frmfont frm_page_break_icon',
233 + 'message' => esc_html__( 'Enhance the user experience and improve completion rates by dividing long surveys into clean, manageable steps with distinct pages.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
234 + 'upsell_image' => $upsell_images_url . 'page-break-field-preview.webp',
235 + 'learn-more' => 'page-breaks',
164 236 ),
165 237 'form' => array(
166 - 'name' => __( 'Embed Form', 'formidable' ),
167 - 'icon' => 'frm_icon_font frm_file_text2_icon',
238 + 'name' => __( 'Embed Form', 'formidable' ),
239 + 'icon' => 'frmfont frm_file_text2_icon',
240 + 'message' => esc_html__( 'Seamlessly integrate other existing forms or external content directly inside your current form, creating powerful, interconnected workflows.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
241 + 'upsell_image' => $upsell_images_url . 'embed-form-field-preview.webp',
242 + 'learn-more' => 'embed-form',
168 243 ),
169 244 'likert' => array(
170 - 'name' => __( 'Likert Scale', 'formidable' ),
171 - 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
172 - 'addon' => 'surveys',
245 + 'name' => __( 'Likert Scale', 'formidable' ),
246 + 'icon' => 'frmfont frm_likert_scale frm_show_upgrade',
247 + 'addon' => 'surveys',
248 + 'message' => esc_html__( 'Get nuanced, detailed opinions using standardized agreement scales, unlocking deeper insights beyond simple yes/no answers.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
249 + 'upsell_image' => $upsell_images_url . 'likert-field-preview.webp',
250 + 'learn-more' => 'likert-scale',
173 251 ),
174 252 'nps' => array(
175 - 'name' => __( 'NPS', 'formidable' ),
176 - 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
177 - 'addon' => 'surveys',
253 + 'name' => __( 'NPS', 'formidable' ),
254 + 'icon' => 'frmfont frm_nps frm_show_upgrade',
255 + 'addon' => 'surveys',
256 + 'message' => esc_html__( 'Directly measure customer loyalty with the industry-standard Net Promoter Score® field, giving you a single, vital metric for business growth.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
257 + 'upsell_image' => $upsell_images_url . 'nps-field-preview.webp',
258 + 'learn-more' => 'net-promoter-score',
178 259 ),
179 260 'password' => array(
180 - 'name' => __( 'Password', 'formidable' ),
181 - 'icon' => 'frm_icon_font frm_lock_closed2_icon',
261 + 'name' => __( 'Password', 'formidable' ),
262 + 'icon' => 'frmfont frm_lock_closed2_icon',
263 + 'message' => esc_html__( 'Confidently collect sensitive credentials or create secure sections with a dedicated field that masks input for privacy and security.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
264 + 'upsell_image' => $upsell_images_url . 'password-field-preview.webp',
265 + 'learn-more' => 'password-2',
182 266 ),
183 267 'tag' => array(
184 - 'name' => __( 'Tags', 'formidable' ),
185 - 'icon' => 'frm_icon_font frm_price_tags2_icon',
268 + 'name' => __( 'Tags', 'formidable' ),
269 + 'icon' => 'frmfont frm_price_tags2_icon',
270 + 'message' => esc_html__( 'Facilitate easy categorization and analysis by letting users select or create multiple relevant keywords or labels for their entry.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
271 + 'upsell_image' => $upsell_images_url . 'tags-field-preview.webp',
272 + 'learn-more' => 'tags',
186 273 ),
187 274 // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices.
188 275 // Right now it leaves a gap. Maybe we can skip anything without a name or something.
189 276 'credit_card' => array(
@@ -190,75 +277,96 @@
190 277 'name' => '',
191 278 'icon' => '',
192 279 ),
193 280 'address' => array(
194 - 'name' => __( 'Address', 'formidable' ),
195 - 'icon' => 'frm_icon_font frm_location2_icon',
281 + 'name' => __( 'Address', 'formidable' ),
282 + 'icon' => 'frmfont frm_location2_icon',
283 + 'message' => esc_html__( 'Instantly capture location information, simplifying logistics and contact collection. (Or go further with our Geolocation add-on!)', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
284 + 'upsell_image' => $upsell_images_url . 'address-field-preview.webp',
285 + 'learn-more' => 'address',
196 286 ),
197 287 'summary' => array(
198 - 'name' => __( 'Summary', 'formidable' ),
199 - 'icon' => 'frm_icon_font frm_file_text3_icon',
200 - 'message' => __( 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.', 'formidable' ),
288 + 'name' => __( 'Summary', 'formidable' ),
289 + 'icon' => 'frmfont frm_file_text3_icon',
290 + 'message' => __( 'Provide users with a clean, final review of all their entered data before submission, reducing errors and improving data quality.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
291 + 'upsell_image' => $upsell_images_url . 'summary-field-preview.webp',
292 + 'learn-more' => 'summary-review-before-submit',
201 293 ),
202 294 'signature' => array(
203 - 'name' => __( 'Signature', 'formidable' ),
204 - 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
205 - 'addon' => 'signature',
295 + 'name' => __( 'Signature', 'formidable' ),
296 + 'icon' => 'frmfont frm_signature_icon frm_show_upgrade',
297 + 'addon' => 'signature',
298 + 'message' => __( 'Capture digital e-signatures directly within your form, making official agreements and authorizations straightforward.', 'formidable' ),
299 + 'upsell_image' => $upsell_images_url . 'signature-field-preview.webp',
300 + 'learn-more' => 'formidable-signature',
206 301 ),
207 302 'ai' => array(
208 - 'name' => __( 'AI', 'formidable' ),
209 - 'icon' => 'frm_icon_font frm-ai-icon frm_show_upgrade',
210 - 'addon' => 'ai',
211 - 'message' => __( 'Streamline workflows and reclaim valuable time with the power of AI. You can effortlessly respond to your visitors in real-time with ChatGPT as your automated assistant. Upgrade to Pro and unlock AI-powered fields.', 'formidable' ),
303 + 'name' => __( 'AI', 'formidable' ),
304 + 'icon' => 'frmfont frm-ai-icon frm_show_upgrade',
305 + 'addon' => 'ai',
306 + 'message' => __( 'Harness artificial intelligence by taking user input and let the model of your choice create an output, quickly and easily.', 'formidable' ),
307 + 'upsell_image' => $upsell_images_url . 'ai-field-preview.webp',
308 + 'learn-more' => 'form-ai',
212 309 ),
213 310 'ssa-appointment' => array(
214 - 'name' => __( 'Appointment', 'formidable' ),
215 - 'icon' => 'frm_icon_font frm_schedule_icon frm_show_upgrade',
216 - 'require' => 'Simply Schedule Appointments',
217 - 'message' => sprintf(
311 + 'name' => __( 'Appointment', 'formidable' ),
312 + 'icon' => 'frmfont frm_schedule_icon frm_show_upgrade',
313 + 'require' => 'Simply Schedule Appointments',
314 + 'message' => sprintf(
218 315 /* translators: %1$s: Link opening HTML, %2$s: Link tag closing */
219 - esc_html__( 'Appointment fields are an integration with %1$sSimply Schedule Appointments%2$s. Get started now to schedule appointments directly from your forms.', 'formidable' ),
220 - '<a href="https://simplyscheduleappointments.com/meet/formidable/">',
316 + esc_html__( 'Appointment fields are an integration with %1$sSimply Schedule Appointments%2$s. Get started now to schedule appointments directly from your forms.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
317 + '<a class="frm-inline-flex" href="https://simplyscheduleappointments.com/meet/formidable/" target="_blank" rel="noopener">',
221 318 '</a>'
222 - ) . '<img src="' . esc_url( $images_url ) . 'appointments.png" alt="' . esc_attr__( 'Scheduling', 'formidable' ) . '" />',
223 - 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
319 + ),
320 + 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
321 + 'upsell_image' => $upsell_images_url . 'appointment-field-preview.webp',
322 + 'learn-more' => 'simply-schedule-appointments-forms',
224 323 ),
324 + 'virtual' => array(
325 + 'name' => __( 'Virtual', 'formidable' ),
326 + 'icon' => 'frmfont frm-virtual-field-icon',
327 + 'message' => esc_html__( 'Protect sensitive data by storing field values server-side only, preventing users from viewing or manipulating them in their browser.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
328 + 'upsell_image' => $upsell_images_url . 'virtual-field-preview.webp',
329 + 'learn-more' => '/virtual',
330 + 'is_new' => self::field_is_new( 'virtual' ),
331 + ),
225 332 'product' => array(
226 - 'name' => __( 'Product', 'formidable' ),
227 - 'icon' => 'frm_icon_font frm_product2_icon',
228 - 'section' => 'pricing',
333 + 'name' => __( 'Product', 'formidable' ),
334 + 'icon' => 'frmfont frm_product2_icon',
335 + 'section' => 'pricing',
336 + 'message' => __( 'Turn your form into a simple storefront by adding fields to list products, choose quantities, and calculate totals, enabling direct sales.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
337 + 'upsell_image' => $upsell_images_url . 'product-field-preview.webp',
338 + 'learn-more' => 'features/pricing-fields',
229 339 ),
230 340 'quantity' => array(
231 - 'name' => __( 'Quantity', 'formidable' ),
232 - 'icon' => 'frm_icon_font frm_quantity_icon',
233 - 'section' => 'pricing',
341 + 'name' => __( 'Quantity', 'formidable' ),
342 + 'icon' => 'frmfont frm_quantity_icon',
343 + 'section' => 'pricing',
344 + 'message' => __( 'Turn your form into a simple storefront by adding fields to list products, choose quantities, and calculate totals, enabling direct sales.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
345 + 'upsell_image' => $upsell_images_url . 'quantity-field-preview.webp',
346 + 'learn-more' => 'features/pricing-fields',
234 347 ),
235 348 'total' => array(
236 - 'name' => __( 'Total', 'formidable' ),
237 - 'icon' => 'frm_icon_font frm_total2_icon',
349 + 'name' => __( 'Total', 'formidable' ),
350 + 'icon' => 'frmfont frm_total2_icon',
351 + 'section' => 'pricing',
352 + 'message' => __( 'Turn your form into a simple storefront by adding fields to list products, choose quantities, and calculate totals, enabling direct sales.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
353 + 'upsell_image' => $upsell_images_url . 'total-field-preview.webp',
354 + 'learn-more' => 'features/pricing-fields',
355 + ),
356 + 'coupon' => array(
357 + 'name' => __( 'Coupon', 'formidable' ),
358 + 'icon' => 'frm_icon_font frm_coupon_icon frm_show_upgrade',
359 + 'addon' => 'coupons',
238 360 'section' => 'pricing',
361 + 'limit' => 1,
362 + 'is_new' => self::field_is_new( 'coupon' ),
239 363 ),
240 364 );
241 365
242 - if ( self::include_ranking_fields() ) {
243 - $fields['ranking'] = array(
244 - 'name' => __( 'Ranking', 'formidable' ),
245 - 'icon' => 'frm_icon_font frm_chart_bar_icon frm_show_upgrade',
246 - 'message' => __( 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.', 'formidable' ),
247 - 'upsell_image' => esc_url( $images_url ) . 'ranking-field.svg',
248 - 'addon' => 'surveys',
249 - 'is_new' => self::field_is_new( 'ranking' ),
250 - );
251 - } else {
252 - unset( $fields['ranking'] );
253 - }
254 -
255 - if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
256 - unset( $fields['ai'] );
257 - }
258 -
259 366 // Since the signature field may be in a different section, don't show it twice.
260 367 $lite_fields = self::field_selection();
368 +
261 369 if ( isset( $lite_fields['signature'] ) ) {
262 370 unset( $fields['signature'] );
263 371 }
264 372
@@ -265,96 +373,78 @@
265 373 return apply_filters( 'frm_pro_available_fields', $fields );
266 374 }
267 375
268 376 /**
269 - * Check if we should show ranking fields in the builder.
270 - * This is based on the active version coming from our API data.
271 - * If Surveys v1.1 is not released yet, we don't want to display ranking fields yet.
377 + * Flag Pro field types that require a newer Pro version with frm_show_update.
272 378 *
273 - * @since 6.8.3
379 + * @since 6.29
274 380 *
275 - * @return bool
381 + * @param array $fields Available Pro field types.
382 + *
383 + * @return array
276 384 */
277 - private static function include_ranking_fields() {
278 - if ( class_exists( 'FrmSurveys\models\fields\Ranking' ) ) {
279 - // Always return true if Ranking fields exist.
280 - return true;
385 + public static function show_update_for_pro_fields( $fields ) {
386 + if ( FrmAppHelper::pro_is_installed() && ! class_exists( 'FrmProVirtualFieldController', false ) ) {
387 + $fields['virtual']['icon'] .= ' frm_show_update';
281 388 }
282 389
283 - $plugin = 'formidable-surveys/formidable-surveys.php';
284 - $expected_version = '1.1';
285 -
286 - return self::installed_plugin_meets_version( $plugin, $expected_version ) || self::api_meets_version( $plugin, $expected_version );
390 + return $fields;
287 391 }
288 392
289 393 /**
290 - * @since 6.8.3
394 + * Gets field section labels in the form builder.
291 395 *
292 - * @param string $plugin
293 - * @param string $expected_version
294 - * @return bool
396 + * @since 6.30
397 + *
398 + * @return array
295 399 */
296 - private static function installed_plugin_meets_version( $plugin, $expected_version ) {
297 - $installed_version = self::get_installed_version( $plugin );
298 - return $installed_version && version_compare( $installed_version, $expected_version, '>=' );
400 + public static function field_section_labels() {
401 + return apply_filters(
402 + 'frm_available_field_sections',
403 + array(
404 + 'pricing' => __( 'Pricing Fields', 'formidable' ),
405 + )
406 + );
299 407 }
300 408
301 409 /**
410 + * Consider a field new for 90 days after the release date.
411 + *
302 412 * @since 6.8.3
303 413 *
304 - * @param string $plugin
305 - * @return false|string String version. False if the plugin is not installed.
306 - */
307 - private static function get_installed_version( $plugin ) {
308 - if ( ! function_exists( 'get_plugins' ) ) {
309 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
310 - }
311 - $plugins = get_plugins();
312 - if ( isset( $plugins[ $plugin ] ) && ! empty( $plugins[ $plugin ]['Version'] ) ) {
313 - return $plugins[ $plugin ]['Version'];
314 - }
315 - return false;
316 - }
317 -
318 - /**
319 - * @since 6.8.3
414 + * @param string $type
320 415 *
321 - * @param string $plugin
322 - * @param string $expected_version
323 416 * @return bool
324 417 */
325 - private static function api_meets_version( $plugin, $expected_version ) {
326 - $api = new FrmFormApi();
327 - $addons = $api->get_api_info();
328 - $matches = wp_list_filter( $addons, array( 'plugin' => $plugin ) );
329 - if ( ! $matches ) {
330 - return false;
331 - }
418 + private static function field_is_new( $type ) {
419 + $release_dates = array(
420 + 'virtual' => '2026-03-10',
421 + );
332 422
333 - $match = reset( $matches );
334 - if ( empty( $match['new_version'] ) ) {
423 + if ( ! isset( $release_dates[ $type ] ) ) {
335 424 return false;
336 425 }
337 426
338 - $api_version = $match['new_version'];
339 - return version_compare( $api_version, $expected_version, '>=' );
427 + $release_date = $release_dates[ $type ];
428 + $three_months_after_release = gmdate( 'Y-m-d', strtotime( $release_date . ' + 90 days' ) );
429 + return gmdate( 'Y-m-d' ) < $three_months_after_release;
340 430 }
341 431
342 432 /**
343 - * Consider a field new for 90 days after the release date.
433 + * Remove field types that are moved from Pro to Lite.
344 434 *
345 - * @since 6.8.3
435 + * @since 6.30
346 436 *
347 - * @param string $type
348 - * @return bool
437 + * @param array $pro_fields
438 + *
439 + * @return void
349 440 */
350 - private static function field_is_new( $type ) {
351 - if ( 'ranking' === $type ) {
352 - $ranking_release_date = '2024-03-12';
353 - $three_months_after_release = gmdate( 'Y-m-d', strtotime( $ranking_release_date . ' + 90 days' ) );
354 - return gmdate( 'Y-m-d' ) < $three_months_after_release;
355 - }
356 - return false;
441 + public static function remove_moved_field_types_from_pro( &$pro_fields ) {
442 + unset( $pro_fields['credit_card'] );
443 + unset( $pro_fields['product'] );
444 + unset( $pro_fields['quantity'] );
445 + unset( $pro_fields['total'] );
446 + unset( $pro_fields['address'] );
357 447 }
358 448
359 449 /**
360 450 * @since 4.0
@@ -361,10 +451,9 @@
361 451 *
362 452 * @return array
363 453 */
364 454 public static function all_field_selection() {
365 - $pro_field_selection = self::pro_field_selection();
366 - return array_merge( $pro_field_selection, self::field_selection() );
455 + return array_merge( self::pro_field_selection(), self::field_selection() );
367 456 }
368 457
369 458 /**
370 459 * Create a field.
@@ -370,8 +459,9 @@
370 459 * Create a field.
371 460 *
372 461 * @param array $values
373 462 * @param bool $return
463 + *
374 464 * @return false|int
375 465 */
376 466 public static function create( $values, $return = true ) {
377 467 global $wpdb, $frm_duplicate_ids;
@@ -387,13 +477,19 @@
387 477 $new_values[ $col ] = $values[ $col ];
388 478 }
389 479 }
390 480
391 - $new_values['options'] = self::maybe_filter_options( $values['options'] );
481 + // Both option columns are stored serialized, but they do not accept the same shapes.
482 + // Choice fields pass options already serialized, as does FrmFieldsHelper::fill_field
483 + // when a field is duplicated, and fields with no choices pass an empty string, so a
484 + // missing key is the only thing worth defaulting. An is_array check here would throw
485 + // every one of those defaults away. field_options is always an array, so anything
486 + // else is invalid input, and replacing it stops consumers getting null.
487 + $new_values['options'] = self::maybe_filter_options( $values['options'] ?? array() );
392 488 $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
393 489 $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
394 490 $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
395 - $new_values['field_options'] = $values['field_options'];
491 + $new_values['field_options'] = isset( $values['field_options'] ) && is_array( $values['field_options'] ) ? $values['field_options'] : array();
396 492 $new_values['created_at'] = current_time( 'mysql', 1 );
397 493
398 494 if ( isset( $values['id'] ) ) {
399 495 $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
@@ -403,13 +499,9 @@
403 499 self::preserve_format_option_backslashes( $new_values );
404 500
405 501 foreach ( $new_values as $k => $v ) {
406 502 if ( is_array( $v ) ) {
407 - if ( $k === 'default_value' ) {
408 - $new_values[ $k ] = FrmAppHelper::maybe_json_encode( $v );
409 - } else {
410 - $new_values[ $k ] = serialize( $v );
411 - }
503 + $new_values[ $k ] = $k === 'default_value' ? FrmAppHelper::maybe_json_encode( $v ) : serialize( $v );
412 504 }
413 505 unset( $k, $v );
414 506 }
415 507
@@ -419,14 +511,15 @@
419 511 return false;
420 512 }
421 513
422 514 self::delete_form_transient( $new_values['form_id'] );
423 - $new_id = $wpdb->insert_id;
424 515
425 516 if ( ! $return ) {
426 517 return false;
427 518 }
428 519
520 + $new_id = $wpdb->insert_id;
521 +
429 522 if ( isset( $values['id'] ) ) {
430 523 $frm_duplicate_ids[ $values['id'] ] = $new_id;
431 524 }
432 525
@@ -439,9 +532,10 @@
439 532 * See FrmAppHelper::allow_unfiltered_html.
440 533 *
441 534 * @since 5.0.08
442 535 *
443 - * @param array $options
536 + * @param array|string $options Already serialized for choice fields, and an empty string for fields with no choices.
537 + *
444 538 * @return array
445 539 */
446 540 private static function maybe_filter_options( $options ) {
447 541 $options = FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
@@ -463,8 +557,9 @@
463 557 *
464 558 * @since 6.11.2
465 559 *
466 560 * @param string $html
561 + *
467 562 * @return string
468 563 */
469 564 private static function maybe_filter_custom_html_input_attributes( $html ) {
470 565 if ( FrmAppHelper::allow_unfiltered_html() ) {
@@ -475,8 +570,9 @@
475 570 return preg_replace_callback(
476 571 "/$pattern/",
477 572 /**
478 573 * @param array $match Shortcode data.
574 + *
479 575 * @return string
480 576 */
481 577 function ( $match ) {
482 578 $attr = shortcode_parse_atts( $match[3] );
@@ -486,27 +582,30 @@
486 582 return '[input]';
487 583 }
488 584
489 585 $safe_atts = array();
586 +
490 587 foreach ( $attr as $attr_key => $att ) {
491 - if ( ! is_numeric( $attr_key ) ) {
492 - // opt=1 without parentheses for example is mapped like 'opt' => 1.
493 - $key = $attr_key;
494 - $value = $att;
495 - } else {
588 + if ( is_numeric( $attr_key ) ) {
496 589 // Some data is mapped like 0 => 'placeholder="Placeholder"'.
497 590 $split = explode( '=', $att, 2 );
591 +
498 592 if ( 2 !== count( $split ) ) {
499 593 continue;
500 594 }
595 +
501 596 $key = trim( $split[0] );
502 597 $value = trim( $split[1], '"' );
598 + } else {
599 + // opt=1 without parentheses for example is mapped like 'opt' => 1.
600 + $key = $attr_key;
601 + $value = $att;
503 602 }
504 603
505 604 if ( FrmAppHelper::input_key_is_safe( $key, 'update' ) ) {
506 605 $safe_atts[ $key ] = $value;
507 606 }
508 - }
607 + }//end foreach
509 608
510 609 if ( ! $safe_atts ) {
511 610 return '[input]';
512 611 }
@@ -520,11 +619,17 @@
520 619 /**
521 620 * Process the field duplication.
522 621 *
523 622 * @since 5.0.05
623 + *
624 + * @param int|string $field_id Field ID.
625 + * @param int|string $form_id Form ID.
626 + *
627 + * @return array|false
524 628 */
525 629 public static function duplicate_single_field( $field_id, $form_id ) {
526 630 $copy_field = self::getOne( $field_id );
631 +
527 632 if ( ! $copy_field ) {
528 633 return false;
529 634 }
530 635
@@ -534,10 +639,9 @@
534 639 $values = array(
535 640 'id' => $copy_field->id,
536 641 );
537 642 FrmFieldsHelper::fill_field( $values, $copy_field, $copy_field->form_id );
538 - $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
539 -
643 + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
540 644 $field_id = self::create( $values );
541 645
542 646 /**
543 647 * Fires after duplicating a field.
@@ -557,8 +661,16 @@
557 661
558 662 return compact( 'field_id', 'values' );
559 663 }
560 664
665 + /**
666 + * @param int|string $old_form_id
667 + * @param int|string $form_id
668 + * @param bool $copy_keys
669 + * @param false|int $blog_id
670 + *
671 + * @return void
672 + */
561 673 public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
562 674 global $frm_duplicate_ids;
563 675
564 676 $where = array(
@@ -571,8 +683,10 @@
571 683 $fields = self::getAll( $where, 'field_order', '', $blog_id );
572 684
573 685 foreach ( (array) $fields as $field ) {
574 686 $new_key = $copy_keys ? $field->field_key : '';
687 +
688 + // phpcs:ignore Universal.Operators.StrictComparisons
575 689 if ( $copy_keys && substr( $field->field_key, - 1 ) == 2 ) {
576 690 $new_key = rtrim( $new_key, 2 );
577 691 }
578 692
@@ -580,9 +694,9 @@
580 694 FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
581 695
582 696 // If this is a repeating section, create new form
583 697 if ( self::is_repeating_field( $field ) ) {
584 - // create the repeatable form
698 + // Create the repeatable form
585 699 $new_repeat_form_id = apply_filters(
586 700 'frm_create_repeat_form',
587 701 0,
588 702 array(
@@ -598,9 +712,9 @@
598 712 $values['field_options']['form_select'] = $new_repeat_form_id;
599 713 }
600 714
601 715 // If this is a field inside of a repeating section, associate it with the correct form
602 - if ( $field->form_id != $old_form_id && isset( $old_repeat_form_id ) && isset( $new_repeat_form_id ) && $field->form_id == $old_repeat_form_id ) {
716 + if ( (int) $field->form_id !== (int) $old_form_id && isset( $old_repeat_form_id ) && isset( $new_repeat_form_id ) && (int) $field->form_id === (int) $old_repeat_form_id ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
603 717 $values['form_id'] = $new_repeat_form_id;
604 718 }
605 719
606 720 $values['description'] = FrmFieldsHelper::switch_field_ids( $values['description'] );
@@ -615,8 +729,9 @@
615 729
616 730 /**
617 731 * @param int|string $id
618 732 * @param array $values
733 + *
619 734 * @return false|int
620 735 */
621 736 public static function update( $id, $values ) {
622 737 global $wpdb;
@@ -649,33 +764,38 @@
649 764 */
650 765 $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
651 766
652 767 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
653 - // don't keep the old placeholder setting for hidden fields
768 + // Don't keep the old placeholder setting for hidden fields
654 769 $values['field_options']['clear_on_focus'] = 0;
655 770 }
656 771 }
657 772
658 - // serialize array values
773 + // Serialize array values
659 774 foreach ( array( 'field_options', 'options' ) as $opt ) {
660 - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
661 - if ( 'field_options' === $opt ) {
662 - $values[ $opt ] = self::maybe_filter_options( $values[ $opt ] );
663 - }
664 - $values[ $opt ] = serialize( $values[ $opt ] );
775 + if ( ! isset( $values[ $opt ] ) || ! is_array( $values[ $opt ] ) ) {
776 + continue;
665 777 }
778 +
779 + if ( 'field_options' === $opt ) {
780 + $values[ $opt ] = self::maybe_filter_options( $values[ $opt ] );
781 + }
782 +
783 + $values[ $opt ] = serialize( $values[ $opt ] );
666 784 }
785 +
667 786 if ( isset( $values['default_value'] ) && is_array( $values['default_value'] ) ) {
668 787 $values['default_value'] = json_encode( $values['default_value'] );
669 788 }
670 789
671 790 $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
791 + $form_id = 0;
672 792
673 - $form_id = 0;
674 793 if ( isset( $values['form_id'] ) ) {
675 794 $form_id = absint( $values['form_id'] );
676 795 } else {
677 796 $field = self::getOne( $id );
797 +
678 798 if ( $field ) {
679 799 $form_id = $field->form_id;
680 800 }
681 801 unset( $field );
@@ -683,8 +803,9 @@
683 803 unset( $values );
684 804
685 805 if ( $query_results ) {
686 806 wp_cache_delete( $id, 'frm_field' );
807 +
687 808 if ( $form_id ) {
688 809 self::delete_form_transient( $form_id );
689 810 }
690 811 }
@@ -697,8 +818,10 @@
697 818 *
698 819 * @since 2.0.8
699 820 *
700 821 * @param array $values Pass by reference.
822 + *
823 + * @return void
701 824 */
702 825 private static function preserve_format_option_backslashes( &$values ) {
703 826 if ( isset( $values['field_options']['format'] ) ) {
704 827 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -704,8 +827,13 @@
704 827 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
705 828 }
706 829 }
707 830
831 + /**
832 + * @param int|string $id
833 + *
834 + * @return bool|int
835 + */
708 836 public static function destroy( $id ) {
709 837 global $wpdb;
710 838
711 839 do_action( 'frm_before_destroy_field', $id );
@@ -711,8 +839,9 @@
711 839 do_action( 'frm_before_destroy_field', $id );
712 840
713 841 wp_cache_delete( $id, 'frm_field' );
714 842 $field = self::getOne( $id );
843 +
715 844 if ( ! $field ) {
716 845 return false;
717 846 }
718 847
@@ -722,8 +851,13 @@
722 851
723 852 return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
724 853 }
725 854
855 + /**
856 + * @param int|string $form_id
857 + *
858 + * @return void
859 + */
726 860 public static function delete_form_transient( $form_id ) {
727 861 $form_id = absint( $form_id );
728 862 delete_transient( 'frm_form_fields_' . $form_id . 'excludeinclude' );
729 863 delete_transient( 'frm_form_fields_' . $form_id . 'includeinclude' );
@@ -730,14 +864,15 @@
730 864 delete_transient( 'frm_form_fields_' . $form_id . 'includeexclude' );
731 865 delete_transient( 'frm_form_fields_' . $form_id . 'excludeexclude' );
732 866
733 867 global $wpdb;
734 - $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) );
868 + $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
735 869
736 870 FrmDb::cache_delete_group( 'frm_field' );
737 871
738 872 $form = FrmForm::getOne( $form_id );
739 - if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
873 +
874 + if ( $form && $form->parent_form_id && (int) $form->parent_form_id !== $form_id ) {
740 875 self::delete_form_transient( $form->parent_form_id );
741 876 }
742 877 }
743 878
@@ -744,8 +879,9 @@
744 879 /**
745 880 * If $field is numeric, get the field object
746 881 *
747 882 * @param int|object|string $field
883 + *
748 884 * @return void
749 885 */
750 886 public static function maybe_get_field( &$field ) {
751 887 if ( ! is_object( $field ) ) {
@@ -755,11 +891,13 @@
755 891
756 892 /**
757 893 * @param int|string $id The field id or key.
758 894 * @param bool $filter When true, run the frm_field filter.
895 + *
896 + * @return object|null
759 897 */
760 898 public static function getOne( $id, $filter = false ) {
761 - if ( empty( $id ) ) {
899 + if ( ! $id ) {
762 900 return null;
763 901 }
764 902
765 903 global $wpdb;
@@ -768,9 +906,9 @@
768 906 $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
769 907
770 908 $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
771 909
772 - if ( empty( $results ) ) {
910 + if ( ! $results ) {
773 911 self::filter_field( $filter, $results );
774 912 return $results;
775 913 }
776 914
@@ -787,10 +925,13 @@
787 925 }
788 926
789 927 /**
790 928 * @since 3.06.01
929 + *
791 930 * @param bool $filter When true, run the frm_field filter.
792 931 * @param object $results
932 + *
933 + * @return void
793 934 */
794 935 private static function filter_field( $filter, &$results ) {
795 936 if ( $filter ) {
796 937 /**
@@ -804,23 +945,21 @@
804 945 * Get the field type by key or id
805 946 *
806 947 * @param int|string $id The field id or key.
807 948 * @param mixed $col The name of the column in the fields database table.
949 + *
950 + * @return mixed
808 951 */
809 952 public static function get_type( $id, $col = 'type' ) {
810 953 $field = FrmDb::check_cache( $id, 'frm_field' );
954 +
811 955 if ( $field ) {
812 - $type = $field->{$col};
813 - } else {
814 - if ( is_numeric( $id ) ) {
815 - $where = array( 'id' => $id );
816 - } else {
817 - $where = array( 'field_key' => $id );
818 - }
819 - $type = FrmDb::get_var( 'frm_fields', $where, $col );
956 + return $field->{$col};
820 957 }
821 958
822 - return $type;
959 + $where = is_numeric( $id ) ? array( 'id' => $id ) : array( 'field_key' => $id );
960 +
961 + return FrmDb::get_var( 'frm_fields', $where, $col );
823 962 }
824 963
825 964 /**
826 965 * @param int|string $form_id
@@ -826,8 +965,10 @@
826 965 * @param int|string $form_id
827 966 * @param string $type
828 967 * @param int|string $limit
829 968 * @param string $inc_sub
969 + *
970 + * @return array|object
830 971 */
831 972 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
832 973 if ( ! $form_id ) {
833 974 return array();
@@ -839,24 +980,28 @@
839 980 'inc_embed' => $inc_sub,
840 981 'inc_repeat' => $inc_sub,
841 982 )
842 983 );
843 - if ( ! empty( $results ) ) {
984 +
985 + if ( $results ) {
844 986 $fields = array();
845 987 $count = 0;
988 +
846 989 foreach ( $results as $result ) {
847 - if ( $type != $result->type ) {
990 + if ( $type !== $result->type ) {
848 991 continue;
849 992 }
850 993
851 994 $fields[ $result->id ] = $result;
852 995 ++$count;
996 +
997 + // phpcs:ignore Universal.Operators.StrictComparisons
853 998 if ( $limit == 1 ) {
854 999 $fields = $result;
855 1000 break;
856 1001 }
857 1002
858 - if ( ! empty( $limit ) && $count >= $limit ) {
1003 + if ( $limit && $count >= $limit ) {
859 1004 break;
860 1005 }
861 1006
862 1007 unset( $result );
@@ -883,8 +1028,9 @@
883 1028 * @param int|string $form_id
884 1029 * @param int|string $limit
885 1030 * @param string $inc_embed
886 1031 * @param string $inc_repeat
1032 + *
887 1033 * @return array
888 1034 */
889 1035 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
890 1036 if ( ! (int) $form_id ) {
@@ -891,19 +1037,22 @@
891 1037 return array();
892 1038 }
893 1039
894 1040 $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) );
895 - if ( ! empty( $results ) ) {
896 - if ( empty( $limit ) ) {
1041 +
1042 + if ( $results ) {
1043 + if ( ! $limit ) {
897 1044 return $results;
898 1045 }
899 1046
900 1047 $fields = array();
901 1048 $count = 0;
1049 +
902 1050 foreach ( $results as $result ) {
903 1051 ++$count;
904 1052 $fields[ $result->id ] = $result;
905 - if ( ! empty( $limit ) && $count >= $limit ) {
1053 +
1054 + if ( $limit && $count >= $limit ) {
906 1055 break;
907 1056 }
908 1057 }
909 1058
@@ -919,9 +1068,9 @@
919 1068 self::$use_cache = true;
920 1069
921 1070 self::include_sub_fields( $results, $inc_embed, 'all', $form_id );
922 1071
923 - if ( empty( $limit ) ) {
1072 + if ( ! $limit ) {
924 1073 self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) );
925 1074 }
926 1075
927 1076 return $results;
@@ -931,36 +1080,51 @@
931 1080 * If repeating fields should be included, adjust $where accordingly
932 1081 *
933 1082 * @param string $inc_repeat
934 1083 * @param array $where Pass by reference.
1084 + *
1085 + * @return void
935 1086 */
936 1087 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
937 - if ( $inc_repeat === 'include' ) {
938 - $form_id = $where['fi.form_id'];
939 - $where[] = array(
940 - 'or' => 1,
941 - 'fi.form_id' => $form_id,
942 - 'fr.parent_form_id' => $form_id,
943 - );
944 - unset( $where['fi.form_id'] );
1088 + if ( $inc_repeat !== 'include' ) {
1089 + return;
945 1090 }
1091 +
1092 + $form_id = $where['fi.form_id'];
1093 + $where[] = array(
1094 + 'or' => 1,
1095 + 'fi.form_id' => $form_id,
1096 + 'fr.parent_form_id' => $form_id,
1097 + );
1098 + unset( $where['fi.form_id'] );
946 1099 }
947 1100
1101 + /**
1102 + * @param array $results
1103 + * @param string $inc_embed
1104 + * @param string $type
1105 + * @param int|string $form_id
1106 + *
1107 + * @return void
1108 + */
948 1109 public static function include_sub_fields( &$results, $inc_embed, $type = 'all', $form_id = '' ) {
949 - $no_sub_forms = empty( $results ) && $type === 'all';
950 - if ( 'include' != $inc_embed || $no_sub_forms ) {
1110 + $no_sub_forms = ! $results && $type === 'all';
1111 +
1112 + if ( 'include' !== $inc_embed || $no_sub_forms ) {
951 1113 return;
952 1114 }
953 1115
954 1116 $form_fields = $results;
955 - $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
1117 + $should_get_subforms = $type !== 'all' && $type !== 'form' && $form_id;
1118 +
956 1119 if ( $should_get_subforms ) {
957 1120 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
958 1121 }
959 1122
960 1123 $index_offset = 1;
1124 +
961 1125 foreach ( $form_fields as $k => $field ) {
962 - if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
1126 + if ( 'form' !== $field->type || ! isset( $field->field_options['form_select'] ) ) {
963 1127 continue;
964 1128 }
965 1129
966 1130 if ( $type === 'all' ) {
@@ -977,13 +1141,23 @@
977 1141 unset( $field, $sub_fields );
978 1142 }
979 1143 }
980 1144
1145 + /**
1146 + * @param array|string $where
1147 + * @param string $order_by
1148 + * @param string $limit
1149 + * @param false|int $blog_id
1150 + *
1151 + * @return array|object|null
1152 + */
981 1153 public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
982 1154 $cache_key = FrmAppHelper::maybe_json_encode( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
1155 +
983 1156 if ( self::$use_cache ) {
984 - // make sure old cache doesn't get saved as a transient
1157 + // Make sure old cache doesn't get saved as a transient
985 1158 $results = wp_cache_get( $cache_key, 'frm_field' );
1159 +
986 1160 if ( false !== $results ) {
987 1161 return wp_unslash( $results );
988 1162 }
989 1163 }
@@ -990,15 +1164,9 @@
990 1164
991 1165 global $wpdb;
992 1166
993 1167 if ( $blog_id && is_multisite() ) {
994 - global $wpmuBaseTablePrefix;
995 - if ( $wpmuBaseTablePrefix ) {
996 - $prefix = $wpmuBaseTablePrefix . $blog_id . '_';
997 - } else {
998 - $prefix = $wpdb->get_blog_prefix( $blog_id );
999 - }
1000 -
1168 + $prefix = $wpdb->get_blog_prefix( $blog_id );
1001 1169 $table_name = $prefix . 'frm_fields';
1002 1170 $form_table_name = $prefix . 'frm_forms';
1003 1171 } else {
1004 1172 $table_name = $wpdb->prefix . 'frm_fields';
@@ -1004,16 +1172,15 @@
1004 1172 $table_name = $wpdb->prefix . 'frm_fields';
1005 1173 $form_table_name = $wpdb->prefix . 'frm_forms';
1006 1174 }
1007 1175
1008 - if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
1176 + if ( $order_by && ! str_contains( $order_by, 'ORDER BY' ) ) {
1009 1177 $order_by = ' ORDER BY ' . $order_by;
1010 1178 }
1011 1179
1012 - $limit = FrmDb::esc_limit( $limit );
1013 -
1180 + $limit = FrmDb::esc_limit( $limit );
1014 1181 $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi JOIN {$form_table_name} fr ON fi.form_id=fr.id";
1015 - $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
1182 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results'; // phpcs:ignore Universal.Operators.StrictComparisons
1016 1183
1017 1184 if ( is_array( $where ) ) {
1018 1185 $args = array(
1019 1186 'order_by' => $order_by,
@@ -1020,9 +1187,9 @@
1020 1187 'limit' => $limit,
1021 1188 );
1022 1189 $results = FrmDb::get_var( $table_name . ' fi JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', $args, '', $query_type );
1023 1190 } else {
1024 - // if the query is not an array, then it has already been prepared
1191 + // If the query is not an array, then it has already been prepared
1025 1192 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
1026 1193
1027 1194 $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
1028 1195 $results = $wpdb->$function_name( $query );
@@ -1037,8 +1204,12 @@
1037 1204 }
1038 1205
1039 1206 /**
1040 1207 * @since 2.0.8
1208 + *
1209 + * @param array|object|null $results Results.
1210 + *
1211 + * @return void
1041 1212 */
1042 1213 private static function format_field_results( &$results ) {
1043 1214 if ( is_array( $results ) ) {
1044 1215 foreach ( $results as $r_key => $result ) {
@@ -1069,8 +1240,9 @@
1069 1240 *
1070 1241 * @since 6.15
1071 1242 *
1072 1243 * @param stdClass $result
1244 + *
1073 1245 * @return void
1074 1246 */
1075 1247 private static function add_slashes_to_format_before_setting_field_cache( $result ) {
1076 1248 if ( ! isset( $result->field_options ) || ! is_array( $result->field_options ) || empty( $result->field_options['format'] ) ) {
@@ -1083,8 +1255,12 @@
1083 1255 /**
1084 1256 * Unserialize all the serialized field data
1085 1257 *
1086 1258 * @since 2.0
1259 + *
1260 + * @param object $results
1261 + *
1262 + * @return void
1087 1263 */
1088 1264 private static function prepare_options( &$results ) {
1089 1265 FrmAppHelper::unserialize_or_decode( $results->field_options );
1090 1266 FrmAppHelper::unserialize_or_decode( $results->options );
@@ -1093,14 +1269,17 @@
1093 1269 $before = $results->default_value;
1094 1270
1095 1271 $field_object = FrmFieldFactory::get_field_type( $results->type );
1096 1272
1097 - if ( $field_object->should_unserialize_value() ) {
1098 - FrmAppHelper::unserialize_or_decode( $results->default_value );
1099 - if ( $before === $results->default_value && is_string( $before ) && strpos( $before, '["' ) === 0 ) {
1100 - $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
1101 - }
1273 + if ( ! $field_object->should_unserialize_value() ) {
1274 + return;
1102 1275 }
1276 +
1277 + FrmAppHelper::unserialize_or_decode( $results->default_value );
1278 +
1279 + if ( $before === $results->default_value && is_string( $before ) && str_starts_with( $before, '["' ) ) {
1280 + $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
1281 + }
1103 1282 }
1104 1283
1105 1284 /**
1106 1285 * If a form has too many fields, they won't all save into a single transient.
@@ -1106,8 +1285,13 @@
1106 1285 * If a form has too many fields, they won't all save into a single transient.
1107 1286 * We'll break them into groups of 200
1108 1287 *
1109 1288 * @since 2.0.1
1289 + *
1290 + * @param int|string $form_id Form ID.
1291 + * @param array $args Additional arguments.
1292 + *
1293 + * @return array
1110 1294 */
1111 1295 private static function get_fields_from_transients( $form_id, $args ) {
1112 1296 $fields = array();
1113 1297 self::get_next_transient( $fields, 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'] );
@@ -1118,22 +1302,32 @@
1118 1302 /**
1119 1303 * Called by get_fields_from_transients
1120 1304 *
1121 1305 * @since 2.0.1
1306 + *
1307 + * @param array $fields Array of fields.
1308 + * @param string $base_name Base name.
1309 + * @param int $next Next transient number.
1310 + *
1311 + * @return void
1122 1312 */
1123 1313 private static function get_next_transient( &$fields, $base_name, $next = 0 ) {
1124 1314 $name = $next ? $base_name . $next : $base_name;
1125 1315 $next_fields = get_transient( $name );
1126 1316
1127 - if ( $next_fields ) {
1128 - $fields = array_merge( $fields, $next_fields );
1317 + if ( ! $next_fields ) {
1318 + return;
1319 + }
1129 1320
1130 - if ( count( $next_fields ) >= self::$transient_size ) {
1131 - // if this transient is full, check for another
1132 - ++$next;
1133 - self::get_next_transient( $fields, $base_name, $next );
1134 - }
1321 + $fields = array_merge( $fields, $next_fields );
1322 +
1323 + if ( count( $next_fields ) < self::$transient_size ) {
1324 + return;
1135 1325 }
1326 +
1327 + // If this transient is full, check for another
1328 + ++$next;
1329 + self::get_next_transient( $fields, $base_name, $next );
1136 1330 }
1137 1331
1138 1332 /**
1139 1333 * Save the transients in chunks for large forms
@@ -1138,8 +1332,15 @@
1138 1332 /**
1139 1333 * Save the transients in chunks for large forms
1140 1334 *
1141 1335 * @since 2.0.1
1336 + *
1337 + * @param array $fields Array of fields.
1338 + * @param int|string $form_id Form ID.
1339 + * @param int $next Next transient number.
1340 + * @param array $args Additional arguments.
1341 + *
1342 + * @return void
1142 1343 */
1143 1344 private static function set_field_transient( &$fields, $form_id, $next = 0, $args = array() ) {
1144 1345 $base_name = 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'];
1145 1346 $field_chunks = array_chunk( $fields, self::$transient_size );
@@ -1146,12 +1347,13 @@
1146 1347
1147 1348 foreach ( $field_chunks as $field ) {
1148 1349 $name = $next ? $base_name . $next : $base_name;
1149 1350 $set = set_transient( $name, $field, 60 * 60 * 6 );
1351 +
1150 1352 if ( ! $set ) {
1151 - // the transient didn't save
1152 - if ( $name != $base_name ) {
1153 - // if the first saved an others fail, this will show an incomplete form
1353 + // The transient didn't save
1354 + if ( $name !== $base_name ) {
1355 + // If the first saved an others fail, this will show an incomplete form
1154 1356 self::delete_form_transient( $form_id );
1155 1357 }
1156 1358
1157 1359 return;
@@ -1162,8 +1364,9 @@
1162 1364 }
1163 1365
1164 1366 /**
1165 1367 * @param string $type
1368 + *
1166 1369 * @return bool
1167 1370 */
1168 1371 public static function is_no_save_field( $type ) {
1169 1372 return in_array( $type, self::no_save_fields(), true );
@@ -1191,20 +1394,16 @@
1191 1394 }
1192 1395
1193 1396 $field_type = self::get_original_field_type( $field );
1194 1397
1195 - $is_multi_value_field = (
1196 - self::is_checkbox( $field ) ||
1197 - $field_type === 'address' ||
1198 - self::is_multiple_select( $field )
1199 - );
1200 -
1201 - return $is_multi_value_field;
1398 + return self::is_checkbox( $field ) || $field_type === 'address' || self::is_multiple_select( $field );
1202 1399 }
1203 1400
1204 1401 /**
1205 1402 * @since 3.0
1403 + *
1206 1404 * @param array|object $field
1405 + *
1207 1406 * @return string
1208 1407 */
1209 1408 public static function get_field_type( $field ) {
1210 1409 return is_array( $field ) ? $field['type'] : $field->type;
@@ -1211,8 +1410,11 @@
1211 1410 }
1212 1411
1213 1412 /**
1214 1413 * @since 3.0
1414 + *
1415 + * @param array|object $field
1416 + *
1215 1417 * @return string
1216 1418 */
1217 1419 public static function get_original_field_type( $field ) {
1218 1420 $field_type = self::get_field_type( $field );
@@ -1217,11 +1419,11 @@
1217 1419 public static function get_original_field_type( $field ) {
1218 1420 $field_type = self::get_field_type( $field );
1219 1421 $original_type = self::get_option( $field, 'original_type' );
1220 1422
1221 - if ( ! empty( $original_type ) && $original_type != $field_type ) {
1423 + if ( $original_type && $original_type !== $field_type ) {
1222 1424 // Check the original type for arrays.
1223 - $field_type = $original_type;
1425 + return $original_type;
1224 1426 }
1225 1427
1226 1428 return $field_type;
1227 1429 }
@@ -1229,14 +1431,15 @@
1229 1431 /**
1230 1432 * Check if this is a multiselect dropdown field
1231 1433 *
1232 1434 * @since 2.0.9
1435 + *
1436 + * @param array|object $field Field object.
1437 + *
1233 1438 * @return bool
1234 1439 */
1235 1440 public static function is_multiple_select( $field ) {
1236 - $field_type = self::get_field_type( $field );
1237 - $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
1238 -
1441 + $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && self::get_field_type( $field ) !== 'hidden';
1239 1442 return apply_filters( 'frm_is_multiple_select', $is_multiple, $field );
1240 1443 }
1241 1444
1242 1445 /**
@@ -1245,8 +1448,9 @@
1245 1448 *
1246 1449 * @since 2.0.9
1247 1450 *
1248 1451 * @param array|object $field
1452 + *
1249 1453 * @return bool
1250 1454 */
1251 1455 public static function is_read_only( $field ) {
1252 1456 global $frm_vars;
@@ -1256,20 +1460,19 @@
1256 1460 /**
1257 1461 * @since 2.0.9
1258 1462 *
1259 1463 * @param array $field
1464 + *
1260 1465 * @return bool
1261 1466 */
1262 1467 public static function is_required( $field ) {
1263 - $required = $field['required'] != '0';
1468 + $required = $field['required'] != '0'; // phpcs:ignore Universal.Operators.StrictComparisons
1264 1469
1265 1470 /**
1266 1471 * @param bool $required
1267 1472 * @param array $field
1268 1473 */
1269 - $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1270 -
1271 - return $required;
1474 + return (bool) apply_filters( 'frm_is_field_required', $required, $field );
1272 1475 }
1273 1476
1274 1477 /**
1275 1478 * @since 2.0.9
@@ -1275,8 +1478,9 @@
1275 1478 * @since 2.0.9
1276 1479 *
1277 1480 * @param array|object $field
1278 1481 * @param string $option
1482 + *
1279 1483 * @return bool
1280 1484 */
1281 1485 public static function is_option_true( $field, $option ) {
1282 1486 if ( is_array( $field ) ) {
@@ -1289,8 +1493,9 @@
1289 1493 * @since 2.0.9
1290 1494 *
1291 1495 * @param array|object $field
1292 1496 * @param string $option
1497 + *
1293 1498 * @return bool
1294 1499 */
1295 1500 public static function is_option_empty( $field, $option ) {
1296 1501 if ( is_array( $field ) ) {
@@ -1301,8 +1506,9 @@
1301 1506
1302 1507 /**
1303 1508 * @param array $field
1304 1509 * @param string $option
1510 + *
1305 1511 * @return bool
1306 1512 */
1307 1513 public static function is_option_true_in_array( $field, $option ) {
1308 1514 return ! empty( $field[ $option ] );
@@ -1310,17 +1516,19 @@
1310 1516
1311 1517 /**
1312 1518 * @param object $field
1313 1519 * @param string $option
1520 + *
1314 1521 * @return bool
1315 1522 */
1316 1523 public static function is_option_true_in_object( $field, $option ) {
1317 - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1524 + return ! empty( $field->field_options[ $option ] );
1318 1525 }
1319 1526
1320 1527 /**
1321 1528 * @param array $field
1322 1529 * @param string $option
1530 + *
1323 1531 * @return bool
1324 1532 */
1325 1533 public static function is_option_empty_in_array( $field, $option ) {
1326 1534 return empty( $field[ $option ] );
@@ -1328,8 +1536,9 @@
1328 1536
1329 1537 /**
1330 1538 * @param object $field
1331 1539 * @param string $option
1540 + *
1332 1541 * @return bool
1333 1542 */
1334 1543 public static function is_option_empty_in_object( $field, $option ) {
1335 1544 return empty( $field->field_options[ $option ] );
@@ -1337,12 +1546,13 @@
1337 1546
1338 1547 /**
1339 1548 * @param stdClass $field
1340 1549 * @param string $option
1550 + *
1341 1551 * @return bool
1342 1552 */
1343 1553 public static function is_option_value_in_object( $field, $option ) {
1344 - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1554 + return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; // phpcs:ignore Universal.Operators.StrictComparisons
1345 1555 }
1346 1556
1347 1557 /**
1348 1558 * @since 2.0.18
@@ -1348,23 +1558,19 @@
1348 1558 * @since 2.0.18
1349 1559 *
1350 1560 * @param array|object $field
1351 1561 * @param string $option
1562 + *
1352 1563 * @return mixed
1353 1564 */
1354 1565 public static function get_option( $field, $option ) {
1355 - if ( is_array( $field ) ) {
1356 - $option = self::get_option_in_array( $field, $option );
1357 - } else {
1358 - $option = self::get_option_in_object( $field, $option );
1359 - }
1360 -
1361 - return $option;
1566 + return is_array( $field ) ? self::get_option_in_array( $field, $option ) : self::get_option_in_object( $field, $option );
1362 1567 }
1363 1568
1364 1569 /**
1365 1570 * @param array $field
1366 1571 * @param string $option
1572 + *
1367 1573 * @return mixed
1368 1574 */
1369 1575 public static function get_option_in_array( $field, $option ) {
1370 1576 if ( isset( $field[ $option ] ) ) {
@@ -1380,8 +1586,9 @@
1380 1586
1381 1587 /**
1382 1588 * @param object $field
1383 1589 * @param string $option
1590 + *
1384 1591 * @return mixed
1385 1592 */
1386 1593 public static function get_option_in_object( $field, $option ) {
1387 1594 return $field->field_options[ $option ] ?? '';
@@ -1390,17 +1597,13 @@
1390 1597 /**
1391 1598 * @since 2.0.09
1392 1599 *
1393 1600 * @param array|object $field
1601 + *
1394 1602 * @return bool
1395 1603 */
1396 1604 public static function is_repeating_field( $field ) {
1397 - if ( is_array( $field ) ) {
1398 - $is_repeating_field = ( 'divider' === $field['type'] );
1399 - } else {
1400 - $is_repeating_field = ( 'divider' === $field->type );
1401 - }
1402 -
1605 + $is_repeating_field = is_array( $field ) ? 'divider' === $field['type'] : 'divider' === $field->type;
1403 1606 return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1404 1607 }
1405 1608
1406 1609 /**
@@ -1409,9 +1612,8 @@
1409 1612 * @return int field id
1410 1613 */
1411 1614 public static function get_id_by_key( $key ) {
1412 1615 $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
1413 -
1414 1616 return (int) $id;
1415 1617 }
1416 1618
1417 1619 /**
@@ -1422,12 +1624,16 @@
1422 1624 public static function get_key_by_id( $id ) {
1423 1625 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1424 1626 }
1425 1627
1628 + /**
1629 + * @param array|object $field
1630 + *
1631 + * @return bool
1632 + */
1426 1633 public static function is_image( $field ) {
1427 1634 $type = self::get_field_type( $field );
1428 -
1429 - return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1635 + return $type === 'url' && self::get_option( $field, 'show_image' );
1430 1636 }
1431 1637
1432 1638 /**
1433 1639 * Check if field is radio or Dynamic radio
@@ -1465,18 +1671,12 @@
1465 1671 *
1466 1672 * @return bool true if field type is checkbox or Dynamic checkbox
1467 1673 */
1468 1674 public static function is_field_type( $field, $is_type ) {
1469 - $field_type = self::get_original_field_type( $field );
1470 - $data_type = self::get_option( $field, 'data_type' );
1675 + $field_type = self::get_original_field_type( $field );
1676 + $data_type = self::get_option( $field, 'data_type' );
1677 + $is_field_type = $is_type === $field_type || ( 'data' === $field_type && $is_type === $data_type ) || ( 'lookup' === $field_type && $is_type === $data_type ) || ( 'product' === $field_type && $is_type === $data_type ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1471 1678
1472 - $is_field_type = (
1473 - $is_type === $field_type ||
1474 - ( 'data' === $field_type && $is_type === $data_type ) ||
1475 - ( 'lookup' === $field_type && $is_type === $data_type ) ||
1476 - ( 'product' === $field_type && $is_type === $data_type )
1477 - );
1478 -
1479 1679 /**
1480 1680 * When a field type is checked, allow individual fields
1481 1681 * to set the type.
1482 1682 *
@@ -1490,12 +1690,12 @@
1490 1690 *
1491 1691 * @since 4.10.02
1492 1692 *
1493 1693 * @param array $field Field array.
1694 + *
1494 1695 * @return bool
1495 1696 */
1496 1697 public static function is_combo_field( $field ) {
1497 1698 $field_type_obj = FrmFieldFactory::get_field_factory( $field );
1498 -
1499 1699 return ! empty( $field_type_obj->is_combo_field );
1500 1700 }
1501 1701 }