-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUserProfilePanel.php
More file actions
67 lines (57 loc) · 1.58 KB
/
Copy pathUserProfilePanel.php
File metadata and controls
67 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* "Change email" button on the WP user-edit / profile screen.
*
* @package WorkOS\Auth\ChangeEmail
*/
namespace WorkOS\Auth\ChangeEmail;
use WP_User;
defined( 'ABSPATH' ) || exit;
/**
* Renders a button inside the existing WorkOS section on user-edit.php
* / profile.php. Click fires the admin JS, which prompts for the new
* address and POSTs to the initiate endpoint.
*
* Priority 21 so it sits below the PasswordResetAdmin panel (priority
* 20) — both render under the existing read-only WorkOS section.
*/
class UserProfilePanel {
/**
* Register hooks.
*
* @return void
*/
public function register(): void {
add_action( 'show_user_profile', [ $this, 'render' ], 21 );
add_action( 'edit_user_profile', [ $this, 'render' ], 21 );
}
/**
* Render the panel.
*
* @param WP_User $user Target user.
*
* @return void
*/
public function render( WP_User $user ): void {
if ( ! current_user_can( 'edit_user', $user->ID ) ) {
return;
}
$workos_user_id = (string) get_user_meta( $user->ID, '_workos_user_id', true );
if ( '' === $workos_user_id ) {
return;
}
printf( '<h3>%s</h3>', esc_html__( 'Change Email', 'integration-workos' ) );
printf(
'<p class="description">%s</p>',
esc_html__(
'Send a verification email to a new address. The change only commits after the new address is confirmed.',
'integration-workos'
)
);
printf(
'<p><button type="button" class="button workos-change-email-trigger" data-user-id="%d">%s</button></p>',
(int) $user->ID,
esc_html__( 'Change email…', 'integration-workos' )
);
}
}