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
formidable / stripe / controllers / FrmTransLiteCRUDController.php

FrmTransLiteCRUDController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, 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 *
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 return $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
84 /**
85 * Handle routing for deleting a payment.
86 *
87 * @return void
88 */
89 public static function destroy() {
90 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
91
92 if ( ! wp_verify_nonce( $nonce ) ) {
93 $frm_settings = FrmAppHelper::get_settings();
94 wp_die( esc_html( $frm_settings->admin_permission ) );
95 }
96
97 FrmAppHelper::permission_check( 'administrator' );
98
99 $message = '';
100 $frm_payment = self::the_class();
101 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
102
103 if ( $id && $frm_payment->destroy( $id ) ) {
104 $message = __( 'Payment was Successfully Deleted', 'formidable' );
105 }
106
107 FrmTransLiteListsController::display_list( compact( 'message' ) );
108 }
109
110 /**
111 * @return string
112 */
113 private static function table_name() {
114 $allowed = array( 'payments', 'subscriptions' );
115 $default = reset( $allowed );
116 $name = FrmAppHelper::get_param( 'type', $default, 'get', 'sanitize_text_field' );
117
118 return in_array( $name, $allowed, true ) ? $name : $default;
119 }
120
121 /**
122 * @return FrmTransLitePayment|FrmTransLiteSubscription
123 */
124 private static function the_class() {
125 if ( self::table_name() === 'subscriptions' ) {
126 return new FrmTransLiteSubscription();
127 }
128
129 return new FrmTransLitePayment();
130 }
131 }
132