← All changes
|
includes/privacy/charitable-privacy-functions.php
+45
-13
1.7.0.3
→
1.8.13
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Charitable Privacy Functions. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Functions/Privacy |
| 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.6.2 |
| 10 | 10 | * @version 1.6.2 |
| 11 | 11 | */ |
| @@ -25,10 +25,11 @@ | ||
| 25 | 25 | * |
| 26 | 26 | * @return boolean |
| 27 | 27 | */ |
| 28 | 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' ) ); | |
| 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' ) ); | |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Check whether the privacy policy is active. |
| @@ -36,14 +37,22 @@ | ||
| 36 | 37 | * This returns true when the "privacy_policy" and the "privacy_policy_page" |
| 37 | 38 | * settings are not empty. |
| 38 | 39 | * |
| 39 | 40 | * @since 1.6.2 |
| 41 | + * @version 1.8.4.7 | |
| 40 | 42 | * |
| 41 | 43 | * @return boolean |
| 42 | 44 | */ |
| 43 | 45 | 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 | + // 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 | + } | |
| 46 | 55 | } |
| 47 | 56 | |
| 48 | 57 | /** |
| 49 | 58 | * Check whether the contact consent is active. |
| @@ -56,10 +65,10 @@ | ||
| 56 | 65 | * |
| 57 | 66 | * @return boolean |
| 58 | 67 | */ |
| 59 | 68 | 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' ) ) | |
| 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 | |
| 62 | 71 | && Charitable_Upgrade::get_instance()->upgrade_has_been_completed( 'upgrade_donor_tables' ); |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | /** |
| @@ -64,9 +73,11 @@ | ||
| 64 | 73 | |
| 65 | 74 | /** |
| 66 | 75 | * Returns the full text of the Terms and Conditions. |
| 67 | 76 | * |
| 68 | - * @since 1.6.2 | |
| 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. | |
| 69 | 80 | * |
| 70 | 81 | * @return string |
| 71 | 82 | */ |
| 72 | 83 | function charitable_get_terms_and_conditions() { |
| @@ -73,10 +84,21 @@ | ||
| 73 | 84 | $endpoints = charitable()->endpoints(); |
| 74 | 85 | |
| 75 | 86 | remove_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 76 | 87 | |
| 77 | - $content = apply_filters( 'the_content', get_post_field( 'post_content', charitable_get_option( 'terms_conditions_page', 0 ), 'display' ) ); | |
| 88 | + $custom_content = apply_filters( 'charitable_get_terms_and_conditions_content', false ); | |
| 78 | 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 | + | |
| 79 | 101 | add_filter( 'the_content', array( $endpoints, 'get_content' ) ); |
| 80 | 102 | |
| 81 | 103 | return $content; |
| 82 | 104 | } |
| @@ -84,8 +106,9 @@ | ||
| 84 | 106 | /** |
| 85 | 107 | * Returns the checkbox label for the Terms and Conditions field. |
| 86 | 108 | * |
| 87 | 109 | * @since 1.6.2 |
| 110 | + * @since 1.8.6.2 - added additional sanitization | |
| 88 | 111 | * |
| 89 | 112 | * @return string |
| 90 | 113 | */ |
| 91 | 114 | function charitable_get_terms_and_conditions_field_label() { |
| @@ -94,10 +117,14 @@ | ||
| 94 | 117 | if ( ! $url ) { |
| 95 | 118 | return ''; |
| 96 | 119 | } |
| 97 | 120 | |
| 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>', | |
| 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>', | |
| 100 | 127 | $url, |
| 101 | 128 | __( 'terms and conditions', 'charitable' ) |
| 102 | 129 | ); |
| 103 | 130 | |
| @@ -107,8 +134,9 @@ | ||
| 107 | 134 | /** |
| 108 | 135 | * Returns the Privacy Policy text. |
| 109 | 136 | * |
| 110 | 137 | * @since 1.6.2 |
| 138 | + * @since 1.8.6.2 - added additional sanitization | |
| 111 | 139 | * |
| 112 | 140 | * @return string |
| 113 | 141 | */ |
| 114 | 142 | function charitable_get_privacy_policy_field_text() { |
| @@ -117,10 +145,14 @@ | ||
| 117 | 145 | if ( ! $url ) { |
| 118 | 146 | return ''; |
| 119 | 147 | } |
| 120 | 148 | |
| 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>', | |
| 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>', | |
| 123 | 155 | $url, |
| 124 | 156 | __( 'privacy policy', 'charitable' ) |
| 125 | 157 | ); |
| 126 | 158 | |