Code Duplication    Length = 50-50 lines in 2 locations

includes/class-give-donor-wall.php 1 location

@@ 195-244 (lines=50) @@
192
	 *
193
	 * @return bool If the gravatar exists or not
194
	 */
195
	public function validate_gravatar( $id_or_email ) {
196
		// id or email code borrowed from wp-includes/pluggable.php
197
		$email = '';
198
		if ( is_numeric( $id_or_email ) ) {
199
			$id   = (int) $id_or_email;
200
			$user = get_userdata( $id );
201
			if ( $user ) {
202
				$email = $user->user_email;
203
			}
204
		} elseif ( is_object( $id_or_email ) ) {
205
			// No avatar for pingbacks or trackbacks
206
			$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
207
			if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
208
				return false;
209
			}
210
211
			if ( ! empty( $id_or_email->user_id ) ) {
212
				$id   = (int) $id_or_email->user_id;
213
				$user = get_userdata( $id );
214
				if ( $user ) {
215
					$email = $user->user_email;
216
				}
217
			} elseif ( ! empty( $id_or_email->comment_author_email ) ) {
218
				$email = $id_or_email->comment_author_email;
219
			}
220
		} else {
221
			$email = $id_or_email;
222
		}
223
224
		$hashkey = md5( strtolower( trim( $email ) ) );
225
		$uri     = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
226
227
		$data = Give_Cache::get_group( $hashkey );
228
229
		if ( is_null( $data ) ) {
230
			$response = wp_remote_head( $uri );
231
			if ( is_wp_error( $response ) ) {
232
				$data = 'not200';
233
			} else {
234
				$data = $response['response']['code'];
235
			}
236
			Give_Cache::set_group( $hashkey, $data, $group = '', $expire = 60 * 5 );
237
238
		}
239
		if ( $data == '200' ) {
240
			return true;
241
		} else {
242
			return false;
243
		}
244
	}
245
246
	/**
247
	 * Settings

includes/donors/frontend-donor-functions.php 1 location

@@ 53-102 (lines=50) @@
50
 *
51
 * @return bool
52
 */
53
function give_validate_gravatar( $id_or_email ) {
54
55
	//id or email code borrowed from wp-includes/pluggable.php
56
	$email = '';
57
	if ( is_numeric( $id_or_email ) ) {
58
		$id   = (int) $id_or_email;
59
		$user = get_userdata( $id );
60
		if ( $user ) {
61
			$email = $user->user_email;
62
		}
63
	} elseif ( is_object( $id_or_email ) ) {
64
		// No avatar for pingbacks or trackbacks
65
		$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
66
		if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
67
			return false;
68
		}
69
70
		if ( ! empty( $id_or_email->user_id ) ) {
71
			$id   = (int) $id_or_email->user_id;
72
			$user = get_userdata( $id );
73
			if ( $user ) {
74
				$email = $user->user_email;
75
			}
76
		} elseif ( ! empty( $id_or_email->comment_author_email ) ) {
77
			$email = $id_or_email->comment_author_email;
78
		}
79
	} else {
80
		$email = $id_or_email;
81
	}
82
83
	$hashkey = md5( strtolower( trim( $email ) ) );
84
	$uri     = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
85
86
	$data = wp_cache_get( $hashkey );
87
	if ( false === $data ) {
88
		$response = wp_remote_head( $uri );
89
		if ( is_wp_error( $response ) ) {
90
			$data = 'not200';
91
		} else {
92
			$data = $response['response']['code'];
93
		}
94
		wp_cache_set( $hashkey, $data, $group = '', $expire = 60 * 5 );
95
96
	}
97
	if ( $data == '200' ) {
98
		return true;
99
	} else {
100
		return false;
101
	}
102
}
103
104
105
/**