-
Notifications
You must be signed in to change notification settings - Fork 27
Feature: Save google profile picture of the user during account creation #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
ed17145
573693b
cdb6f84
63a2c9b
86f6ffc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,6 +112,8 @@ public function run(): void { | |||||||||||
| add_action( 'init', [ $this, 'load_translations' ] ); | ||||||||||||
|
|
||||||||||||
| add_action( 'plugin_action_links_' . plugin_basename( $this->path ) . '/login-with-google.php', [ $this, 'add_plugin_action_links' ] ); | ||||||||||||
|
|
||||||||||||
| add_action( 'get_avatar_url', [ $this, 'return_avatar_url' ], 10, 3 ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
|
|
@@ -162,4 +164,48 @@ public function add_plugin_action_links( $actions ) { | |||||||||||
|
|
||||||||||||
| return array_merge( $new_actions, $actions ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Return the stored profile picture during the account creation. | ||||||||||||
| * | ||||||||||||
| * @param string $url The URL of the avatar. | ||||||||||||
| * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar SHA-256 or MD5 hash, user email, WP_User object, WP_Post object, or WP_Comment object. | ||||||||||||
| * @param array $args Arguments passed to get_avatar_data() , after processing. | ||||||||||||
| * | ||||||||||||
| * @return string The URL of the avatar. | ||||||||||||
| */ | ||||||||||||
| public function return_avatar_url( $url, $id_or_email, $args ): string { | ||||||||||||
| /** | ||||||||||||
| * Filter to bypass the use of saved profile picture for avatar. | ||||||||||||
| * | ||||||||||||
| * @since n.e.x.t | ||||||||||||
| * | ||||||||||||
| * @param boolean $use_saved_profile_picture_for_avatar Whether to bypass the use the saved profile picture for avatar or not. | ||||||||||||
| */ | ||||||||||||
| $use_avatar_url = apply_filters( 'rtcamp.google_use_saved_profile_picture_for_avatar', true ); | ||||||||||||
|
|
||||||||||||
| if ( ! $use_avatar_url ) { | ||||||||||||
| return $url; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $wp_user = null; | ||||||||||||
| if ( is_int( $id_or_email ) ) { | ||||||||||||
| $wp_user = get_user_by( 'id', $id_or_email ); | ||||||||||||
| } elseif ( is_string( $id_or_email ) && is_email( $id_or_email ) ) { | ||||||||||||
| $wp_user = get_user_by( 'email', $id_or_email ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ( $wp_user ) { | ||||||||||||
| $width = isset( $args['width'] ) ? absint( $args['width'] ) : 64; | ||||||||||||
| $height = isset( $args['height'] ) ? absint( $args['height'] ) : 64; | ||||||||||||
|
|
||||||||||||
| $profile_picture_id = get_user_meta( $wp_user->ID, 'rtlwg_profile_picture_id', true ); | ||||||||||||
|
|
||||||||||||
| if ( ! empty( $profile_picture_id ) ) { | ||||||||||||
| $url = wp_get_attachment_image_url( $profile_picture_id, [ $width, $height ] ); | ||||||||||||
|
||||||||||||
| $url = wp_get_attachment_image_url( $profile_picture_id, [ $width, $height ] ); | |
| $profile_picture_url = wp_get_attachment_image_url( $profile_picture_id, [ $width, $height ] ); | |
| if ( $profile_picture_url ) { | |
| $url = $profile_picture_url; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,6 +112,21 @@ public function register( stdClass $user ): ?WP_User { | |||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Filter to bypass the profile picture saving process. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @since n.e.x.t | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @param boolean $save Whether to save profile picture or not. | ||||||||||||||||||||||||
| * @param int $uid WP User ID. | ||||||||||||||||||||||||
| * @param \stdClass User object return by Google. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| * @param \stdClass User object return by Google. | |
| * @param \stdClass User object returned by Google. |
mi5t4n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent path separator usage. Line 209 uses '/wp-admin' while lines 213-215 use 'wp-admin' (without leading slash). The leading slash should be removed for consistency, as ABSPATH already ends with a trailing slash.
| require_once ABSPATH . '/wp-admin/includes/file.php'; | |
| require_once ABSPATH . 'wp-admin/includes/file.php'; |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing property existence check for $user->picture. The code should verify that the picture property exists on the user object before attempting to access it to avoid potential PHP warnings or errors.
| // Using larger image size. By default, profile picture has 96 width size with cropped. | |
| // Using larger image size. By default, profile picture has 96 width size with cropped. | |
| if ( ! isset( $user->picture ) ) { | |
| // No profile picture available, so nothing to do. | |
| return; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a check for WPVIP? and if the site is hosted on WPVIP we directly use wpcom_vip_download_image() this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SH4LIN Yes, it can be a bit unclear—I’ll look into it further to make it more straightforward. As for re-syncing the image at each login, should we also extend this to include the First Name and Last Name, since those fields can also be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SH4LIN Regarding vip check, that is a good catch. I will promptly implement this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also extend this to include the First Name and Last Name, since those fields can also be updated?
In WordPress, we have the option to update the first name and last name. So, if they want to customize it, they can do so from the settings. However, there is no option in the WordPress dashboard to change the image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a check for WPVIP? and if the site is hosted on WPVIP we directly use
wpcom_vip_download_image()this function.
I tried to use this function, it seems it won't work in our scenario. I got the following error while trying to use it .

The function was expecting a POST request, but Google calls the redirect URL using the GET method instead. We could try to change the global variables to make it work, but that would be a hacky solution. So, I decided to remove the function for now.
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for download_url() which can return a WP_Error object on failure. The code should check if the result is a WP_Error before proceeding to use it as a filename.
| if ( is_wp_error( $profile_picture_filename ) ) { | |
| // Optionally log the error: error_log( $profile_picture_filename->get_error_message() ); | |
| return; | |
| } |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable $profile_picture_extension may not be defined if no matching MIME type is found in the foreach loop. Initialize this variable before the loop or add an else condition to handle the case when no match is found.
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for media_handle_sideload() which can return a WP_Error object on failure. The code only checks if result is an integer but doesn't handle potential WP_Error cases or clean up the temporary file on error.
| if ( is_wp_error( $attachment_id ) ) { | |
| // Clean up the temporary file if there was an error. | |
| if ( file_exists( $profile_picture_filename ) ) { | |
| @unlink( $profile_picture_filename ); | |
| } | |
| // Optionally, log the error. | |
| // error_log( 'Failed to sideload profile picture: ' . $attachment_id->get_error_message() ); | |
| return; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant word 'the' in the docblock. Should be 'Whether to bypass the use of the saved profile picture' or 'Whether to use the saved profile picture'.