PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
← All changes | includes/donors/frontend-donor-functions.php +31 -29 2.3.0 → 4.17.0 View file →
@@ -3,13 +3,15 @@
3 3 * Donors
4 4 *
5 5 * @package Give
6 6 * @subpackage Donors
7 - * @copyright Copyright (c) 2018, WordImpress
7 + * @copyright Copyright (c) 2018, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 2.2.0
10 10 */
11 11
12 +use Give\Donations\ValueObjects\DonationMetaKeys;
13 +
12 14 /**
13 15 * Get the donor's Gravatar with a nice fallback.
14 16 *
15 17 * The fallback uses the donor's
@@ -15,10 +17,10 @@
15 17 * The fallback uses the donor's
16 18 *
17 19 * @since 2.2.0
18 20 *
19 - * @param Give_Donor $donor
20 - * @param int $size
21 + * @param Give_Donor $donor
22 + * @param int $size
21 23 *
22 24 * @return string HTML output.
23 25 */
24 26 function give_get_donor_avatar( $donor, $size = 60 ) {
@@ -32,9 +34,10 @@
32 34 echo get_avatar( $donor->email, $size );
33 35 } else {
34 36 // No gravatar = output initials.
35 37 echo $donor->get_donor_initals();
36 - } ?>
38 + }
39 + ?>
37 40 </div>
38 41 <?php
39 42
40 43 return apply_filters( 'give_get_donor_avatar', ob_get_clean() );
@@ -51,9 +54,9 @@
51 54 * @return bool
52 55 */
53 56 function give_validate_gravatar( $id_or_email ) {
54 57
55 - //id or email code borrowed from wp-includes/pluggable.php
58 + // id or email code borrowed from wp-includes/pluggable.php
56 59 $email = '';
57 60 if ( is_numeric( $id_or_email ) ) {
58 61 $id = (int) $id_or_email;
59 62 $user = get_userdata( $id );
@@ -79,17 +82,15 @@
79 82 } else {
80 83 $email = $id_or_email;
81 84 }
82 85
83 -
84 86 $hashkey = md5( strtolower( trim( $email ) ) );
85 - $cache_key = 'give_valid_gravatars';
86 - $data = get_transient( $cache_key );
87 + $cache_key = Give_Cache::get_key( 'give_valid_gravatars' );
88 + $data = Give_Cache::get( $cache_key );
87 89 $data = ! empty( $data ) ? $data : array();
88 90
89 -
90 91 if ( ! array_key_exists( $hashkey, $data ) ) {
91 - $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
92 + $uri = "http://www.gravatar.com/avatar/{$hashkey}?d=404";
92 93
93 94 $response = wp_remote_head( $uri );
94 95
95 96 $data[ $hashkey ] = 0;
@@ -97,9 +98,9 @@
97 98 if ( ! is_wp_error( $response ) ) {
98 99 $data[ $hashkey ] = absint( '200' == $response['response']['code'] );
99 100 }
100 101
101 - set_transient( $cache_key, $data, DAY_IN_SECONDS );
102 + Give_Cache::set( $cache_key, $data, DAY_IN_SECONDS );
102 103 }
103 104
104 105 return (bool) $data[ $hashkey ];
105 106 }
@@ -118,14 +119,14 @@
118 119 * @return int The new note ID
119 120 */
120 121 function give_insert_donor_donation_comment( $donation_id, $donor, $note, $comment_args = array() ) {
121 122 // Backward compatibility.
122 - if( ! give_has_upgrade_completed('v230_move_donation_note' ) ) {
123 + if ( ! give_has_upgrade_completed( 'v230_move_donation_note' ) ) {
123 124 $comment_args = wp_parse_args(
124 125 $comment_args,
125 126 array(
126 127 'comment_approved' => 0,
127 - 'comment_parent' => give_get_payment_form_id( $donation_id )
128 + 'comment_parent' => give_get_payment_form_id( $donation_id ),
128 129 )
129 130 );
130 131
131 132 $comment_id = Give_Comment::add( $donation_id, $note, 'payment', $comment_args );
@@ -155,19 +156,20 @@
155 156 * Retrieve all donor comment attached to a donation
156 157 *
157 158 * Note: currently donor can only add one comment per donation
158 159 *
159 - * @param int $donation_id The donation ID to retrieve comment for.
160 - * @param int $donor_id The donor ID to retrieve comment for.
161 - * @param string $search Search for comment that contain a search term.
160 + * @since 2.27.0 Change to read comment from donations meta table
161 + * @since 2.2.0
162 162 *
163 - * @since 2.2.0
163 + * @param int $donation_id The donation ID to retrieve comment for.
164 + * @param int $donor_id The donor ID to retrieve comment for.
165 + * @param string $search Search for comment that contain a search term.
164 166 *
165 - * @return WP_Comment|array
167 + * @return array|stdClass|WP_Comment
166 168 */
167 169 function give_get_donor_donation_comment( $donation_id, $donor_id, $search = '' ) {
168 170 // Backward compatibility.
169 - if( ! give_has_upgrade_completed('v230_move_donation_note' ) ) {
171 + if ( ! give_has_upgrade_completed( 'v230_move_donation_note' ) ) {
170 172
171 173 $comments = Give_Comment::get(
172 174 $donation_id,
173 175 'payment',
@@ -175,27 +177,27 @@
175 177 'number' => 1,
176 178 'meta_query' => array(
177 179 array(
178 180 'key' => '_give_donor_id',
179 - 'value' => $donor_id
180 - )
181 - )
181 + 'value' => $donor_id,
182 + ),
183 + ),
182 184 ),
183 185 $search
184 186 );
185 187
186 - $comment = ! empty( $comments ) ? current( $comments ) : array();
188 + $comment = !empty($comments) ? current($comments) : array();
187 189
188 190 return $comment;
189 191 }
190 192
191 - $comments = Give()->comment->db->get_comments( array(
192 - 'number' => 1,
193 - 'comment_parent' => $donation_id,
194 - 'comment_type' => 'donor_donation',
195 - ) );
193 + $comment = new stdClass();
194 + $comment->comment_ID = 0;
195 + $comment->comment_content = give_get_payment_meta($donation_id, DonationMetaKeys::COMMENT, true);
196 + $comment->comment_parent = $donation_id;
197 + $comment->comment_type = 'donor_donation';
196 198
197 - return ( ! empty( $comments ) ? current( $comments ) : array() );
199 + return $comment;
198 200 }
199 201
200 202 /**
201 203 * Retrieve donor comment id attached to a donation