| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bricks SureForms Payment History element. |
| 4 |
* |
| 5 |
* @package sureforms. |
| 6 |
* @since 2.12.2 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SRFM\Inc\Page_Builders\Bricks\Elements; |
| 10 |
|
| 11 |
use SRFM\Inc\Payments\Payment_History_Shortcode; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; // Exit if accessed directly. |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* SureForms Bricks element that displays the Payment History (parity with the srfm/payment-history block). |
| 19 |
* |
| 20 |
* @since 2.12.2 |
| 21 |
*/ |
| 22 |
class Payment_History_Widget extends \Bricks\Element { |
| 23 |
/** |
| 24 |
* Element category. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
public $category = 'sureforms'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Element name. |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
public $name = 'sureforms-payment-history'; |
| 36 |
|
| 37 |
/** |
| 38 |
* Element icon. |
| 39 |
* |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
public $icon = 'ti-wallet'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Get element label. |
| 46 |
* |
| 47 |
* @since 2.12.2 |
| 48 |
* @return string element label. |
| 49 |
*/ |
| 50 |
public function get_label() { |
| 51 |
return __( 'Payment History', 'sureforms' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get element keywords. |
| 56 |
* |
| 57 |
* @since 2.12.2 |
| 58 |
* @return array<string> element keywords. |
| 59 |
*/ |
| 60 |
public function get_keywords() { |
| 61 |
return [ |
| 62 |
'sureforms', |
| 63 |
'payment', |
| 64 |
'payment history', |
| 65 |
'subscription', |
| 66 |
]; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Enqueue the payment-history stylesheet. NOTE: Bricks fires this at render time |
| 71 |
* (`Frontend::render_element()` → `Element::init()`), which runs after `wp_head`, so |
| 72 |
* this alone would print the CSS in the footer → FOUC. The head-load is handled |
| 73 |
* separately by `Service_Provider::maybe_enqueue_payment_history_assets()`, which |
| 74 |
* detects this element on `wp_enqueue_scripts`; this override stays only as a |
| 75 |
* belt-and-braces fallback. The handle is registered by |
| 76 |
* `Payment_History_Shortcode::register_assets()` (priority 1). |
| 77 |
* |
| 78 |
* @since 2.12.3 |
| 79 |
* @return void |
| 80 |
*/ |
| 81 |
public function enqueue_scripts() { |
| 82 |
wp_enqueue_style( 'srfm-payment-history' ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Set element controls. |
| 87 |
* |
| 88 |
* @since 2.12.2 |
| 89 |
* @return void |
| 90 |
*/ |
| 91 |
public function set_controls() { |
| 92 |
$this->controls['per_page'] = [ |
| 93 |
'tab' => 'content', |
| 94 |
'label' => __( 'Items per page', 'sureforms' ), |
| 95 |
'type' => 'number', |
| 96 |
'min' => 1, |
| 97 |
'default' => 10, |
| 98 |
]; |
| 99 |
|
| 100 |
$this->controls['show_subscription'] = [ |
| 101 |
'tab' => 'content', |
| 102 |
'label' => __( 'Show Subscriptions', 'sureforms' ), |
| 103 |
'type' => 'checkbox', |
| 104 |
'default' => true, |
| 105 |
]; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Render the element output. |
| 110 |
* |
| 111 |
* Delegates to the Payment_History_Shortcode, mirroring the Gutenberg block. |
| 112 |
* |
| 113 |
* @since 2.12.2 |
| 114 |
* @return void |
| 115 |
*/ |
| 116 |
public function render() { |
| 117 |
$per_page = absint( $this->settings['per_page'] ?? 10 ); |
| 118 |
if ( $per_page <= 0 ) { |
| 119 |
$per_page = 10; |
| 120 |
} |
| 121 |
|
| 122 |
$atts = [ |
| 123 |
'per_page' => strval( $per_page ), |
| 124 |
'show_subscription' => ! empty( $this->settings['show_subscription'] ) ? 'true' : 'false', |
| 125 |
]; |
| 126 |
|
| 127 |
echo '<div ' . $this->render_attributes( '_root' ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() returns escaped attributes. |
| 128 |
echo Payment_History_Shortcode::get_instance()->render( $atts ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped within the shortcode renderer. |
| 129 |
echo '</div>'; |
| 130 |
} |
| 131 |
} |
| 132 |
|