PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.8
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.8
2.12.8 2.12.7 2.12.6 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 All 98 releases
← All changes | inc/page-builders/bricks/service-provider.php +38 -0 2.7.1 → 2.12.8 View file →
@@ -7,8 +7,9 @@
7 7 */
8 8
9 9 namespace SRFM\Inc\Page_Builders\Bricks;
10 10
11 +use SRFM\Inc\Payments\Payment_History_Shortcode;
11 12 use SRFM\Inc\Traits\Get_Instance;
12 13
13 14 if ( ! defined( 'ABSPATH' ) ) {
14 15 exit; // Exit if accessed directly.
@@ -41,8 +42,45 @@
41 42 'bricks/builder/i18n',
42 43 [ $this, 'bricks_translatable_strings' ]
43 44 );
44 45 \Bricks\Elements::register_element( __DIR__ . '/elements/form-widget.php' );
46 + \Bricks\Elements::register_element( __DIR__ . '/elements/payment-history-widget.php' );
47 +
48 + // Head-load the Payment History stylesheet when the element is on the page.
49 + // Priority 5 runs after Payment_History_Shortcode::register_assets() (priority 1)
50 + // so the handle exists, and before wp_head prints styles.
51 + add_action( 'wp_enqueue_scripts', [ $this, 'maybe_enqueue_payment_history_assets' ], 5 );
52 + }
53 +
54 + /**
55 + * Enqueue the Payment History assets in the <head> when a Bricks Payment History
56 + * element is present on the current page.
57 + *
58 + * Bricks instantiates elements — and so fires their `enqueue_scripts()` — only
59 + * during render (`Frontend::render_element()` → `Element::init()`), which runs
60 + * after `wp_head`. An element-side enqueue therefore lands in the footer and the
61 + * dashboard flashes unstyled. Bricks stores element data in postmeta, so detect our
62 + * element in the head the same way Bricks detects its own setting-specific assets:
63 + * sniff the serialised template data of each area for the element name.
64 + *
65 + * @since 2.12.3
66 + * @return void
67 + */
68 + public function maybe_enqueue_payment_history_assets() {
69 + if ( ! class_exists( '\Bricks\Database' ) ) {
70 + return;
71 + }
72 +
73 + foreach ( [ 'header', 'content', 'footer' ] as $area ) {
74 + $data = \Bricks\Database::get_template_data( $area );
75 + if ( ! is_array( $data ) ) {
76 + continue;
77 + }
78 + if ( false !== strpos( (string) wp_json_encode( $data ), '"sureforms-payment-history"' ) ) {
79 + Payment_History_Shortcode::get_instance()->enqueue_assets( true );
80 + return;
81 + }
82 + }
45 83 }
46 84
47 85 /**
48 86 * Filter to add translatable string to the builder.