Skip to content
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ed17145
Feature: Save google profile picture during account creation
mi5t4n May 5, 2025
573693b
fix: phpcs errors
mi5t4n May 5, 2025
cdb6f84
Merge branch 'develop' into feature/save-google-profile-picture-durin…
mi5t4n May 15, 2025
63a2c9b
Check for wp_filesystem as well
mi5t4n May 16, 2025
86f6ffc
Merge branch 'develop' into feature/save-google-profile-picture-durin…
mchirag2002 Oct 30, 2025
489c68b
fix: typo
mi5t4n Dec 3, 2025
0479da9
Remove leading forward slash
mi5t4n Dec 3, 2025
7bc0631
fix: typo
mi5t4n Dec 3, 2025
f01033a
refactor
mi5t4n Dec 3, 2025
c6659bb
added error handling
mi5t4n Dec 3, 2025
877990d
handle empty user picture field from the response
mi5t4n Dec 3, 2025
68cc83c
Passing 0 as post id to media_handle_sideload
mi5t4n Dec 3, 2025
15820bd
refactor
mi5t4n Dec 3, 2025
62c8c18
handle error when moving file fails
mi5t4n Dec 3, 2025
55118bc
handle error when profile picture downloading fails
mi5t4n Dec 3, 2025
4d93934
Merge remote-tracking branch 'refs/remotes/origin/feature/save-google…
mi5t4n Dec 3, 2025
d0e204b
fix typo
mi5t4n Dec 3, 2025
d8d9d61
fix typo
mi5t4n Dec 3, 2025
daec6ee
Added since doc
mi5t4n Dec 3, 2025
5b1dedb
update the save user profile picture filter name
mi5t4n Dec 3, 2025
23098e0
created user profile edit template
mi5t4n Dec 4, 2025
17dbdc3
fix: google user profile display on user edit page
mi5t4n Dec 4, 2025
1a367d7
Conditionally render the google avatar
mi5t4n Dec 4, 2025
f8679f5
Save the avatar source user profile options
mi5t4n Dec 4, 2025
c36f21e
handle default google avatar source
mi5t4n Dec 4, 2025
f8ac4e9
Set avatar source as google for the first login with google
mi5t4n Dec 4, 2025
64e44b3
refactor
mi5t4n Dec 4, 2025
f6aa442
update the google profile picture if it's been changed
mi5t4n Dec 9, 2025
0d17dba
update the code such that the profile picture is not syned
mi5t4n Dec 10, 2025
458e84c
show user can set the google profile picture notice
mi5t4n Dec 10, 2025
df906b2
fix: typo
mi5t4n Dec 10, 2025
bcf6db9
do not display notice if google picture doesn't exists
mi5t4n Dec 10, 2025
1e6f6f7
fix: phpcs errors
mi5t4n Dec 10, 2025
964f6cf
Apply suggestions from code review
mi5t4n Dec 10, 2025
2f04b1f
Update src/Modules/UserProfile.php
mi5t4n Dec 10, 2025
b651a08
Update src/Modules/UserProfile.php
mi5t4n Dec 10, 2025
9d4693d
fix: prefix
mi5t4n Dec 10, 2025
d53d4f8
fix: phpcs errors
mi5t4n Dec 10, 2025
f94397e
fix: phpcs errors
mi5t4n Dec 10, 2025
268d19b
Update src/Utils/Authenticator.php
mi5t4n Dec 10, 2025
c1b6635
Update src/Modules/UserProfile.php
mi5t4n Dec 10, 2025
9a5a33b
Update src/Modules/UserProfile.php
mi5t4n Dec 10, 2025
e1f2707
Update src/Modules/UserProfile.php
mi5t4n Dec 10, 2025
3f975d5
fix: pcp errors
mi5t4n Dec 11, 2025
596427b
added more parameters to the filter
mi5t4n Dec 11, 2025
f45b753
updated the readme.md with new filters
mi5t4n Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use RtCamp\GoogleLogin\Modules\Login;
use RtCamp\GoogleLogin\Modules\OneTapLogin;
use RtCamp\GoogleLogin\Modules\Settings;
use RtCamp\GoogleLogin\Modules\UserProfile;
use RtCamp\GoogleLogin\Utils\Authenticator;
use RtCamp\GoogleLogin\Utils\GoogleClient;
use RtCamp\GoogleLogin\Modules\Shortcode;
Expand Down Expand Up @@ -190,6 +191,18 @@ public function define_services(): void {
};


/**
* Define User Profile service to manage user profile.
*
* @param PimpleContainer $c Pimple container object.
*
* @return UserProfile
*/
$this->container['user_profile'] = function ( PimpleContainer $c ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return new UserProfile();
};


Comment thread
mi5t4n marked this conversation as resolved.
/**
* Define any additional services.
*
Expand Down
206 changes: 206 additions & 0 deletions src/Modules/UserProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php
/**
* Handle User Profile module.
*
* @package RtCamp\GoogleLogin
* @since n.e.x.t
* @author rtCamp <contact@rtcamp.com>
*/

declare(strict_types=1);

namespace RtCamp\GoogleLogin\Modules;

