PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.3
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 / admin / campaign-builder / functions-legacy.php

functions-legacy.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.3, at includes/admin/campaign-builder/functions-legacy.php

88 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * General functions made for the campaign builder interacts with legacy campaigns.
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.1.12
10 * @version 1.8.1.14
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 add_action( 'charitable_campaign_save', 'charitable_legacy_campaign_save', 10, 1 );
19
20 /**
21 * Do something with the posted data.
22 *
23 * @since 1.8.1.12
24 * @version 1.8.9.1
25 *
26 * @param WP_Post $post An instance of `WP_Post`.
27 */
28 function charitable_legacy_campaign_save( $post ) {
29
30 // check and see if $post is an instance of 'WP_Post'.
31 if ( empty( $post ) || ! $post instanceof WP_Post ) {
32 return;
33 }
34
35 if ( defined( 'CHARITABLE_DISABLE_LEGACY_SYNC_TO_BUILDER' ) && CHARITABLE_DISABLE_LEGACY_SYNC_TO_BUILDER ) { // phpcs:ignore
36 return;
37 }
38
39 $campaign_id = ! empty( $post->ID ) ? $post->ID : 0;
40
41 if ( $campaign_id <= 0 ) {
42 return;
43 }
44
45 // Fetch campaign details.
46 $campaign_settings_v2 = (array) get_post_meta( $campaign_id, 'campaign_settings_v2', true );
47
48 // Clean house.
49 $campaign_settings_v2 = array_filter( $campaign_settings_v2 );
50
51 // If the campaign settings are empty, then this was never created in the new builder.
52 if ( empty( $campaign_settings_v2 ) ) {
53 return;
54 }
55
56 // phpcs:disable WordPress.Security.NonceVerification.Missing
57 // --- Campaign Goal.
58 $_campaign_goal = ! empty( $_POST['_campaign_goal'] ) ? sanitize_text_field( wp_unslash( $_POST['_campaign_goal'] ) ) : false;
59
60 // Sanitize some misc fields.
61 $campaign_settings_v2['settings']['general']['goal'] = ! empty( $_campaign_goal ) ? Charitable_Currency::get_instance()->sanitize_monetary_amount( (string) $_campaign_goal ) : false;
62 $campaign_settings_v2['settings']['general']['goal'] = '0' === $campaign_settings_v2['settings']['general']['goal'] ? '' : $campaign_settings_v2['settings']['general']['goal'];
63
64 // if the money values are negative, make it positive.
65 if ( ! empty( $campaign_settings_v2['settings']['general']['goal'] ) && '-' === substr( $campaign_settings_v2['settings']['general']['goal'], 0, 1 ) ) {
66 $campaign_settings_v2['settings']['general']['goal'] = substr( $campaign_settings_v2['settings']['general']['goal'], 1 );
67 }
68 if ( ! empty( $campaign_settings_v2['settings']['donation-options']['minimum_donation_amount'] ) && '-' === substr( $campaign_settings_v2['settings']['donation-options']['minimum_donation_amount'], 0, 1 ) ) {
69 $campaign_settings_v2['settings']['donation-options']['minimum_donation_amount'] = substr( $campaign_settings_v2['settings']['donation-options']['minimum_donation_amount'], 1 );
70 }
71
72 // --- End Date.
73 $end_date_raw = ! empty( $_POST['_campaign_end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['_campaign_end_date'] ) ) : '';
74 $end_time_raw = isset( $_POST['_campaign_end_time'] ) ? sanitize_text_field( wp_unslash( $_POST['_campaign_end_time'] ) ) : '';
75 $_end_date = ! empty( $end_date_raw ) ? $end_date_raw . ' ' . $end_time_raw : '';
76
77 $campaign_settings_v2['settings']['general']['end_date'] = Charitable_Campaign::sanitize_campaign_end_date( $_end_date );
78
79 // --- Title.
80 $campaign_settings_v2['title'] = ! empty( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : false;
81
82 // --- Description.
83 $campaign_settings_v2['settings']['general']['description'] = ! empty( $_POST['post_content'] ) ? sanitize_textarea_field( wp_unslash( $_POST['post_content'] ) ) : false;
84 // phpcs:enable WordPress.Security.NonceVerification.Missing
85
86 update_post_meta( $campaign_id, 'campaign_settings_v2', $campaign_settings_v2 );
87 }
88