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
← All changes | includes/campaigns/class-charitable-campaign-processor.php +86 -22 1.7.0 → 1.8.13 View file →
@@ -3,9 +3,9 @@
3 3 * Class that is responsible for creating campaigns.
4 4 *
5 5 * @package Charitable/Classes/Charitable_Campaign_Processor
6 6 * @author David Bisset
7 - * @copyright Copyright (c) 2022, WP Charitable LLC
7 + * @copyright Copyright (c) 2023, WP Charitable LLC
8 8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 9 * @since 1.5.9
10 10 * @version 1.6.54
11 11 */
@@ -60,8 +60,17 @@
60 60 */
61 61 protected $meta_keys;
62 62
63 63 /**
64 + * Campaign id.
65 + *
66 + * @since 1.5.9
67 + *
68 + * @var array
69 + */
70 + public $campaign_id;
71 +
72 + /**
64 73 * Create class object.
65 74 *
66 75 * @since 1.5.9
67 76 *
@@ -82,10 +91,12 @@
82 91 $this->meta_keys = is_array( $meta_keys ) ? $meta_keys : array(
83 92 'goal',
84 93 'end_date',
85 94 'suggested_donations',
95 + 'suggested_donations_default',
86 96 'allow_custom_donations',
87 97 'description',
98 + 'minimum_donation_amount',
88 99 );
89 100
90 101 $this->parse_args();
91 102 }
@@ -132,9 +143,10 @@
132 143 /**
133 144 * If a class sanitization method exists for this key, call it.
134 145 */
135 146 if ( $this->use_sanitizer( $key ) ) {
136 - $value = call_user_func( array( $this, 'sanitize_' . $key ), $value );
147 + $sanitizer_method = 'sanitize_' . $key;
148 + $value = $this->$sanitizer_method( $value );
137 149 }
138 150
139 151 /**
140 152 * Filter a campaign argument when it is set.
@@ -154,8 +166,9 @@
154 166 *
155 167 * @return int The campaign ID, or 0 if the campaign was not created.
156 168 */
157 169 public function save() {
170 +
158 171 $this->campaign_id = $this->save_core();
159 172
160 173 if ( ! $this->campaign_id || is_wp_error( $this->campaign_id ) ) {
161 174 return 0;
@@ -170,8 +183,9 @@
170 183 /**
171 184 * Save the core data.
172 185 *
173 186 * @since 1.5.9
187 + * @since 1.8.1 Added two action hooks.
174 188 *
175 189 * @return int|WP_Error The donation ID if succesful. The value 0 or WP_Error on failure.
176 190 */
177 191 public function save_core() {
@@ -191,12 +205,39 @@
191 205 /**
192 206 * Update or insert the campaign.
193 207 */
194 208 if ( $data['ID'] ) {
195 - return wp_update_post( $data );
209 +
210 + // The returned value can be either the campaign_id or 0 on fail.
211 + $campaign_id = wp_update_post( $data );
212 +
213 + /**
214 + * Peform an action after the campaign has been updated.
215 + *
216 + * @since 1.8.1
217 + *
218 + * @param array $data Core data.
219 + * @param Charitable_Campaign_Processor $processor This processor object.
220 + */
221 + do_action( 'charitable_campaign_processor_save_core', 'update', $campaign_id, $data, $this );
222 +
223 + return $campaign_id;
196 224 }
197 225
198 - return wp_insert_post( $data );
226 + // The returned value can be either the campaign_id or 0 on fail.
227 + $campaign_id = wp_insert_post( $data );
228 +
229 + /**
230 + * Peform an action after the campaign has been updated.
231 + *
232 + * @since 1.8.1
233 + *
234 + * @param array $data Core data.
235 + * @param Charitable_Campaign_Processor $processor This processor object.
236 + */
237 + do_action( 'charitable_campaign_processor_save_core', 'insert', $campaign_id, $data, $this );
238 +
239 + return $campaign_id;
199 240 }
200 241
201 242 /**
202 243 * Save the campaign meta data.
@@ -214,8 +255,9 @@
214 255 *
215 256 * @param array $meta Meta data.
216 257 * @param Charitable_Campaign_Processor $processor This processor object.
217 258 */
259 +
218 260 $meta = apply_filters( 'charitable_campaign_processor_meta_data', charitable_array_subset( $this->args, $this->meta_keys ), $this );
219 261
220 262 array_walk( $meta, array( $this, 'save_meta_field' ) );
221 263
@@ -298,22 +340,24 @@
298 340 */
299 341 return apply_filters(
300 342 'charitable_campaign_processor_default_args',
301 343 array(
302 - 'ID' => 0,
303 - 'title' => '',
304 - 'content' => '',
305 - 'creator' => get_current_user_id(),
306 - 'status' => 'publish',
307 - 'parent' => 0,
308 - 'image' => 0,
309 - 'description' => '',
310 - 'goal' => 0,
311 - 'end_date' => 0,
312 - 'suggested_donations' => array(),
313 - 'allow_custom_donations' => 1,
314 - 'categories' => array(),
315 - 'tags' => array(),
344 + 'ID' => 0,
345 + 'title' => '',
346 + 'content' => '',
347 + 'creator' => get_current_user_id(),
348 + 'status' => 'publish',
349 + 'parent' => 0,
350 + 'image' => 0,
351 + 'description' => '',
352 + 'goal' => 0,
353 + 'end_date' => 0,
354 + 'suggested_donations' => array(),
355 + 'suggested_donations_default' => 0,
356 + 'allow_custom_donations' => 1,
357 + 'categories' => array(),
358 + 'tags' => array(),
359 + 'minimum_donation_amount' => 0,
316 360 )
317 361 );
318 362 }
319 363
@@ -423,8 +467,24 @@
423 467 return Charitable_Campaign::sanitize_campaign_suggested_donations( $value );
424 468 }
425 469
426 470 /**
471 + * Sanitize the suggested donations default
472 + *
473 + * @since 1.5.9
474 + *
475 + * @param arrat $value Current value of suggested_donations.
476 + * @return array
477 + */
478 + protected function sanitize_suggested_donations_default( $value ) {
479 + if ( $this->should_skip_sanitizer_for_key( 'suggested_donations_default', array( 'Charitable_Campaign', 'sanitize_campaign_suggested_donations' ) ) ) {
480 + return $value;
481 + }
482 +
483 + return Charitable_Campaign::sanitize_campaign_suggested_donations_default( $value );
484 + }
485 +
486 + /**
427 487 * Sanitize the custom donations checkbox.
428 488 *
429 489 * @since 1.5.9
430 490 *
@@ -490,8 +550,9 @@
490 550
491 551 if ( ! $this->is_mysql_date_format( $value ) ) {
492 552 charitable_get_deprecated()->doing_it_wrong(
493 553 __METHOD__,
554 + // Translators: %s is the date passed.
494 555 sprintf( __( 'Campaign processor requires date in YYYY-MM-DD format. Date passed as %s. This message was added in Charitable version 1.5.9.', 'charitable' ), $value ),
495 556 null
496 557 );
497 558
@@ -573,18 +634,19 @@
573 634 * @param mixed $value The value of the meta field.
574 635 * @param string $key The key of the meta field.
575 636 * @return void
576 637 */
577 - protected function save_meta_field( $value, $key ) {
638 + public function save_meta_field( $value, $key ) {
578 639 update_post_meta( $this->campaign_id, $this->get_meta_key( $key ), $value );
579 640
580 641 if ( method_exists( $this, 'post_process_' . $key ) ) {
581 - call_user_func( array( $this, 'post_process_' . $key ), $value );
642 + $post_process_method = 'post_process_' . $key;
643 + $this->$post_process_method( $value );
582 644 }
583 645 }
584 646
585 647 /**
586 - * Returns a sanitized meta key.
648 + * Returns a sanitized meta key.
587 649 *
588 650 * @since 1.5.9
589 651 *
590 652 * @param string $key The key to be sanitized.
@@ -648,9 +710,11 @@
648 710 $method = is_array( $callback ) ? implode( '::', $callback ) : $method;
649 711
650 712 charitable_get_deprecated()->doing_it_wrong(
651 713 $tag,
652 - sprintf( __( '%s is deprecated as a sanitizer on the %s hook. To prevent sanitization, use add_filter( \'charitable_campaign_processor_disable_sanitizer_%s\', \'__return_true\' ) instead.', 'charitable' ),
714 + sprintf(
715 + // Translators: %1$s is the method, %2$s is the tag, %3$s is the key.
716 + __( '%1$s is deprecated as a sanitizer on the %2$s hook. To prevent sanitization, use add_filter( \'charitable_campaign_processor_disable_sanitizer_%3$s\', \'__return_true\' ) instead.', 'charitable' ),
653 717 $method,
654 718 $tag,
655 719 $key
656 720 ),