| @@ -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 |
| @@ -365,9 +361,22 @@ | ||
| 365 | 361 | * |
| 366 | 362 | * @return int |
| 367 | 363 | */ |
| 368 | 364 | public static function get_user_id_for_current_payment() { |
| 369 | - 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 ); | |
| 370 | 379 | } |
| 371 | 380 | |
| 372 | 381 | /** |
| 373 | 382 | * @param int $user_id |
| @@ -392,20 +401,22 @@ | ||
| 392 | 401 | * |
| 393 | 402 | * @return void |
| 394 | 403 | */ |
| 395 | 404 | public static function show_in_table( $value, $label ) { |
| 396 | - if ( $value ) { | |
| 397 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 398 | - ?> | |
| 399 | - <tr> | |
| 400 | - <th scope="row"><?php echo esc_html( $label ); ?>:</th> | |
| 401 | - <td> | |
| 402 | - <?php echo esc_html( $value ); ?> | |
| 403 | - </td> | |
| 404 | - </tr> | |
| 405 | - <?php | |
| 406 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 405 | + if ( ! $value ) { | |
| 406 | + return; | |
| 407 | 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 | |
| 408 | 419 | } |
| 409 | 420 | |
| 410 | 421 | /** |
| 411 | 422 | * Echo a link that includes a data-deleteconfirm attribute. |
| @@ -604,6 +615,61 @@ | ||
| 604 | 615 | */ |
| 605 | 616 | public static function should_fallback_to_paypal() { |
| 606 | 617 | _deprecated_function( __METHOD__, '6.27' ); |
| 607 | 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 ); | |
| 608 | 674 | } |
| 609 | 675 | } |