| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Privacy Functions. |
| 4 |
* |
| 5 |
* @package Charitable/Functions/Privacy |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2022, 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 |
&& '' != charitable_get_option( 'terms_conditions', __( 'I have read and agree to the website [terms].', 'charitable' ) ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Check whether the privacy policy is active. |
| 35 |
* |
| 36 |
* This returns true when the "privacy_policy" and the "privacy_policy_page" |
| 37 |
* settings are not empty. |
| 38 |
* |
| 39 |
* @since 1.6.2 |
| 40 |
* |
| 41 |
* @return boolean |
| 42 |
*/ |
| 43 |
function charitable_is_privacy_policy_activated() { |
| 44 |
return 0 != charitable_get_option( 'privacy_policy_page', 0 ) |
| 45 |
&& '' != 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' ) ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Check whether the contact consent is active. |
| 50 |
* |
| 51 |
* This returns true when the "contact_consent" and the "contact_consent_label" |
| 52 |
* fields are not empty, and when the upgrade_donor_tables upgrade routine has |
| 53 |
* been run. |
| 54 |
* |
| 55 |
* @since 1.6.2 |
| 56 |
* |
| 57 |
* @return boolean |
| 58 |
*/ |
| 59 |
function charitable_is_contact_consent_activated() { |
| 60 |
return 0 != charitable_get_option( 'contact_consent', 0 ) |
| 61 |
&& '' != charitable_get_option( 'contact_consent_label', __( 'Yes, I am happy for you to contact me via email or phone.', 'charitable' ) ) |
| 62 |
&& Charitable_Upgrade::get_instance()->upgrade_has_been_completed( 'upgrade_donor_tables' ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the full text of the Terms and Conditions. |
| 67 |
* |
| 68 |
* @since 1.6.2 |
| 69 |
* |
| 70 |
* @return string |
| 71 |
*/ |
| 72 |
function charitable_get_terms_and_conditions() { |
| 73 |
$endpoints = charitable()->endpoints(); |
| 74 |
|
| 75 |
remove_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 76 |
|
| 77 |
$content = apply_filters( 'the_content', get_post_field( 'post_content', charitable_get_option( 'terms_conditions_page', 0 ), 'display' ) ); |
| 78 |
|
| 79 |
add_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 80 |
|
| 81 |
return $content; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns the checkbox label for the Terms and Conditions field. |
| 86 |
* |
| 87 |
* @since 1.6.2 |
| 88 |
* |
| 89 |
* @return string |
| 90 |
*/ |
| 91 |
function charitable_get_terms_and_conditions_field_label() { |
| 92 |
$url = get_the_permalink( charitable_get_option( 'terms_conditions_page', 0 ) ); |
| 93 |
|
| 94 |
if ( ! $url ) { |
| 95 |
return ''; |
| 96 |
} |
| 97 |
|
| 98 |
$text = charitable_get_option( 'terms_conditions', __( 'I have read and agree to the website [terms].', 'charitable' ) ); |
| 99 |
$replace = sprintf( '<a href="%s" target="_blank" class="charitable-terms-link">%s</a>', |
| 100 |
$url, |
| 101 |
__( 'terms and conditions', 'charitable' ) |
| 102 |
); |
| 103 |
|
| 104 |
return str_replace( '[terms]', $replace, $text ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Returns the Privacy Policy text. |
| 109 |
* |
| 110 |
* @since 1.6.2 |
| 111 |
* |
| 112 |
* @return string |
| 113 |
*/ |
| 114 |
function charitable_get_privacy_policy_field_text() { |
| 115 |
$url = get_the_permalink( charitable_get_option( 'privacy_policy_page', 0 ) ); |
| 116 |
|
| 117 |
if ( ! $url ) { |
| 118 |
return ''; |
| 119 |
} |
| 120 |
|
| 121 |
$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' ) ); |
| 122 |
$replace = sprintf( '<a href="%s" target="_blank" class="charitable-privacy-policy-link">%s</a>', |
| 123 |
$url, |
| 124 |
__( 'privacy policy', 'charitable' ) |
| 125 |
); |
| 126 |
|
| 127 |
return str_replace( '[privacy_policy]', $replace, $text ); |
| 128 |
} |
| 129 |
|