PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.4.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.4.0
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / page-builders / bricks / service-provider.php

service-provider.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.4.0, at inc/page-builders/bricks/service-provider.php

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bricks service provider.
4 *
5 * Registers the SureDonation element category and all campaign/donation
6 * elements with Bricks Builder. Self-gates on Bricks being active.
7 *
8 * @package SureDonation
9 * @since 1.2.0
10 */
11
12 namespace SureDonation\Inc\Page_Builders\Bricks;
13
14 use SureDonation\Inc\Traits\Get_Instance;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Service_Provider class.
22 *
23 * @since 1.2.0
24 */
25 class Service_Provider {
26 use Get_Instance;
27
28 /**
29 * Element category slug (label registered via `bricks/builder/i18n`).
30 *
31 * @since 1.2.0
32 */
33 public const CATEGORY = 'suredonation';
34
35 /**
36 * Constructor — Bricks collects custom elements on init (priority 11,
37 * matching the SureForms integration).
38 *
39 * @since 1.2.0
40 */
41 public function __construct() {
42 add_action( 'init', [ $this, 'register_elements' ], 11 );
43 }
44
45 /**
46 * Register every SureDonation element with Bricks.
47 *
48 * @since 1.2.0
49 * @return void
50 */
51 public function register_elements() {
52 if ( ! class_exists( '\Bricks\Elements' ) ) {
53 return;
54 }
55
56 add_filter( 'bricks/builder/i18n', [ $this, 'bricks_translatable_strings' ] );
57
58 // Explicit class names are required: Bricks' fallback picks the last
59 // declared class after including the file, which would be the autoloaded
60 // Base_Element parent instead of the element itself. `::class` does not
61 // trigger the autoloader, so this stays fatal-safe without Bricks.
62 $elements = [
63 __DIR__ . '/elements/donation-form.php' => Elements\Donation_Form::class,
64 __DIR__ . '/elements/campaign-goal.php' => Elements\Campaign_Goal::class,
65 __DIR__ . '/elements/campaign-stats.php' => Elements\Campaign_Stats::class,
66 __DIR__ . '/elements/campaign-donations.php' => Elements\Campaign_Donations::class,
67 __DIR__ . '/elements/campaign-donors.php' => Elements\Campaign_Donors::class,
68 __DIR__ . '/elements/campaign-donate-button.php' => Elements\Campaign_Donate_Button::class,
69 __DIR__ . '/elements/campaign-social-sharing.php' => Elements\Campaign_Social_Sharing::class,
70 ];
71
72 foreach ( $elements as $file => $class_name ) {
73 \Bricks\Elements::register_element( $file, '', $class_name );
74 }
75 }
76
77 /**
78 * Register the SureDonation category label with the builder.
79 *
80 * @since 1.2.0
81 * @param array<string, string> $i18n Builder translatable strings.
82 * @return array<string, string>
83 */
84 public function bricks_translatable_strings( $i18n ) {
85 $i18n[ self::CATEGORY ] = __( 'SureDonation', 'suredonation' );
86 return $i18n;
87 }
88 }
89