Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

First pass at issue #35. Updated get_avatar methods to use the core get_avatar function and extract url. #47

Merged
merged 3 commits into from

2 participants

@rachelbaker
Owner

Per issue #35, using core get_avatar function and then stripping out the avatar url from the full img html.

@rmccue rmccue merged commit 9ef12f8 into WP-API:master
@rmccue rmccue was assigned
@rmccue
Owner

:tada: :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 46 deletions.
  1. +9 −23 lib/class-wp-json-posts.php
  2. +9 −23 lib/class-wp-json-server.php
View
32 lib/class-wp-json-posts.php
@@ -910,39 +910,25 @@ protected function get_date_with_gmt( $date, $force_utc = false ) {
}
/**
- * Retrieve the avatar for a user who provided a user ID or email address.
+ * Retrieve the avatar url for a user who provided a user ID or email address.
*
* {@see get_avatar()} doesn't return just the URL, so we have to
- * reimplement this here.
+ * extract it here.
*
- * @todo Rework how we do this. Copying it is a hack.
- *
- * @since 2.5
* @param string $email Email address
- * @return string <img> tag for the user's avatar
+ * @return string url for the user's avatar
*/
protected function get_avatar( $email ) {
- if ( ! get_option( 'show_avatars' ) )
- return false;
+ $avatar_html = get_avatar( $email );
+ // strip the avatar url from the get_avatar img tag.
+ preg_match('/src=["|\'](.+)[\&|"|\']/U', $avatar_html, $matches);
- $email_hash = md5( strtolower( trim( $email ) ) );
+ if ( isset( $matches[1] ) && ! empty( $matches[1] ) ) {
- if ( is_ssl() ) {
- $host = 'https://secure.gravatar.com';
- } else {
- if ( !empty($email) )
- $host = sprintf( 'http://%d.gravatar.com', ( hexdec( $email_hash[0] ) % 2 ) );
- else
- $host = 'http://0.gravatar.com';
+ return esc_url_raw( $matches[1] );
}
- $avatar = "$host/avatar/$email_hash&d=404";
-
- $rating = get_option( 'avatar_rating' );
- if ( !empty( $rating ) )
- $avatar .= "&r={$rating}";
-
- return apply_filters( 'get_avatar', $avatar, $email, '96', '404', '' );
+ return '';
}
/**
View
32 lib/class-wp-json-server.php
@@ -603,39 +603,25 @@ public function get_date_with_gmt( $date, $force_utc = false ) {
}
/**
- * Retrieve the avatar for a user who provided a user ID or email address.
+ * Retrieve the avatar url for a user who provided a user ID or email address.
*
* {@see get_avatar()} doesn't return just the URL, so we have to
- * reimplement this here.
+ * extract it here.
*
- * @todo Rework how we do this. Copying it is a hack.
- *
- * @since 2.5
* @param string $email Email address
- * @return string <img> tag for the user's avatar
+ * @return string url for the user's avatar
*/
public function get_avatar( $email ) {
- if ( ! get_option( 'show_avatars' ) )
- return false;
+ $avatar_html = get_avatar( $email );
+ // strip the avatar url from the get_avatar img tag.
+ preg_match('/src=["|\'](.+)[\&|"|\']/U', $avatar_html, $matches);
- $email_hash = md5( strtolower( trim( $email ) ) );
+ if ( isset( $matches[1] ) && ! empty( $matches[1] ) ) {
- if ( is_ssl() ) {
- $host = 'https://secure.gravatar.com';
- } else {
- if ( !empty($email) )
- $host = sprintf( 'http://%d.gravatar.com', ( hexdec( $email_hash[0] ) % 2 ) );
- else
- $host = 'http://0.gravatar.com';
+ return esc_url_raw( $matches[1] );
}
- $avatar = "$host/avatar/$email_hash&d=404";
-
- $rating = get_option( 'avatar_rating' );
- if ( !empty( $rating ) )
- $avatar .= "&r={$rating}";
-
- return apply_filters( 'get_avatar', $avatar, $email, '96', '404', '' );
+ return '';
}
/**
Something went wrong with that request. Please try again.