use RtCamp\GoogleLogin\Interfaces\Module as ModuleInterface;
use RtCamp\GoogleLogin\Utils\UserProfileHelper;
use function RtCamp\GoogleLogin\plugin;

/**
* Class UserProfile.
*
* @package RtCamp\GoogleLogin\Modules
*/
class UserProfile implements ModuleInterface {

/**
* Module name.
*
* @since n.e.x.t
*
* @return string
*/
public function name(): string {
return 'user_profile';
}

/**
* Initialize the UserProfile module.
*
* @since n.e.x.t
* @return void
*/
public function init(): void {
add_action( 'get_avatar_url', [ $this, 'return_avatar_url' ], 10, 3 );

// Render the profile edit options.
add_action( 'show_user_profile', [ $this, 'render_user_profile_edit_options' ] );
add_action( 'edit_user_profile', [ $this, 'render_user_profile_edit_options' ] );

// Save the profile edit options.
add_action( 'personal_options_update', [ $this, 'save_user_profile_edit_options' ] );
add_action( 'edit_user_profile_update', [ $this, 'save_user_profile_edit_options' ] );

add_action( 'admin_notices', [ $this, 'display_google_profile_picture_notice' ] );
}

/**
* Return the stored profile picture during the account creation.
*
* @since n.e.x.t
*
* @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 of 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;
}

// Do not interfere on profile edit page.
if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
return $url;
}

// Do not interfere on user edit screen in admin.
$current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( $current_screen && 'user-edit' === $current_screen->id ) {
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 );
} elseif ( $id_or_email instanceof \WP_User ) {
$wp_user = $id_or_email;
} elseif ( $id_or_email instanceof \WP_Post ) {
$wp_user = get_user_by( 'id', (int) $id_or_email->post_author );
} elseif ( $id_or_email instanceof \WP_Comment ) {
$wp_user = get_user_by( 'id', (int) $id_or_email->user_id );
}

// Bail early if the user is not found.
if ( ! $wp_user ) {
return $url;
}

// Bail if user has chosen gravatar as avatar source.
$profile_picture_source = UserProfileHelper::get_profile_picture_source( $wp_user->ID );
if ( $profile_picture_source && 'gravatar' === $profile_picture_source ) {
return $url;
}

// Return the saved google avatar URL.
$width = isset( $args['width'] ) ? absint( $args['width'] ) : 96;
$height = isset( $args['height'] ) ? absint( $args['height'] ) : 96;

$profile_picture_id = UserProfileHelper::get_saved_google_profile_picture_id( $wp_user->ID );

if ( ! empty( $profile_picture_id ) ) {
$profile_picture_url = wp_get_attachment_image_url( $profile_picture_id, [ $width, $height ] );
if ( $profile_picture_url ) {
$url = $profile_picture_url;
}
}

return $url;
}

/**
* Render user profile edit template
*
* @since n.e.x.t
* @param WP_User $wp_user WP_User object.
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
* @return void
*/
public function render_user_profile_edit_options( $wp_user ) {
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
require_once plugin()->template_dir . 'user-profile-edit.php'; //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomFunction
}

/**
* Save user profile edit options.
*
* @since n.e.x.t
*
* @param int $user_id User ID.
* @return void
*/
public function save_user_profile_edit_options( $user_id ) {
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['_wpnonce'] ), 'update-user_' . $user_id ) ) {
return;
}

if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
}

if ( isset( $_POST['rtlg_profile_picture_source'] ) ) {
$avatar_source = sanitize_text_field( wp_unslash( $_POST['rtlg_profile_picture_source'] ) );
UserProfileHelper::save_profile_picture_source( $user_id, $avatar_source );
}

return true;
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
}

/**
* Display notice to the user that profile picture has been downloaded and they can use that.
*
* @since n.e.x.t
*
* @return void
*/
public function display_google_profile_picture_notice(): void {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
$profile_picture_source = UserProfileHelper::get_profile_picture_source( get_current_user_id() );
$has_google_profile_picture = UserProfileHelper::has_google_profile_picture( get_current_user_id() );


Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. Remove one of the blank lines to maintain consistent spacing with the rest of the codebase.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread
mi5t4n marked this conversation as resolved.
Outdated
// Bail early if the current screen is not profile screen.
if ( null === $screen || 'profile' !== $screen->id ) {
return;
}

// Bail early if user has set google profile picture source.
if ( 'google' === $profile_picture_source ) {
return;
}

if ( ! $has_google_profile_picture ) {
return;
}

?>
<div class="notice notice-info is-dismissible">
<p>
<?php esc_html_e( 'Note: Your Google profile picture was downloaded and is available for use on your profile.', 'login-with-google' ); ?>
<a href="#rtlg-user-profile-edit">
<?php esc_html_e( 'You can select it from your profile settings.', 'login-with-google' ); ?>
</a>
</p>
</div>
<?php
}
}
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace RtCamp\GoogleLogin;

use RtCamp\GoogleLogin\Interfaces\Container as ContainerInterface;
use RtCamp\GoogleLogin\Utils\Helper;

/**
* Class Plugin.
Expand Down Expand Up @@ -75,6 +76,7 @@ class Plugin {
'shortcode',
'one_tap_login',
'google_login_block',
'user_profile',
];

/**
Expand Down
Loading