PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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 1.7.0.9 All 211 releases
charitable / includes / donations / class-charitable-donation-notices.php

class-charitable-donation-notices.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/donations/class-charitable-donation-notices.php

152 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for documenting notices, errors, etc. for a donation.
4 *
5 * @package Charitable/Classes/Charitable_Donation_Notice
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.6
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18
19 if ( ! class_exists( 'Charitable_Donation_Notices' ) ) :
20
21 /**
22 * Charitable_Donation_Notice
23 *
24 * @since 1.8.1.6
25 */
26 class Charitable_Donation_Notices {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Donation_Notices|null
32 */
33 private static $instance = null;
34
35 /**
36 * The donation ID.
37 *
38 * @since 1.8.1.6
39 *
40 * @var int
41 */
42 private $donation_id;
43
44 /**
45 * Create class object.
46 *
47 * @since 1.8.1.6
48 */
49 public function __construct() {
50 }
51
52 /**
53 * Add security check error total.
54 *
55 * @since 1.8.1.6
56 *
57 * @param boolean $ret Whether to return the value true/false, passed in and not modified.
58 * @param Charitable_Donation_Form $form The donation form.
59 */
60 public function update_security_check_error_total( $ret = true, $form = false ) {
61
62 // if the passed value is true (from validate_security_check() ), then the check passed and we can exit.
63 if ( true === $ret ) {
64 return $ret;
65 }
66
67 $donation_security_checks = get_transient( 'charitable_donation_security_checks' );
68
69 if ( ! is_array( $donation_security_checks ) ) {
70 $donation_security_checks = array();
71 }
72
73 $campaign = $form->get_campaign(); // Charitable_Campaign object.
74 $campaign_id = ! empty( $campaign->get_campaign_id() ) ? $campaign->get_campaign_id() : 0;
75
76 if ( 0 === $campaign_id ) {
77 return $ret;
78 }
79
80 if ( isset( $donation_security_checks[ $campaign_id ] ) ) {
81 ++$donation_security_checks[ $campaign_id ];
82 } else {
83 $donation_security_checks[ $campaign_id ] = 1;
84 }
85
86 $time_span = apply_filters( 'charitable_donation_security_checks_log_length', 7 * DAY_IN_SECONDS );
87
88 // if the transients doesn't exist, create one that lasts 7 days.
89 set_transient( 'charitable_donation_security_checks', $donation_security_checks, $time_span );
90
91 return $ret;
92 }
93
94 /**
95 * Get dashboard notices.
96 *
97 * @since 1.8.1.6
98 * @version 1.8.1.9 // Updated doc URL.
99 * @version 1.8.2 // added dashboard notification related code.
100 */
101 public function get_dashboard_notices() {
102
103 // Until there's a global dashboard notice system, we'll just tap into dashboard notifications.
104
105 $dashboard_notices = get_option( 'charitable_dashboard_notifications', array() );
106 $donation_security_checks = get_transient( 'charitable_donation_security_checks' );
107
108 // if the 'donation_security_checks' already exists in the dashboard notices, don't add it again.
109 if ( isset( $dashboard_notices['donation_security_checks'] ) ) {
110 return $dashboard_notices;
111 }
112
113 if ( is_array( $donation_security_checks ) && ! empty( $donation_security_checks ) && count( $donation_security_checks ) > 0 ) {
114 if ( empty( $dashboard_notices ) || ! is_array( $dashboard_notices ) ) {
115 $dashboard_notices = array();
116 }
117 $dashboard_notices['donation_security_checks'] = array(
118 'type' => 'warning',
119 'dismiss' => false,
120 'title' => esc_html__( 'Important', 'charitable' ), // phpcs:ignore
121 'custom_css' => 'charitable-notification-type-important',
122 'message' => sprintf( '<p><strong>%s</strong></p>', esc_html__( 'Charitable has noticed some recent donation attempts via a donation form have failed due to invalid security checks.', 'charitable' ) ) .
123 sprintf( '<ul class="charitable-notice-recommendations"><li>%s</li>', esc_html__( 'If you have any caching plugins installed, try deactivating to test or add any relevant URLs to any "bypass" list in the cache plugin\'s settings.', 'charitable' ) ) .
124 sprintf( '<li>%s <strong>%s</strong>.</li>', esc_html__( 'Depending on your theme and/or plugins you can manually clear cache on pages to test the donation form. Example: ', 'charitable' ), esc_html__( 'test.com/campaign/donate?cache=123', 'charitable' ) ) .
125 sprintf( '<li><a href="%s">%s</a> %s <a href="%s">%s</a> %s</li>', 'https://www.wpcharitable.com/documentation/charitable-has-noticed-some-recent-donation-attempts-via-the-donation-form-have-failed-due-to-invalid-security-checks/', esc_html__( 'Please read our documentation.', 'charitable' ), esc_html__( 'Also feel free to ', 'charitable' ), 'https://www.wpcharitable.com/support/', esc_html__( 'contact our support team', 'charitable' ), esc_html__( 'if you need further assistance.', 'charitable' ) ) .
126 sprintf( '</ul>' ),
127 );
128 }
129
130 update_option( 'charitable_dashboard_notifications', $dashboard_notices );
131
132 return $dashboard_notices;
133 }
134
135 /**
136 * Create and return the class object.
137 *
138 * @since 1.8.1.6
139 *
140 * @return Charitable_Upgrade
141 */
142 public static function get_instance() {
143 if ( is_null( self::$instance ) ) {
144 self::$instance = new self();
145 }
146
147 return self::$instance;
148 }
149 }
150
151 endif;
152