← All changes
|
includes/campaigns/class-charitable-campaign-processor.php
+66
-23
1.7.0.12
→
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 | * |
| @@ -134,9 +143,10 @@ | ||
| 134 | 143 | /** |
| 135 | 144 | * If a class sanitization method exists for this key, call it. |
| 136 | 145 | */ |
| 137 | 146 | if ( $this->use_sanitizer( $key ) ) { |
| 138 | - $value = call_user_func( array( $this, 'sanitize_' . $key ), $value ); | |
| 147 | + $sanitizer_method = 'sanitize_' . $key; | |
| 148 | + $value = $this->$sanitizer_method( $value ); | |
| 139 | 149 | } |
| 140 | 150 | |
| 141 | 151 | /** |
| 142 | 152 | * Filter a campaign argument when it is set. |
| @@ -156,8 +166,9 @@ | ||
| 156 | 166 | * |
| 157 | 167 | * @return int The campaign ID, or 0 if the campaign was not created. |
| 158 | 168 | */ |
| 159 | 169 | public function save() { |
| 170 | + | |
| 160 | 171 | $this->campaign_id = $this->save_core(); |
| 161 | 172 | |
| 162 | 173 | if ( ! $this->campaign_id || is_wp_error( $this->campaign_id ) ) { |
| 163 | 174 | return 0; |
| @@ -172,8 +183,9 @@ | ||
| 172 | 183 | /** |
| 173 | 184 | * Save the core data. |
| 174 | 185 | * |
| 175 | 186 | * @since 1.5.9 |
| 187 | + * @since 1.8.1 Added two action hooks. | |
| 176 | 188 | * |
| 177 | 189 | * @return int|WP_Error The donation ID if succesful. The value 0 or WP_Error on failure. |
| 178 | 190 | */ |
| 179 | 191 | public function save_core() { |
| @@ -193,12 +205,39 @@ | ||
| 193 | 205 | /** |
| 194 | 206 | * Update or insert the campaign. |
| 195 | 207 | */ |
| 196 | 208 | if ( $data['ID'] ) { |
| 197 | - 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; | |
| 198 | 224 | } |
| 199 | 225 | |
| 200 | - 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; | |
| 201 | 240 | } |
| 202 | 241 | |
| 203 | 242 | /** |
| 204 | 243 | * Save the campaign meta data. |
| @@ -301,24 +340,24 @@ | ||
| 301 | 340 | */ |
| 302 | 341 | return apply_filters( |
| 303 | 342 | 'charitable_campaign_processor_default_args', |
| 304 | 343 | array( |
| 305 | - 'ID' => 0, | |
| 306 | - 'title' => '', | |
| 307 | - 'content' => '', | |
| 308 | - 'creator' => get_current_user_id(), | |
| 309 | - 'status' => 'publish', | |
| 310 | - 'parent' => 0, | |
| 311 | - 'image' => 0, | |
| 312 | - 'description' => '', | |
| 313 | - 'goal' => 0, | |
| 314 | - 'end_date' => 0, | |
| 315 | - 'suggested_donations' => 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(), | |
| 316 | 355 | 'suggested_donations_default' => 0, |
| 317 | - 'allow_custom_donations' => 1, | |
| 318 | - 'categories' => array(), | |
| 319 | - 'tags' => array(), | |
| 320 | - 'minimum_donation_amount' => 0, | |
| 356 | + 'allow_custom_donations' => 1, | |
| 357 | + 'categories' => array(), | |
| 358 | + 'tags' => array(), | |
| 359 | + 'minimum_donation_amount' => 0, | |
| 321 | 360 | ) |
| 322 | 361 | ); |
| 323 | 362 | } |
| 324 | 363 | |
| @@ -511,8 +550,9 @@ | ||
| 511 | 550 | |
| 512 | 551 | if ( ! $this->is_mysql_date_format( $value ) ) { |
| 513 | 552 | charitable_get_deprecated()->doing_it_wrong( |
| 514 | 553 | __METHOD__, |
| 554 | + // Translators: %s is the date passed. | |
| 515 | 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 ), |
| 516 | 556 | null |
| 517 | 557 | ); |
| 518 | 558 | |
| @@ -594,18 +634,19 @@ | ||
| 594 | 634 | * @param mixed $value The value of the meta field. |
| 595 | 635 | * @param string $key The key of the meta field. |
| 596 | 636 | * @return void |
| 597 | 637 | */ |
| 598 | - protected function save_meta_field( $value, $key ) { | |
| 638 | + public function save_meta_field( $value, $key ) { | |
| 599 | 639 | update_post_meta( $this->campaign_id, $this->get_meta_key( $key ), $value ); |
| 600 | 640 | |
| 601 | 641 | if ( method_exists( $this, 'post_process_' . $key ) ) { |
| 602 | - call_user_func( array( $this, 'post_process_' . $key ), $value ); | |
| 642 | + $post_process_method = 'post_process_' . $key; | |
| 643 | + $this->$post_process_method( $value ); | |
| 603 | 644 | } |
| 604 | 645 | } |
| 605 | 646 | |
| 606 | 647 | /** |
| 607 | - * Returns a sanitized meta key. | |
| 648 | + * Returns a sanitized meta key. | |
| 608 | 649 | * |
| 609 | 650 | * @since 1.5.9 |
| 610 | 651 | * |
| 611 | 652 | * @param string $key The key to be sanitized. |
| @@ -669,9 +710,11 @@ | ||
| 669 | 710 | $method = is_array( $callback ) ? implode( '::', $callback ) : $method; |
| 670 | 711 | |
| 671 | 712 | charitable_get_deprecated()->doing_it_wrong( |
| 672 | 713 | $tag, |
| 673 | - 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' ), | |
| 674 | 717 | $method, |
| 675 | 718 | $tag, |
| 676 | 719 | $key |
| 677 | 720 | ), |