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/controllers/FrmEmailStylesController.php +42 -24 6.25 → trunk View file →
@@ -62,8 +62,9 @@
62 62 *
63 63 * @since 6.25
64 64 *
65 65 * @param array[] $email_styles The email styles.
66 + *
66 67 * @return array
67 68 */
68 69 return apply_filters( 'frm_email_styles', $email_styles );
69 70 }
@@ -71,8 +72,9 @@
71 72 /**
72 73 * Gets email style preview URL.
73 74 *
74 75 * @param string $style_key Style key.
76 + *
75 77 * @return string
76 78 */
77 79 public static function get_email_style_preview_url( $style_key ) {
78 80 return wp_nonce_url( admin_url( 'admin-ajax.php?action=frm_email_style_preview&style_key=' . $style_key ), 'frm_email_style_preview' );
@@ -84,8 +86,9 @@
84 86 * @return string
85 87 */
86 88 public static function get_default_email_style() {
87 89 $frm_settings = FrmAppHelper::get_settings();
90 +
88 91 if ( empty( $frm_settings->email_style ) ) {
89 92 return 'classic';
90 93 }
91 94
@@ -91,8 +94,9 @@
91 94
92 95 // Check if the selected style is available and selectable.
93 96 $styles = self::get_email_styles();
94 97 $style = $frm_settings->email_style;
98 +
95 99 if ( isset( $styles[ $style ] ) && ! empty( $styles[ $style ]['selectable'] ) ) {
96 100 return $style;
97 101 }
98 102
@@ -102,8 +106,9 @@
102 106 /**
103 107 * Gets the test email content.
104 108 *
105 109 * @param false|string $style_key Default is `false`, using the one in settings.
110 + *
106 111 * @return string
107 112 */
108 113 private static function get_test_email_content( $style_key = false ) {
109 114 if ( ! $style_key ) {
@@ -129,15 +134,16 @@
129 134 Praesent in risus velit. Donec molestie tincidunt ex sed consequat. Ut ornare fringilla fringilla.',
130 135 ),
131 136 );
132 137
133 - if ( 'plain' !== $style_key ) {
134 - $content = self::get_test_rich_text_email_content( $style_key, $table_rows );
135 - } else {
138 + if ( 'plain' === $style_key ) {
136 139 $content = '';
140 +
137 141 foreach ( $table_rows as $row ) {
138 142 $content .= $row['label'] . ': ' . $row['value'] . "\r\n";
139 143 }
144 + } else {
145 + $content = self::get_test_rich_text_email_content( $style_key, $table_rows );
140 146 }//end if
141 147
142 148 return $content;
143 149 }
@@ -146,8 +152,9 @@
146 152 * Gets the test email content.
147 153 *
148 154 * @param string $style_key Style key.
149 155 * @param array $table_rows Table rows.
156 + *
150 157 * @return string
151 158 */
152 159 private static function get_test_rich_text_email_content( $style_key, $table_rows ) {
153 160 $style_settings = self::get_email_style_settings();
@@ -156,13 +163,11 @@
156 163 $should_remove_border = 'sleek' === $style_key;
157 164
158 165 // Modern and Compact table styles don't have top and bottom border.
159 166 $should_remove_top_bottom_border = 'classic' !== $style_key;
167 + $table_generator = self::get_table_generator( $style_key );
168 + $content = $table_generator->generate_table_header();
160 169
161 - $table_generator = self::get_table_generator( $style_key );
162 -
163 - $content = $table_generator->generate_table_header();
164 -
165 170 // By default, table has the bottom border and table cells have top border.
166 171 if ( $should_remove_top_bottom_border ) {
167 172 $content = $table_generator->remove_border( $content, 'bottom' );
168 173 }
@@ -168,8 +173,11 @@
168 173 }
169 174
170 175 foreach ( $table_rows as $index => $row ) {
171 176 if ( 'compact' === $style_key ) {
177 + // Add some spaces after the label. Maybe change it to the left in RTL.
178 + $row['label'] = '<div style="padding-right:10px;">' . $row['label'] . '</div>';
179 +
172 180 // Compact table has two columns layout.
173 181 $table_row = $table_generator->generate_two_cell_table_row( $row['label'], $row['value'] );
174 182 } else {
175 183 // Other table styles have one column layout.
@@ -193,8 +201,9 @@
193 201 $content = self::wrap_email_message( $content );
194 202 }
195 203
196 204 $wrapped_content = '<html><head><meta charset="utf-8" /></head>';
205 +
197 206 if ( 'classic' !== $style_key ) {
198 207 // This works in previewing and as a fallback for email content.
199 208 $wrapped_content .= '<style>
200 209 body {background-color:' . esc_attr( $style_settings['bg_color'] ) . ';}
@@ -200,11 +209,10 @@
200 209 body {background-color:' . esc_attr( $style_settings['bg_color'] ) . ';}
201 210 a {color:' . esc_attr( $style_settings['link_color'] ) . ';}
202 211 </style>';
203 212 }
204 - $wrapped_content .= '</head><body>' . $content . '</body></html>';
205 213
206 - return $wrapped_content;
214 + return $wrapped_content . ( '</head><body>' . $content . '</body></html>' );
207 215 }
208 216
209 217 /**
210 218 * Gets content for the cell of one column table.
@@ -210,8 +218,9 @@
210 218 * Gets content for the cell of one column table.
211 219 *
212 220 * @param string $label Field label.
213 221 * @param string $value Prepared field value.
222 + *
214 223 * @return string
215 224 */
216 225 public static function get_content_for_one_column_cell( $label, $value ) {
217 226 return '<div style="font-weight:600;">' . $label . '</div>' . $value;
@@ -220,8 +229,9 @@
220 229 /**
221 230 * Gets table generator object for an email style.
222 231 *
223 232 * @param false|string $email_style Email style. Default is `false`: using the one in global settings.
233 + *
224 234 * @return FrmTableHTMLGenerator
225 235 */
226 236 public static function get_table_generator( $email_style = false ) {
227 237 if ( false === $email_style ) {
@@ -256,14 +266,14 @@
256 266 check_ajax_referer( 'frm_email_style_preview' );
257 267
258 268 $style_key = FrmAppHelper::get_param( 'style_key', '', 'get', 'sanitize_text_field' );
259 269 $not_exist_msg = __( "This email style doesn't exist", 'formidable' );
270 +
260 271 if ( ! $style_key ) {
261 272 die( esc_html( $not_exist_msg ) );
262 273 }
263 274
264 - $styles = self::get_email_styles();
265 - if ( ! isset( $styles[ $style_key ] ) ) {
275 + if ( ! isset( self::get_email_styles()[ $style_key ] ) ) {
266 276 die( esc_html( $not_exist_msg ) );
267 277 }
268 278
269 279 $style_key = FrmAppHelper::get_param( 'style_key', '', 'sanitize_text_field' );
@@ -286,25 +296,27 @@
286 296
287 297 $emails_str = FrmAppHelper::get_post_param( 'emails_str', '', 'sanitize_text_field' );
288 298 $emails = explode( ',', $emails_str );
289 299 $valid_emails = array();
300 +
290 301 foreach ( $emails as $email ) {
291 302 $email = trim( $email );
292 - if ( empty( $email ) || ! is_email( $email ) ) {
303 +
304 + if ( ! $email || ! is_email( $email ) ) {
293 305 continue;
294 306 }
307 +
295 308 $valid_emails[] = $email;
296 309 }
297 310
298 - if ( empty( $valid_emails ) ) {
311 + if ( ! $valid_emails ) {
299 312 wp_send_json_error( __( 'Invalid email address', 'formidable' ) );
300 313 }
301 314
302 315 $email_style = self::get_default_email_style();
303 -
304 - $subject = __( 'Formidable Test Email', 'formidable' );
305 - $content = self::get_test_email_content();
306 - $headers = array(
316 + $subject = __( 'Formidable Test Email', 'formidable' );
317 + $content = self::get_test_email_content();
318 + $headers = array(
307 319 self::get_content_type_header( $email_style ),
308 320 );
309 321
310 322 FrmUsageController::update_flows_data( 'send_test_email', $email_style );
@@ -309,8 +321,9 @@
309 321
310 322 FrmUsageController::update_flows_data( 'send_test_email', $email_style );
311 323
312 324 $result = wp_mail( $valid_emails, $subject, $content, $headers );
325 +
313 326 if ( $result ) {
314 327 wp_send_json_success( __( 'Test email sent successfully!', 'formidable' ) );
315 328 }
316 329
@@ -320,8 +333,9 @@
320 333 /**
321 334 * Gets Content-Type header.
322 335 *
323 336 * @param string $email_style Email style.
337 + *
324 338 * @return string
325 339 */
326 340 private static function get_content_type_header( $email_style ) {
327 341 $content_type = 'plain' === $email_style ? 'text/plain' : 'text/html';
@@ -329,8 +343,10 @@
329 343 }
330 344
331 345 /**
332 346 * Shows placeholder Pro settings.
347 + *
348 + * @return void
333 349 */
334 350 public static function show_upsell_settings() {
335 351 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/email/settings.php';
336 352 }
@@ -369,14 +385,15 @@
369 385 /**
370 386 * Wraps email message with new settings.
371 387 *
372 388 * @param string $message Email message.
389 + *
373 390 * @return string
374 391 */
375 392 public static function wrap_email_message( $message ) {
376 393 $style_settings = self::get_email_style_settings();
394 + $header_img = '';
377 395
378 - $header_img = '';
379 396 if ( $style_settings['img'] ) {
380 397 $img_align = $style_settings['img_align'] ? $style_settings['img_align'] : 'center';
381 398 $img_size = $style_settings['img_size'] ? $style_settings['img_size'] : 'thumbnail';
382 399 $img_url = is_numeric( $style_settings['img'] ) ? wp_get_attachment_image_url( $style_settings['img'], $img_size ) : $style_settings['img'];
@@ -386,9 +403,9 @@
386 403 esc_attr( $img_align )
387 404 );
388 405
389 406 $header_img .= sprintf(
390 - '<img src="%s" alt="" />',
407 + '<img src="%s" alt="" style="max-width:100%%;height:auto;" />',
391 408 esc_url( $img_url )
392 409 );
393 410
394 411 $header_img .= '</div>';
@@ -396,9 +413,9 @@
396 413
397 414 // Wrapper.
398 415 $font_family = $style_settings['font'] ? $style_settings['font'] : 'Inter,sans-serif';
399 416 $new_message = sprintf(
400 - '<div style="background-color:%1$s;color:%2$s;font-family:%3$s;padding:40px 0;">',
417 + '<div style="background-color:%1$s;color:%2$s;font-family:%3$s;padding:40px 10px;">',
401 418 esc_attr( $style_settings['bg_color'] ),
402 419 esc_attr( $style_settings['text_color'] ),
403 420 esc_attr( $font_family )
404 421 );
@@ -403,9 +420,9 @@
403 420 esc_attr( $font_family )
404 421 );
405 422
406 423 // Container.
407 - $new_message .= '<div style="width:640px;margin:auto;">';
424 + $new_message .= '<div style="max-width:640px;margin:auto;">';
408 425
409 426 // Header image if outside.
410 427 if ( $style_settings['img'] && 'inside' !== $style_settings['img_location'] ) {
411 428 $new_message .= $header_img;
@@ -424,11 +441,9 @@
424 441
425 442 // The message.
426 443 $new_message .= self::add_inline_css( 'a', 'color:' . $style_settings['link_color'] . ';', $message );
427 444
428 - $new_message .= '</div></div></div>';
429 -
430 - return $new_message;
445 + return $new_message . '</div></div></div>';
431 446 }
432 447
433 448 /**
434 449 * Adds inline CSS to a tag in the content.
@@ -435,8 +450,9 @@
435 450 *
436 451 * @param string $tag Tag name.
437 452 * @param string $css CSS code.
438 453 * @param string $content The content.
454 + *
439 455 * @return string
440 456 */
441 457 private static function add_inline_css( $tag, $css, $content ) {
442 458 $regex = '/<' . $tag . '.*?>/msi';
@@ -462,12 +478,14 @@
462 478 *
463 479 * @param string $tag Tag name.
464 480 * @param string $css CSS code.
465 481 * @param string $html The HTML tag.
482 + *
466 483 * @return string
467 484 */
468 485 private static function add_css_to_style_attr( $tag, $css, $html ) {
469 486 $regex = '/\sstyle=("|\')/mi';
487 +
470 488 if ( preg_match( $regex, $html, $matches ) ) {
471 489 $search = $matches[0];
472 490 $replace = $search . $css;
473 491 return preg_replace( $regex, $replace, $html );