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

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