PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / page-builders / elementor / payment-history-widget.php
sureforms / inc / page-builders / elementor Last commit date
assets 3 weeks ago form-widget.php 2 months ago payment-history-widget.php 3 weeks ago service-provider.php 1 month ago
payment-history-widget.php
163 lines
1 <?php
2 /**
3 * Elementor SureForms Payment History widget.
4 *
5 * @package sureforms.
6 * @since 2.12.2
7 */
8
9 namespace SRFM\Inc\Page_Builders\Elementor;
10
11 use Elementor\Controls_Manager;
12 use Elementor\Widget_Base;
13 use SRFM\Inc\Payments\Payment_History_Shortcode;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * SureForms Elementor widget that displays the Payment History (parity with the srfm/payment-history block).
21 *
22 * @since 2.12.2
23 */
24 class Payment_History_Widget extends Widget_Base {
25 /**
26 * Get widget name.
27 *
28 * @since 2.12.2
29 * @return string Widget name.
30 */
31 public function get_name() {
32 return 'srfm-payment-history';
33 }
34
35 /**
36 * Get widget title.
37 *
38 * @since 2.12.2
39 * @return string Widget title.
40 */
41 public function get_title() {
42 return __( 'Payment History', 'sureforms' );
43 }
44
45 /**
46 * Get widget icon.
47 *
48 * @since 2.12.2
49 * @return string Widget icon.
50 */
51 public function get_icon() {
52 return 'eicon-price-list srfm-elementor-widget-icon';
53 }
54
55 /**
56 * Get widget categories.
57 *
58 * @since 2.12.2
59 * @return array<string> Widget categories.
60 */
61 public function get_categories() {
62 return [ 'sureforms-elementor' ];
63 }
64
65 /**
66 * Get widget keywords.
67 *
68 * @since 2.12.2
69 * @return array<string> Widget keywords.
70 */
71 public function get_keywords() {
72 return [
73 'sureforms',
74 'payment',
75 'payment history',
76 'subscription',
77 'transactions',
78 ];
79 }
80
81 /**
82 * Declare the payment-history stylesheet as a widget style dependency so Elementor
83 * enqueues it in the <head>. This widget's content lives in postmeta, so the
84 * shortcode's has_block()/has_shortcode() gate on wp_enqueue_scripts can't detect
85 * it; without this the CSS would only load at render() time (footer) and the
86 * dashboard would flash unstyled (FOUC). The handle is registered by
87 * Payment_History_Shortcode::register_assets() on wp_enqueue_scripts (priority 1).
88 *
89 * @since 2.12.3
90 * @return array<string> Style handles this widget depends on.
91 */
92 public function get_style_depends() {
93 return [ 'srfm-payment-history' ];
94 }
95
96 /**
97 * Register widget controls.
98 *
99 * @since 2.12.2
100 * @return void
101 */
102 protected function register_controls() {
103 $this->start_controls_section(
104 'srfm_payment_history_section',
105 [
106 'label' => __( 'Payment History', 'sureforms' ),
107 ]
108 );
109
110 $this->add_control(
111 'per_page',
112 [
113 'label' => __( 'Items per page', 'sureforms' ),
114 'type' => Controls_Manager::NUMBER,
115 'min' => 1,
116 'default' => 10,
117 ]
118 );
119
120 $this->add_control(
121 'show_subscription',
122 [
123 'label' => __( 'Show Subscriptions', 'sureforms' ),
124 'type' => Controls_Manager::SWITCHER,
125 'label_on' => __( 'Show', 'sureforms' ),
126 'label_off' => __( 'Hide', 'sureforms' ),
127 'return_value' => 'true',
128 'default' => 'true',
129 ]
130 );
131
132 $this->end_controls_section();
133 }
134
135 /**
136 * Render the widget output on the frontend.
137 *
138 * Delegates to the Payment_History_Shortcode, mirroring the Gutenberg block.
139 *
140 * @since 2.12.2
141 * @return void
142 */
143 protected function render() {
144 $settings = $this->get_settings_for_display();
145
146 if ( ! is_array( $settings ) ) {
147 return;
148 }
149
150 $per_page = absint( $settings['per_page'] ?? 10 );
151 if ( $per_page <= 0 ) {
152 $per_page = 10;
153 }
154
155 $atts = [
156 'per_page' => strval( $per_page ),
157 'show_subscription' => ! empty( $settings['show_subscription'] ) && 'true' === $settings['show_subscription'] ? 'true' : 'false',
158 ];
159
160 echo Payment_History_Shortcode::get_instance()->render( $atts ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped within the shortcode renderer.
161 }
162 }
163