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

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