PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12
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 1.7.0.9 1.8.0 All 210 releases
charitable / includes / admin / campaign-builder / fields / class-shortcode.php

class-shortcode.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12, at includes/admin/campaign-builder/fields/class-shortcode.php

256 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class to add donation options to a campaign form in the builder.
4 *
5 * @package Charitable
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.0
10 * @version 1.8.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Field_Shortcode' ) ) :
18
19 /**
20 * Class to add campaign shortcode field to a campaign form in the builder.
21 */
22 class Charitable_Field_Shortcode extends Charitable_Builder_Field {
23
24 /**
25 * Primary class constructor.
26 *
27 * @since 1.8.0
28 */
29 public function init() {
30
31 // Define field type information.
32 $this->name = esc_html__( 'Shortcode', 'charitable' );
33 $this->type = 'shortcode';
34 $this->icon = 'fa-code';
35 $this->order = 1000;
36
37 // Edit/Duplication information.
38 $this->can_be_edited = true;
39 $this->can_be_deleted = true;
40 $this->can_be_duplicated = true;
41 $this->edit_label = esc_html__( 'Edit Shotcode', 'charitable' );
42 $this->edit_type = 'shortcode'; // was settings.
43 $this->edit_section = 'standard';
44
45 // Misc.
46 $this->tooltip = esc_html__( 'Display any valid WordPress shortcode.', 'charitable' );
47 }
48
49 /**
50 * Donation Options options panel inside the builder.
51 *
52 * @since 1.8.0
53 *
54 * @param array $field Donation Options settings.
55 */
56 public function field_options( $field ) {
57 /*
58 * Basic field options.
59 */
60
61 // Options open markup.
62 }
63
64 /**
65 * Donation Options preview inside the builder.
66 *
67 * @since 1.8.0
68 *
69 * @param array $field_data Field data and settings.
70 * @param array $campaign_data Campaign data and settings.
71 * @param array $field_id Field ID.
72 * @param string $theme Template data.
73 * @version 1.8.9.1
74 */
75 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
76
77 $headline = ! empty( $field_data['headline'] ) ? esc_html( $field_data['headline'] ) : false;
78 $shortcode = ! empty( $field_data['shortcode'] ) ? $this->format_for_output( $field_data['shortcode'], $campaign_data ) : false;
79
80 $title_html = $this->field_title( $this->name );
81
82 $html = '<div class="charitable-field-preview-shortcode shortcode" data-field-type="' . $this->type . '">
83 <div class="placeholder"><h5 class="charitable-field-preview-headline">' . $headline . '</h5></div>
84 <div class="row">
85 <div class="column">
86 <span class="placeholder shortcode-preview">' . $shortcode . '</span>
87 </div>
88 </div>
89 </div>';
90
91 $final_html = $title_html . $this->field_wrapper( $html, $field_data );
92
93 echo $final_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
94 }
95
96 /**
97 * Donation Options display on the form front-end.
98 *
99 * @since 1.8.0
100 * @version 1.8.8.6
101 *
102 * @param array $field Donation Options settings.
103 * @param array $deprecated Deprecated.
104 * @param array $form_data Form data and settings.
105 */
106 public function field_display( $field, $field_data = false, $campaign_data = false ) {
107
108 $campaign = isset( $campaign_data['id'] ) && 0 !== intval( $campaign_data['id'] ) ? charitable_get_campaign( $campaign_data['id'] ) : false;
109
110 if ( ! $campaign ) {
111 return;
112 }
113
114 $shortcode = ! empty( $field_data['shortcode'] ) ? $this->format_for_output( $field_data['shortcode'], $campaign_data ) : false;
115 $css_class = ! empty( $field_data['css_class'] ) ? ' class="' . esc_attr( $field_data['css_class'] ) . '" ' : '';
116
117 ob_start();
118
119 if ( $shortcode ) :
120
121 ?>
122
123 <div class="charitable-campaign-field_<?php echo esc_attr( $this->type ); ?>">
124 <div <?php echo $css_class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $css_class is already escaped with esc_attr() on line 115. ?>>
125 <?php if ( $shortcode ) : ?>
126 <?php echo do_shortcode( $shortcode ); ?>
127 <?php endif; ?>
128 </div>
129 </div>
130
131 <?php
132
133 endif;
134
135 $html = ob_get_clean();
136
137 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
138 }
139
140 /**
141 * The display on the form settings backend when the user clicks on the field/block.
142 *
143 * @since 1.8.0
144 * @version 1.8.9.1
145 *
146 * @param array $field Social Sharing settings.
147 * @param array $campaign_data Campaign data and settings.
148 */
149 public function settings_display( $field_id = false, $campaign_data = false ) {
150
151 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
152
153 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
154
155 ob_start();
156
157 ?>
158
159 <h4 class="charitable-panel-field" data-field-id="<?php echo intval( $field_id ); ?>"><?php echo esc_html( $this->name ); ?> (ID: <?php echo intval( $field_id ); ?>)</h4>
160
161 <?php
162
163 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
164 isset( $settings['headline'] ) ? $settings['headline'] : '',
165 esc_html__( 'Headline', 'charitable' ),
166 array(
167 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore
168 'name' => array( '_fields', intval( $field_id ), 'headline' ),
169 'field_id' => intval( $field_id ),
170 'tooltip' => esc_html__( 'Add a headline to this field.', 'charitable' ),
171 'class' => 'charitable-campaign-builder-headline',
172 )
173 );
174
175 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
176 isset( $settings['shortcode'] ) ? $this->format_for_setting( $settings['shortcode'] ) : false,
177 esc_html__( 'Shortcode', 'charitable' ),
178 array(
179 'id' => 'field_' . esc_attr( $this->type ) . '_shortcode' . '_' . intval( $field_id ), // phpcs:ignore
180 'name' => array( '_fields', intval( $field_id ), 'shortcode' ),
181 'field_id' => intval( $field_id ),
182 'tooltip' => esc_html( $this->tooltip ),
183 'class' => 'charitable-campaign-builder-shortcode',
184 )
185 );
186
187 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
188 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
189 esc_html__( 'CSS Class', 'charitable' ),
190 array(
191 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ),
192 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
193 'field_id' => intval( $field_id ),
194 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
195 )
196 );
197
198 ?>
199
200 <?php
201
202 $html = ob_get_clean();
203
204 return $html;
205 }
206
207 /**
208 * Enqueue frontend limit option js.
209 *
210 * @since 1.8.0
211 *
212 * @param array $forms Forms on the current page.
213 */
214 public function frontend_js( $forms ) {
215 }
216
217 /**
218 * Format and sanitize field value for builder, in the setting left pane.
219 *
220 * @since 1.8.0
221 *
222 * @param int $field_value The value.
223 */
224 public function format_for_setting( $field_value = false ) {
225
226 return htmlspecialchars( $field_value ); // this will convert quotes, usually used in shortcodes.
227 }
228
229 /**
230 * Format and sanitize field, for use in the frontend (preview and campaign page).
231 *
232 * @since 1.8.0
233 *
234 * @param int $field_value The value.
235 */
236 public function format_for_output( $field_value = false, $campaign_data = false ) {
237
238 return $field_value;
239 }
240
241 /**
242 * Validate field on form submit.
243 *
244 * @since 1.8.0
245 *
246 * @param int $field_id Donation Options ID.
247 * @param mixed $field_submit Donation Options value that was submitted.
248 * @param array $form_data Form data and settings.
249 */
250 public function validate( $field_id, $field_submit, $form_data ) {
251 }
252 }
253
254 new Charitable_Field_Shortcode();
255
256 endif;