| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Privacy Functions. |
| 4 |
* |
| 5 |
* @package Charitable/Functions/Privacy |
| 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.6.2 |
| 10 |
* @version 1.6.2 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Check whether the terms and conditions field is active. |
| 20 |
* |
| 21 |
* This returns true when the "terms_conditions" and the "terms_conditions_page" |
| 22 |
* settings are not empty. |
| 23 |
* |
| 24 |
* @since 1.6.2 |
| 25 |
* |
| 26 |
* @return boolean |
| 27 |
*/ |
| 28 |
function charitable_is_terms_and_conditions_activated() { |
| 29 |
return 0 !== charitable_get_option( 'terms_conditions_page', 0 ) |
| 30 |
&& 0 !== charitable_get_option( 'terms_and_conditions_enabled', 0 ) |
| 31 |
&& '' !== charitable_get_option( 'terms_conditions', __( 'I have read and agree to the website [terms].', 'charitable' ) ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Check whether the privacy policy is active. |
| 36 |
* |
| 37 |
* This returns true when the "privacy_policy" and the "privacy_policy_page" |
| 38 |
* settings are not empty. |
| 39 |
* |
| 40 |
* @since 1.6.2 |
| 41 |
* @version 1.8.4.7 |
| 42 |
* |
| 43 |
* @return boolean |
| 44 |
*/ |
| 45 |
function charitable_is_privacy_policy_activated() { |
| 46 |
// if no 'privacy_policy_enabled' option has been saved, then go with legacy logic. |
| 47 |
if ( 'not set' === charitable_get_option( 'privacy_policy_page', 'not set' ) ) { |
| 48 |
return 0 !== intval( charitable_get_option( 'privacy_policy_page', 0 ) ) |
| 49 |
&& '' !== charitable_get_option( 'privacy_policy', __( 'Your personal data will be used to process your donation, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'charitable' ) ); |
| 50 |
} else { |
| 51 |
return 0 !== intval( charitable_get_option( 'privacy_policy_page', 0 ) ) |
| 52 |
&& '' !== charitable_get_option( 'privacy_policy', __( 'Your personal data will be used to process your donation, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'charitable' ) ) |
| 53 |
&& charitable_get_option( 'privacy_policy_enabled', 0 ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Check whether the contact consent is active. |
| 59 |
* |
| 60 |
* This returns true when the "contact_consent" and the "contact_consent_label" |
| 61 |
* fields are not empty, and when the upgrade_donor_tables upgrade routine has |
| 62 |
* been run. |
| 63 |
* |
| 64 |
* @since 1.6.2 |
| 65 |
* |
| 66 |
* @return boolean |
| 67 |
*/ |
| 68 |
function charitable_is_contact_consent_activated() { |
| 69 |
return 0 != charitable_get_option( 'contact_consent', 0 ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual |
| 70 |
&& '' != charitable_get_option( 'contact_consent_label', __( 'Yes, I am happy for you to contact me via email or phone.', 'charitable' ) ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual |
| 71 |
&& Charitable_Upgrade::get_instance()->upgrade_has_been_completed( 'upgrade_donor_tables' ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Returns the full text of the Terms and Conditions. |
| 76 |
* |
| 77 |
* @since 1.6.2 |
| 78 |
* @since 1.8.0 |
| 79 |
* @since 1.8.1.10 Added the `charitable_get_terms_and_conditions_content_after` filter and shortcode check. |
| 80 |
* |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
function charitable_get_terms_and_conditions() { |
| 84 |
$endpoints = charitable()->endpoints(); |
| 85 |
|
| 86 |
remove_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 87 |
|
| 88 |
$custom_content = apply_filters( 'charitable_get_terms_and_conditions_content', false ); |
| 89 |
|
| 90 |
if ( $custom_content === false ) { |
| 91 |
$terms_page_content = get_post_field( 'post_content', charitable_get_option( 'terms_conditions_page', 0 ), 'display' ); |
| 92 |
|
| 93 |
// if this content contains the shortcode 'charitable_donation_form', stripe this shortcode from the content/text. |
| 94 |
$custom_content = ( has_shortcode( $terms_page_content, 'charitable_donation_form' ) ) ? '' : $terms_page_content; |
| 95 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- the_content is a WordPress core filter hook. |
| 96 |
$custom_content = apply_filters( 'the_content', $custom_content ); |
| 97 |
} |
| 98 |
|
| 99 |
$content = apply_filters( 'charitable_get_terms_and_conditions_content_after', $custom_content ); |
| 100 |
|
| 101 |
add_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 102 |
|
| 103 |
return $content; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Returns the checkbox label for the Terms and Conditions field. |
| 108 |
* |
| 109 |
* @since 1.6.2 |
| 110 |
* @since 1.8.6.2 - added additional sanitization |
| 111 |
* |
| 112 |
* @return string |
| 113 |
*/ |
| 114 |
function charitable_get_terms_and_conditions_field_label() { |
| 115 |
$url = get_the_permalink( charitable_get_option( 'terms_conditions_page', 0 ) ); |
| 116 |
|
| 117 |
if ( ! $url ) { |
| 118 |
return ''; |
| 119 |
} |
| 120 |
|
| 121 |
$text = charitable_get_option( 'terms_conditions', __( 'I have read and agree to the website [terms].', 'charitable' ) ); |
| 122 |
// Sanitize and remove XSS. |
| 123 |
$text = wp_kses_post( $text ); |
| 124 |
|
| 125 |
$replace = sprintf( |
| 126 |
'<a href="%s" target="_blank" class="charitable-terms-link">%s</a>', |
| 127 |
$url, |
| 128 |
__( 'terms and conditions', 'charitable' ) |
| 129 |
); |
| 130 |
|
| 131 |
return str_replace( '[terms]', $replace, $text ); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Returns the Privacy Policy text. |
| 136 |
* |
| 137 |
* @since 1.6.2 |
| 138 |
* @since 1.8.6.2 - added additional sanitization |
| 139 |
* |
| 140 |
* @return string |
| 141 |
*/ |
| 142 |
function charitable_get_privacy_policy_field_text() { |
| 143 |
$url = get_the_permalink( charitable_get_option( 'privacy_policy_page', 0 ) ); |
| 144 |
|
| 145 |
if ( ! $url ) { |
| 146 |
return ''; |
| 147 |
} |
| 148 |
|
| 149 |
$text = charitable_get_option( 'privacy_policy', __( 'Your personal data will be used to process your donation, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'charitable' ) ); |
| 150 |
// Sanitize and remove XSS. |
| 151 |
$text = wp_kses_post( $text ); |
| 152 |
|
| 153 |
$replace = sprintf( |
| 154 |
'<a href="%s" target="_blank" class="charitable-privacy-policy-link">%s</a>', |
| 155 |
$url, |
| 156 |
__( 'privacy policy', 'charitable' ) |
| 157 |
); |
| 158 |
|
| 159 |
return str_replace( '[privacy_policy]', $replace, $text ); |
| 160 |
} |
| 161 |
|