PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.31
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.31
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 1.8.0 All 210 releases
charitable / includes / users / charitable-user-functions.php

charitable-user-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.31, at includes/users/charitable-user-functions.php

203 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable User Functions.
4 *
5 * User related functions.
6 *
7 * @package Charitable/Functions/User
8 * @author Eric Daams
9 * @copyright Copyright (c) 2020, Studio 164a
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.6.0
13 */
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Returns a Charitable_User object for the given user.
22 *
23 * This will first attempt to retrieve it from the object cache to prevent duplicate objects.
24 *
25 * @since 1.0.0
26 *
27 * @param int $user_id The ID of the user to retrieve.
28 * @param boolean $force Optional. Whether to force an update of the local cache from the persistent.
29 * @return Charitable_User
30 */
31 function charitable_get_user( $user_id, $force = false ) {
32 if ( is_a( $user_id, 'WP_User' ) ) {
33 $user_id = $user_id->ID;
34 }
35 $user = wp_cache_get( $user_id, 'charitable_user', $force );
36
37 if ( ! $user ) {
38 $user = new Charitable_User( $user_id );
39 wp_cache_set( $user_id, $user, 'charitable_user' );
40 }
41
42 return $user;
43 }
44
45 /**
46 * Returns a mapping of user keys.
47 *
48 * This is needed because the key used in forms is not always the
49 * same as they key used for storing the database value.
50 *
51 * @since 1.4.0
52 *
53 * @return string[]
54 */
55 function charitable_get_user_mapped_keys() {
56 /**
57 * Filter the mapping of shorthand keys to meta keys.
58 *
59 * The meta keys are used in the wp_usermeta table.
60 *
61 * @since 1.0.0
62 *
63 * @param array $keys User meta keys.
64 */
65 return apply_filters(
66 'charitable_donor_mapped_keys',
67 array(
68 'email' => 'user_email',
69 'company' => 'donor_company',
70 'address' => 'donor_address',
71 'address_2' => 'donor_address_2',
72 'city' => 'donor_city',
73 'state' => 'donor_state',
74 'postcode' => 'donor_postcode',
75 'zip' => 'donor_postcode',
76 'country' => 'donor_country',
77 'phone' => 'donor_phone',
78 'user_description' => 'description',
79 )
80 );
81 }
82
83 /**
84 * Returns a list of the core user keys.
85 *
86 * Core user keys are any keys that can be passed to wp_update_user or wp_insert_user.
87 *
88 * @see wp_update_user
89 * @see wp_insert_user
90 *
91 * @since 1.4.0
92 *
93 * @return string[]
94 */
95 function charitable_get_user_core_keys() {
96 return array(
97 'ID',
98 'user_pass',
99 'user_login',
100 'user_nicename',
101 'user_url',
102 'user_email',
103 'display_name',
104 'nickname',
105 'first_name',
106 'last_name',
107 'rich_editing',
108 'date_registered',
109 'role',
110 'jabber',
111 'aim',
112 'yim',
113 );
114 }
115
116 /**
117 * Returns a list of the donor keys.
118 *
119 * These keys correspond to the columns in the wp_charitable_donors table.
120 *
121 * @since 1.6.2
122 *
123 * @return string[]
124 */
125 function charitable_get_donor_keys() {
126 return array(
127 'donor_id',
128 'user_id',
129 'email',
130 'first_name',
131 'last_name',
132 'date_joined',
133 'date_erased',
134 'contact_consent',
135 );
136 }
137
138 /**
139 * Return the email address when data is erased.
140 *
141 * @since 1.6.0
142 *
143 * @param string $email The email address to check.
144 * @return boolean True if the email is valid; false if it is marked as invalid.
145 */
146 function charitable_is_valid_email_address( $email ) {
147 $invalid = array();
148
149 if ( function_exists( 'wp_privacy_anonymize_data' ) ) {
150 $invalid[] = wp_privacy_anonymize_data( 'email' );
151 }
152
153 /**
154 * Filter the list of invalid email addresses used by Charitable.
155 *
156 * @since 1.6.0
157 *
158 * @param string[] $addresses A list of strings that are invalid email addresses.
159 */
160 $invalid = apply_filters( 'charitable_invalid_email_addresses', $invalid );
161
162 return strlen( $email ) && ! in_array( $email, $invalid );
163 }
164
165 /**
166 * Return whether donors can be added without an email address.
167 *
168 * @since 1.6.0
169 *
170 * @return boolean True if donors can be added without an email address. False otherwise.
171 */
172 function charitable_permit_donor_without_email() {
173 /**
174 * Filter whether donors can be added without an email address.
175 *
176 * Prior to Charitable 1.6, this was never permitted. As of Charitable 1.6, it's possible
177 * to support manual donations without an email address by using this filter.
178 *
179 * NOTE: By default, the public donation form still requires an email address, so this
180 * primarily affects programattically created donors, or donors created via manual
181 * donations in the admin.
182 *
183 * @see https://github.com/Charitable/Charitable/issues/535
184 *
185 * @since 1.6.0
186 *
187 * @param boolean $permitted Whether donors can be added without an email address.
188 */
189 return apply_filters( 'charitable_permit_donor_without_email', false );
190 }
191
192 /**
193 * Get a donor ID based on an email address.
194 *
195 * @since 1.6.2
196 *
197 * @param string $email The email address.
198 * @return int
199 */
200 function charitable_get_donor_id_by_email( $email ) {
201 return charitable_get_table( 'donors' )->get_donor_id_by_email( $email );
202 }
203