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.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 All 211 releases
charitable / includes / admin / campaign-builder / class-builder-fields.php

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

261 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Handles loading all the field types (default and others possibly from optional addons) into the builder.
10 *
11 * @package Charitable
12 * @author David Bisset
13 * @copyright Copyright (c) 2023, WP Charitable LLC
14 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
15 * @since 1.8.0
16 * @version 1.8.0
17 */
18 class Charitable_Builder_Fields {
19
20 /**
21 * Current field data.
22 *
23 * @since 1.8.0
24 *
25 * @var array
26 */
27 public $pro_fields = array();
28
29 /**
30 * Primary class constructor.
31 *
32 * @since 1.8.0
33 */
34 public function __construct() {
35
36 $this->init();
37 }
38
39 /**
40 * Load and init the base field class.
41 *
42 * @since 1.8.0
43 */
44 public function init() {
45
46 // Parent class template.
47 require_once Charitable()->get_path( 'includes' ) . 'admin/campaign-builder/fields/class-base.php';
48
49 // WordPress hooks.
50 $this->hooks();
51 }
52
53 /**
54 * Hooks.
55 *
56 * @since 1.8.0
57 */
58 private function hooks() {
59
60 // Load default fields on WP init.
61 add_action( 'init', [ $this, 'load' ] );
62
63 add_filter( 'charitable_campaign_builder_load_fields', [ $this, 'load_pro_fields' ], 100, 2 );
64
65 add_filter( 'charitable_builder_field_button_attributes', [ $this, 'fields_attributes' ], 100, 2 );
66
67 add_filter( 'charitable_builder_design_buttons', [ $this, 'pro_field_buttons' ], 15 );
68
69 add_action( 'init', array( $this, 'setup_pro_addons' ), 999 ); // 1.8.3.5
70 }
71
72 /**
73 * Adds pro fields to the button list.
74 *
75 * @since 1.8.0
76 *
77 * @param array $fields Field types.
78 *
79 * @return array Fields array.
80 */
81 public function pro_field_buttons( $fields ) {
82
83 if ( false === $fields || ! is_array( $fields ) ) {
84 return $fields;
85 }
86
87 $fields['pro']['fields'] = (array) $this->pro_fields;
88
89 return $fields;
90 }
91
92 /**
93 * Load default field types.
94 *
95 * @since 1.8.0
96 */
97 public function load() {
98
99 $fields = [
100 'campaign-title',
101 'campaign-description',
102 'campaign-hero',
103 'donate-button',
104 'donate-amount',
105 'progress-bar',
106 // 'donation-options',
107 'photo',
108 'organizer',
109 'html',
110 'social-sharing',
111 'social-links',
112 'campaign-summary',
113 'donate-form',
114 'donor-wall',
115 'shortcode',
116 'text',
117 ];
118
119 /**
120 * Filters array of fields to be loaded.
121 *
122 * @since 1.0.0
123 *
124 * @param array $fields Field types.
125 */
126 $fields = (array) apply_filters(
127 'charitable_campaign_builder_load_fields',
128 $fields
129 );
130
131 if ( ! empty( $fields ) ) :
132
133 foreach ( $fields as $key => $field_type ) {
134
135 // reset the value.
136 $file_path = false;
137
138 if ( is_array( $field_type ) ) {
139
140 // if this is an array, it's likely "fnacy" and added by a plugin or addon so look for the key in the array for the field type.
141 $field_type_slug = key( $field_type );
142 $field_type = $field_type[ $field_type_slug ];
143
144 // where do we load the class, otherwise pick the "default" path inside core Charitable.
145 $file = isset( $field_type['file'] ) && ! empty( $field_type['file'] ) ? esc_html( $field_type['file'] ) : false;
146
147 if ( $file ) {
148 $file = wp_slash( charitable()->get_path( 'plugin-directory' ) ) . $file; // /wp-content/plugins/charitable-videos/includes/campaign-builder/fields/class-video.php
149 }
150
151 } else {
152
153 $file = charitable()->get_path( 'includes' ) . 'admin/campaign-builder/fields/class-' . $field_type . '.php';
154
155 }
156
157 if ( false !== $file && file_exists( $file ) ) {
158 require_once $file;
159 }
160
161 }
162
163 endif;
164
165 }
166
167 /**
168 * Filters array of "pro" fields form addons to be loaded.
169 *
170 * @since 1.8.0
171 */
172 public function setup_pro_addons() {
173
174 $this->pro_fields = (array) apply_filters( // phpcs:ignore Charitable.PHP.ValidateHooks.InvalidHookName
175 'charitable_load_campaign_builder_pro_fields',
176 array(
177 'donor-comments' => array(
178 'order' => '250',
179 'name' => esc_html__( 'Donor Comments', 'charitable' ),
180 'type' => 'donor-comments',
181 'icon' => 'fa-comment',
182 'class' => 'pro',
183 'addon' => 'donor-comments',
184 ),
185 'ambassadors-team' => array(
186 'order' => '500',
187 'name' => esc_html__( 'Team', 'charitable' ),
188 'type' => 'team',
189 'icon' => 'fa-users',
190 'class' => 'pro',
191 'addon' => 'ambassador',
192 ),
193 'simple-updates' => array(
194 'order' => '750',
195 'name' => esc_html__( 'Updates', 'charitable' ),
196 'type' => 'simple-updates',
197 'icon' => 'fa-bullhorn',
198 'class' => 'pro',
199 'addon' => 'simple-updates',
200 ),
201 'video' => array(
202 'order' => '1000',
203 'name' => esc_html__( 'Video', 'charitable' ),
204 'type' => 'video',
205 'icon' => 'fa-film',
206 'class' => 'pro',
207 'addon' => 'video',
208 ),
209 )
210 );
211 }
212
213 /**
214 * Filters array of fields to be loaded.
215 *
216 * @since 1.8.0
217 *
218 * @param array $fields Field types.
219 */
220 public function load_pro_fields( $fields = false ) {
221
222 if ( false === $fields ) {
223 $fields = array();
224 }
225
226 foreach ( $this->pro_fields as $pro_field ) {
227 if ( ! key_exists( $pro_field['type'], $fields ) ) {
228 $fields[] = array( $pro_field['type'] => $pro_field );
229 }
230 }
231
232 return $fields;
233
234 }
235
236 /**
237 * Adjust attributes on field buttons.
238 *
239 * @since 1.8.0
240 *
241 * @param array $atts Button attributes.
242 * @param array $field Button properties.
243 *
244 * @return array Attributes array.
245 */
246 public function fields_attributes( $atts, $field ) {
247
248 if ( ! charitable_is_pro() && ! empty( $field['class'] ) && $field['class'] === 'pro' ) {
249 $atts['class'][] = 'charitable-not-available';
250 } elseif ( charitable_is_pro() && ! empty( $field['class'] ) && $field['class'] === 'pro' ) {
251 $atts['class'][] = 'charitable-not-installed';
252 }
253
254 return $atts;
255 }
256
257
258 }
259
260 new Charitable_Builder_Fields();
261