Skip to content

Commit

Permalink
WP Telegram Login | Make User ID column clickable with ID and username (
Browse files Browse the repository at this point in the history
#219)

* WP Telegram Login | Make User ID column clickable with ID and username

* Clean up username if it doesn't exist on login

* Update project config
  • Loading branch information
irshadahmad21 authored Dec 2, 2024
1 parent 85fac93 commit 93f3cbd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-seahorses-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wptelegram-login": patch
---

Updated user ID column to make it clickable with ID and username
2 changes: 1 addition & 1 deletion config/wpdev.base.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getBundleConfig = ({ slug, key, version, textDomain }) => {
// When updating these values, also update them in the E2E test workflow
requiresPHP: '7.4',
requiresAtLeast: '6.4',
testedUpTo: '6.7',
testedUpTo: '6.7.1',
},
target: {
files: [
Expand Down
28 changes: 23 additions & 5 deletions plugins/wptelegram-login/src/admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,32 @@ public function register_custom_user_column( $columns ) {
*/
public function register_custom_user_column_view( $output, $column_name, $user_id ) {

if ( WPTELEGRAM_USER_ID_META_KEY === $column_name ) {
if ( WPTELEGRAM_USER_ID_META_KEY !== $column_name ) {
return $output;
}

$user = get_user_by( 'id', $user_id );
$telegram_id = get_user_meta( $user_id, WPTELEGRAM_USER_ID_META_KEY, true );

if ( $user && $user instanceof WP_User ) {
if ( ! $telegram_id ) {
return $output;
}

return $user->{WPTELEGRAM_USER_ID_META_KEY};
}
// By default, the output is the Telegram user ID.
$output = sprintf(
'<a href="%1$s" target="_blank" rel="noreferrer noopener">%2$s</a>',
esc_url( 'tg://user?id=' . $telegram_id, [ 'tg' ] ),
esc_html( $telegram_id )
);

$telegram_username = get_user_meta( $user_id, WPTELEGRAM_USERNAME_META_KEY, true );

// If the user has a Telegram username, append it to the output.
if ( $telegram_username ) {
$output .= sprintf(
' (<a href="%1$s" target="_blank" rel="noreferrer noopener">@%2$s</a>)',
esc_url( 'https://t.me/' . $telegram_username ),
esc_html( $telegram_username )
);
}
return $output;
}
Expand Down
7 changes: 6 additions & 1 deletion plugins/wptelegram-login/src/shared/LoginHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,12 @@ public function save_user_data( $data, $wp_user_id = null ) {

// Save the telegram user ID and username.
update_user_meta( $wp_user_id, WPTELEGRAM_USER_ID_META_KEY, $id );
update_user_meta( $wp_user_id, WPTELEGRAM_USERNAME_META_KEY, $tg_username );

if ( $tg_username ) {
update_user_meta( $wp_user_id, WPTELEGRAM_USERNAME_META_KEY, $tg_username );
} else {
delete_user_meta( $wp_user_id, WPTELEGRAM_USERNAME_META_KEY );
}

if ( ! empty( $photo_url ) ) {
$meta_key = WPTG_Login()->options()->get( 'avatar_meta_key' );
Expand Down

0 comments on commit 93f3cbd

Please sign in to comment.