PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.1
1.6.1 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 / elementor / service-provider.php

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

151 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor service provider.
4 *
5 * Registers the SureDonation widget category and all campaign/donation widgets
6 * with Elementor, and loads the campaign block styles into the editor preview
7 * so the widgets render styled while editing.
8 *
9 * @package SureDonation
10 * @since 1.2.0
11 */
12
13 namespace SureDonation\Inc\Page_Builders\Elementor;
14
15 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Donate_Button_Widget;
16 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Donations_Widget;
17 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Donor_Comments_Widget;
18 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Donors_Widget;
19 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Goal_Widget;
20 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Social_Sharing_Widget;
21 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Campaign_Stats_Widget;
22 use SureDonation\Inc\Page_Builders\Elementor\Widgets\Donation_Form_Widget;
23 use SureDonation\Inc\Traits\Get_Instance;
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit; // Exit if accessed directly.
27 }
28
29 /**
30 * Service_Provider class.
31 *
32 * @since 1.2.0
33 */
34 class Service_Provider {
35 use Get_Instance;
36
37 /**
38 * Widget category slug.
39 *
40 * @since 1.2.0
41 */
42 public const CATEGORY = 'suredonation';
43
44 /**
45 * Constructor — register hooks only when Elementor is available.
46 *
47 * @since 1.2.0
48 */
49 public function __construct() {
50 if ( ! class_exists( '\Elementor\Plugin' ) ) {
51 return;
52 }
53
54 add_action( 'elementor/elements/categories_registered', [ $this, 'register_category' ] );
55 add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] );
56 add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_preview_assets' ] );
57 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_assets' ] );
58 }
59
60 /**
61 * Load the editor-panel script that backs the Donation Form widget's
62 * "Edit Form" button.
63 *
64 * Runs in the Elementor editor panel (not the preview iframe), which is
65 * where the control's `event` is broadcast on `elementor.channels.editor`.
66 *
67 * @since 1.4.0
68 * @return void
69 */
70 public function enqueue_editor_assets() {
71 wp_enqueue_script(
72 'suredonation-elementor-editor',
73 plugins_url( 'assets/editor.js', __FILE__ ),
74 [],
75 SUREDONATION_VER,
76 true
77 );
78
79 wp_localize_script(
80 'suredonation-elementor-editor',
81 'suredonationElementorData',
82 [
83 'adminUrl' => admin_url(),
84 ]
85 );
86 }
87
88 /**
89 * Register the SureDonation widget category.
90 *
91 * @since 1.2.0
92 * @param \Elementor\Elements_Manager $elements_manager Elementor elements manager.
93 * @return void
94 */
95 public function register_category( $elements_manager ) {
96 if ( ! method_exists( $elements_manager, 'add_category' ) ) {
97 return;
98 }
99
100 $elements_manager->add_category(
101 self::CATEGORY,
102 [
103 'title' => esc_html__( 'SureDonation', 'suredonation' ),
104 'icon' => 'eicon-heart',
105 ]
106 );
107 }
108
109 /**
110 * Register every SureDonation widget.
111 *
112 * @since 1.2.0
113 * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
114 * @return void
115 */
116 public function register_widgets( $widgets_manager ) {
117 if ( ! method_exists( $widgets_manager, 'register' ) ) {
118 return;
119 }
120
121 $widget_classes = [
122 Donation_Form_Widget::class,
123 Campaign_Goal_Widget::class,
124 Campaign_Stats_Widget::class,
125 Campaign_Donations_Widget::class,
126 Campaign_Donor_Comments_Widget::class,
127 Campaign_Donors_Widget::class,
128 Campaign_Donate_Button_Widget::class,
129 Campaign_Social_Sharing_Widget::class,
130 ];
131
132 // Construct inside the loop so one broken widget can't abort
133 // registration of the others.
134 foreach ( $widget_classes as $widget_class ) {
135 $widgets_manager->register( new $widget_class() );
136 }
137 }
138
139 /**
140 * Load the campaign block styles into the Elementor editor preview so the
141 * server-rendered widgets look correct while editing. On the front end each
142 * block's render_callback enqueues the same handle itself.
143 *
144 * @since 1.2.0
145 * @return void
146 */
147 public function enqueue_preview_assets() {
148 wp_enqueue_style( 'suredonation-campaign-blocks' );
149 }
150 }
151