PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / elementor / widgets / class-charitable-elementor-campaign-widget.php

class-charitable-elementor-campaign-widget.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/elementor/widgets/class-charitable-elementor-campaign-widget.php

181 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Charitable Campaign Widget
5 *
6 * @package Elementor_Example_Plugin
7 */
8
9 if (! defined('ABSPATH')) {
10 exit; // Exit if accessed directly.
11 }
12
13 /**
14 * Class Charitable_Campaign_Widget
15 */
16 class Charitable_Elementor_Campaign_Widget extends \Elementor\Widget_Base
17 {
18 /**
19 * Get widget name.
20 *
21 * @return string Widget name.
22 */
23 public function get_name()
24 {
25 return 'charitable_campaign';
26 }
27
28 /**
29 * Get widget title.
30 *
31 * @return string Widget title.
32 */
33 public function get_title()
34 {
35 return esc_html__('Campaign', 'charitable');
36 }
37
38 /**
39 * Get widget icon.
40 *
41 * @return string Widget icon.
42 */
43 public function get_icon()
44 {
45 return 'eicon-site-identity';
46 }
47
48 /**
49 * Get widget categories.
50 *
51 * @return array Widget categories.
52 */
53 public function get_categories()
54 {
55 return array( 'wpcharitable' );
56 }
57
58 /**
59 * Register widget controls.
60 */
61 protected function register_controls()
62 {
63 // Content Section.
64 $this->start_controls_section(
65 'content_section',
66 array(
67 'label' => esc_html__('Content', 'charitable'),
68 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
69 )
70 );
71
72 $this->add_control(
73 'title',
74 array(
75 'label' => esc_html__('Title', 'charitable'),
76 'type' => \Elementor\Controls_Manager::TEXT,
77 'default' => esc_html__('Campaign', 'charitable'),
78 )
79 );
80
81 // Get campaigns for dropdown.
82 $campaigns = get_posts(
83 array(
84 'post_type' => 'campaign',
85 'numberposts' => -1,
86 'orderby' => 'title',
87 'order' => 'ASC',
88 )
89 );
90
91 $campaign_options = array();
92 foreach ($campaigns as $campaign) {
93 $campaign_options[ $campaign->ID ] = $campaign->post_title;
94 }
95
96 $this->add_control(
97 'campaign_id',
98 array(
99 'label' => esc_html__('Select Campaign', 'charitable'),
100 'type' => \Elementor\Controls_Manager::SELECT,
101 'options' => $campaign_options,
102 'label_block' => true,
103 'dynamic' => ['active' => true],
104 )
105 );
106
107
108 $this->end_controls_section();
109
110 // Style Section.
111 $this->start_controls_section(
112 'style_section',
113 array(
114 'label' => esc_html__('Style', 'charitable'),
115 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
116 )
117 );
118
119 $this->add_responsive_control(
120 'padding',
121 array(
122 'label' => esc_html__('Padding', 'charitable'),
123 'type' => \Elementor\Controls_Manager::DIMENSIONS,
124 'size_units' => array( 'px', 'em', '%' ),
125 'selectors' => array(
126 '{{WRAPPER}} .charitable-campaign-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
127 ),
128 )
129 );
130
131 $this->add_group_control(
132 \Elementor\Group_Control_Border::get_type(),
133 array(
134 'name' => 'border',
135 'selector' => '{{WRAPPER}} .charitable-campaign-wrapper',
136 )
137 );
138
139 $this->add_control(
140 'background_color',
141 array(
142 'label' => esc_html__('Background Color', 'charitable'),
143 'type' => \Elementor\Controls_Manager::COLOR,
144 'selectors' => array(
145 '{{WRAPPER}} .charitable-campaign-wrapper' => 'background-color: {{VALUE}};',
146 ),
147 )
148 );
149
150 $this->end_controls_section();
151 }
152
153 /**
154 * Render widget output on the frontend.
155 */
156 protected function render()
157 {
158 $settings = $this->get_settings_for_display();
159
160 $output = '<div class="charitable-campaign-wrapper">';
161 if (! empty($settings['title'])) {
162 $output .= '<h2 class="charitable-campaign-title">' . esc_html($settings['title']) . '</h2>';
163 }
164
165 if (! empty($settings['campaign_id'])) {
166 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
167 $shortcode = sprintf('[campaign id="%d"]', absint($settings['campaign_id']));
168 } else {
169 $shortcode = sprintf('[campaign id="%d"]', absint($settings['campaign_id']));
170 }
171
172 $output .= do_shortcode($shortcode);
173 }
174 $output .= '</div>';
175
176 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
177 }
178
179
180 }
181