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 / bricks / service-provider.php
sureforms / inc / page-builders / bricks Last commit date
elements 3 weeks ago service-provider.php 3 weeks ago
service-provider.php
97 lines
1 <?php
2 /**
3 * Bricks SureForms service provider.
4 *
5 * @package sureforms.
6 * @since 0.0.5
7 */
8
9 namespace SRFM\Inc\Page_Builders\Bricks;
10
11 use SRFM\Inc\Payments\Payment_History_Shortcode;
12 use SRFM\Inc\Traits\Get_Instance;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * SureForms Bricks service provider.
20 */
21 class Service_Provider {
22 use Get_Instance;
23
24 /**
25 * Constructor.
26 */
27 public function __construct() {
28 add_action( 'init', [ $this, 'widget' ], 11 );
29 }
30
31 /**
32 * Register SureForms widget.
33 *
34 * @since 0.0.5
35 * @return void
36 */
37 public function widget() {
38 if ( ! class_exists( '\Bricks\Elements' ) ) {
39 return;
40 }
41 add_filter(
42 'bricks/builder/i18n',
43 [ $this, 'bricks_translatable_strings' ]
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 }
83 }
84
85 /**
86 * Filter to add translatable string to the builder.
87 *
88 * @param array<string> $i18n Array of translatable strings.
89 * @since 0.0.5
90 * @return array<string> $i18n
91 */
92 public function bricks_translatable_strings( $i18n ) {
93 $i18n['sureforms'] = __( 'SureForms', 'sureforms' );
94 return $i18n;
95 }
96 }
97