PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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
formidable / stripe / controllers / FrmTransLiteCRUDController.php

FrmTransLiteCRUDController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.23, at stripe/controllers/FrmTransLiteCRUDController.php

132 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * This CRUD controller only supports Read and Delete operations.
8 * All payment creation in Lite is handled in form logic.
9 */
10 class FrmTransLiteCRUDController {
11
12 /**
13 * Show a table of either payments for subscriptions.
14 *
15 * @param int $id
16 * @return void
17 */
18 public static function show( $id = 0 ) {
19 if ( ! $id ) {
20 $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
21 if ( ! $id ) {
22 wp_die( esc_html__( 'Please select a payment to view', 'formidable' ) );
23 }
24 }
25
26 FrmAppHelper::include_svg();
27
28 $table_name = self::table_name();
29 $payment = self::get_payment_row( $id );
30
31 if ( ! $payment ) {
32 $trans_type = $table_name === 'subscriptions' ? __( 'Subscription', 'formidable' ) : __( 'Payment', 'formidable' );
33 FrmAppController::show_error_modal(
34 array(
35 /* translators: %s: Transaction type */
36 'title' => sprintf( __( 'You can\'t view the %s', 'formidable' ), $trans_type ),
37 /* translators: %s: Transaction type */
38 'body' => sprintf( __( 'You are trying to view a %s that does not exist', 'formidable' ), $trans_type ),
39 /* translators: %s: Transaction table name */
40 'cancel_url' => sprintf( admin_url( 'admin.php?page=formidable-payments&trans_type=%s' ), $table_name ),
41 )
42 );
43 return;
44 }
45
46 $date_format = get_option( 'date_format' );
47 $user_name = FrmTransLiteAppHelper::get_user_link( $payment->user_id );
48 $entry = FrmEntry::getOne( $payment->item_id );
49 $form_id = $entry ? $entry->form_id : false;
50
51 if ( $table_name !== 'payments' ) {
52 $subscription = $payment;
53 }
54
55 include FrmTransLiteAppHelper::plugin_path() . '/views/' . $table_name . '/show.php';
56 }
57
58 /**
59 * @param int $id
60 * @return object|null
61 */
62 private static function get_payment_row( $id ) {
63 global $wpdb;
64
65 $table_name = self::table_name();
66
67 // @codingStandardsIgnoreStart
68 $payment = $wpdb->get_row(
69 $wpdb->prepare(
70 "SELECT
71 p.*, e.user_id
72 FROM `{$wpdb->prefix}frm_{$table_name}` p
73 LEFT JOIN `{$wpdb->prefix}frm_items` e ON p.item_id = e.id
74 WHERE p.id=%d",
75 $id
76 )
77 );
78 // @codingStandardsIgnoreEnd
79
80 return $payment;
81 }
82
83 /**
84 * Handle routing for deleting a payment.
85 *
86 * @return void
87 */
88 public static function destroy() {
89 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
90
91 if ( ! wp_verify_nonce( $nonce ) ) {
92 $frm_settings = FrmAppHelper::get_settings();
93 wp_die( esc_html( $frm_settings->admin_permission ) );
94 }
95
96 FrmAppHelper::permission_check( 'administrator' );
97
98 $message = '';
99 $frm_payment = self::the_class();
100 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
101
102 if ( $id && $frm_payment->destroy( $id ) ) {
103 $message = __( 'Payment was Successfully Deleted', 'formidable' );
104 }
105
106 FrmTransLiteListsController::display_list( compact( 'message' ) );
107 }
108
109 /**
110 * @return string
111 */
112 private static function table_name() {
113 $allowed = array( 'payments', 'subscriptions' );
114 $default = reset( $allowed );
115 $name = FrmAppHelper::get_param( 'type', $default, 'get', 'sanitize_text_field' );
116
117 if ( ! in_array( $name, $allowed, true ) ) {
118 $name = $default;
119 }
120
121 return $name;
122 }
123
124 /**
125 * @return FrmTransLitePayment|FrmTransLiteSubscription
126 */
127 private static function the_class() {
128 $class_name = self::table_name() === 'subscriptions' ? 'FrmTransLiteSubscription' : 'FrmTransLitePayment';
129 return new $class_name();
130 }
131 }
132