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

115 lines 2.8 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 include FrmTransLiteAppHelper::plugin_path() . '/views/' . $table_name . '/show.php';
39 }
40
41 /**
42 * @param int $id
43 * @return object|null
44 */
45 private static function get_payment_row( $id ) {
46 global $wpdb;
47
48 $table_name = self::table_name();
49
50 // @codingStandardsIgnoreStart
51 $payment = $wpdb->get_row(
52 $wpdb->prepare(
53 "SELECT
54 p.*, e.user_id
55 FROM `{$wpdb->prefix}frm_{$table_name}` p
56 LEFT JOIN `{$wpdb->prefix}frm_items` e ON p.item_id = e.id
57 WHERE p.id=%d",
58 $id
59 )
60 );
61 // @codingStandardsIgnoreEnd
62
63 return $payment;
64 }
65
66 /**
67 * Handle routing for deleting a payment.
68 *
69 * @return void
70 */
71 public static function destroy() {
72 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
73
74 if ( ! wp_verify_nonce( $nonce ) ) {
75 $frm_settings = FrmAppHelper::get_settings();
76 wp_die( esc_html( $frm_settings->admin_permission ) );
77 }
78
79 FrmAppHelper::permission_check( 'administrator' );
80
81 $message = '';
82 $frm_payment = self::the_class();
83 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
84
85 if ( $id && $frm_payment->destroy( $id ) ) {
86 $message = __( 'Payment was Successfully Deleted', 'formidable' );
87 }
88
89 FrmTransLiteListsController::display_list( compact( 'message' ) );
90 }
91
92 /**
93 * @return string
94 */
95 private static function table_name() {
96 $allowed = array( 'payments', 'subscriptions' );
97 $default = reset( $allowed );
98 $name = FrmAppHelper::get_param( 'type', $default, 'get', 'sanitize_text_field' );
99
100 if ( ! in_array( $name, $allowed, true ) ) {
101 $name = $default;
102 }
103
104 return $name;
105 }
106
107 /**
108 * @return FrmTransLitePayment|FrmTransLiteSubscription
109 */
110 private static function the_class() {
111 $class_name = self::table_name() === 'subscriptions' ? 'FrmTransLiteSubscription' : 'FrmTransLitePayment';
112 return new $class_name();
113 }
114 }
115