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 | stripe/helpers/FrmTransLiteAppHelper.php +96 -37 6.27 → trunk View file →
@@ -174,13 +174,9 @@
174 174 }
175 175
176 176 $form_action = FrmTransLiteAction::get_single_action_type( $atts['payment']['action_id'], 'payment' );
177 177
178 - if ( ! $form_action ) {
179 - return array();
180 - }
181 -
182 - return $form_action->post_content;
178 + return $form_action ? $form_action->post_content : array();
183 179 }
184 180
185 181 /**
186 182 * Allow entry values, default values, and other shortcodes
@@ -264,14 +260,9 @@
264 260 * @return string
265 261 */
266 262 public static function get_repeat_label_from_value( $value, $number ) {
267 263 $times = self::get_plural_repeat_times( $number );
268 -
269 - if ( isset( $times[ $value ] ) ) {
270 - $value = $times[ $value ];
271 - }
272 -
273 - return $value;
264 + return $times[ $value ] ?? $value;
274 265 }
275 266
276 267 /**
277 268 * @param array|float|int|object $payment
@@ -341,21 +332,16 @@
341 332 /**
342 333 * @return string
343 334 */
344 335 public static function get_date_format() {
345 - $date_format = 'm/d/Y';
336 + if ( ! class_exists( 'FrmProAppHelper' ) ) {
337 + return get_option( 'date_format' );
338 + }
346 339
347 - if ( class_exists( 'FrmProAppHelper' ) ) {
348 - $frmpro_settings = FrmProAppHelper::get_settings();
340 + $date_format = 'm/d/Y';
341 + $frmpro_settings = FrmProAppHelper::get_settings();
349 342
350 - if ( $frmpro_settings ) {
351 - $date_format = $frmpro_settings->date_format;
352 - }
353 - } else {
354 - $date_format = get_option( 'date_format' );
355 - }
356 -
357 - return $date_format;
343 + return $frmpro_settings ? $frmpro_settings->date_format : $date_format;
358 344 }
359 345
360 346 /**
361 347 * @param string $date
@@ -375,9 +361,22 @@
375 361 *
376 362 * @return int
377 363 */
378 364 public static function get_user_id_for_current_payment() {
379 - return is_user_logged_in() ? get_current_user_id() : 0;
365 + $user_id = is_user_logged_in() ? get_current_user_id() : 0;
366 +
367 + /**
368 + * Set the user who owns the payment being made.
369 + * This makes it possible for an add on to claim the payment for a user who isn't logged in yet,
370 + * for example when the same submission registers them.
371 + *
372 + * @since 6.35
373 + *
374 + * @param int $user_id The logged in user, or 0 for a guest.
375 + */
376 + $user_id = (int) apply_filters( 'frm_payment_user_id', $user_id );
377 +
378 + return max( 0, $user_id );
380 379 }
381 380
382 381 /**
383 382 * @param int $user_id
@@ -384,19 +383,17 @@
384 383 *
385 384 * @return string
386 385 */
387 386 public static function get_user_link( $user_id ) {
388 - $user_link = esc_html__( 'Guest', 'formidable' );
389 -
390 387 if ( $user_id ) {
391 388 $user = get_userdata( $user_id );
392 389
393 390 if ( $user ) {
394 - $user_link = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
391 + return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
395 392 }
396 393 }
397 394
398 - return $user_link;
395 + return esc_html__( 'Guest', 'formidable' );
399 396 }
400 397
401 398 /**
402 399 * @param mixed $value
@@ -404,17 +401,22 @@
404 401 *
405 402 * @return void
406 403 */
407 404 public static function show_in_table( $value, $label ) {
408 - if ( $value ) { ?>
409 - <tr>
410 - <th scope="row"><?php echo esc_html( $label ); ?>:</th>
411 - <td>
412 - <?php echo esc_html( $value ); ?>
413 - </td>
414 - </tr>
415 - <?php
405 + if ( ! $value ) {
406 + return;
416 407 }
408 +
409 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
410 + ?>
411 + <tr>
412 + <th scope="row"><?php echo esc_html( $label ); ?>:</th>
413 + <td>
414 + <?php echo esc_html( $value ); ?>
415 + </td>
416 + </tr>
417 + <?php
418 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
417 419 }
418 420
419 421 /**
420 422 * Echo a link that includes a data-deleteconfirm attribute.
@@ -467,9 +469,9 @@
467 469
468 470 $currency = FrmCurrencyHelper::get_currency( $action->post_content['currency'] );
469 471
470 472 if ( ! empty( $currency['decimals'] ) ) {
471 - $amount = number_format( $amount / 100, 2, '.', '' );
473 + return number_format( $amount / 100, 2, '.', '' );
472 474 }
473 475
474 476 return $amount;
475 477 }
@@ -533,9 +535,9 @@
533 535 $gateway = reset( $gateway );
534 536 }
535 537
536 538 if ( isset( $gateways[ $gateway ] ) ) {
537 - $value = $gateways[ $gateway ][ $setting ];
539 + return $gateways[ $gateway ][ $setting ];
538 540 }
539 541
540 542 return $value;
541 543 }
@@ -565,8 +567,9 @@
565 567 $selected = '';
566 568 }
567 569
568 570 $currencies = FrmCurrencyHelper::get_currencies();
571 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
569 572 ?>
570 573 <select <?php FrmAppHelper::array_to_html_params( $select_attrs, true ); ?>>
571 574 <?php
572 575 if ( in_array( 'square', $gateways, true ) ) {
@@ -592,8 +595,9 @@
592 595 }
593 596 ?>
594 597 </select>
595 598 <?php
599 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
596 600 }
597 601
598 602 /**
599 603 * @since 6.27
@@ -611,6 +615,61 @@
611 615 */
612 616 public static function should_fallback_to_paypal() {
613 617 _deprecated_function( __METHOD__, '6.27' );
614 618 return false;
619 + }
620 +
621 + /**
622 + * Render the gateway icon buttons for the payment action settings.
623 + *
624 + * @param array $gateways
625 + * @param WP_Post $form_action
626 + * @param FrmFormAction $action_control
627 + *
628 + * @return void
629 + */
630 + public static function show_gateway_buttons( $gateways, $form_action, $action_control ) {
631 + $gateway_order = array( 'stripe', 'square', 'paypal' );
632 + $gateways = self::sort_gateways( $gateways, $gateway_order );
633 +
634 + include self::plugin_path() . '/views/action-settings/gateway-buttons.php';
635 + }
636 +
637 + /**
638 + * Sort gateways by a predefined order.
639 + * Unlisted gateways are appended at the end.
640 + *
641 + * @param array $gateways
642 + * @param array $order Gateway keys in desired order.
643 + *
644 + * @return array
645 + */
646 + private static function sort_gateways( $gateways, $order ) {
647 + $sorted = array();
648 +
649 + foreach ( $order as $key ) {
650 + if ( isset( $gateways[ $key ] ) ) {
651 + $sorted[ $key ] = $gateways[ $key ];
652 + }
653 + }
654 +
655 + return $sorted + $gateways;
656 + }
657 +
658 + /**
659 + * @since 6.32.1
660 + *
661 + * @param string $gateway 'stripe', 'square', or 'paypal'.
662 + * @param string $mode 'test' or 'live'.
663 + *
664 + * @return void
665 + */
666 + public static function trigger_gateway_disconnected_hook( $gateway, $mode ) {
667 + /**
668 + * @since 6.32.1
669 + *
670 + * @param string $gateway 'stripe', 'square', or 'paypal'.
671 + * @param string $mode 'test' or 'live'.
672 + */
673 + do_action( 'frm_disconnected_gateway', $gateway, $mode );
615 674 }
616 675 }