-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRowActions.php
More file actions
59 lines (51 loc) · 1.51 KB
/
Copy pathRowActions.php
File metadata and controls
59 lines (51 loc) · 1.51 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
<?php
/**
* "Change email" inline action under the WorkOS column on
* wp-admin/users.php.
*
* @package WorkOS\Auth\ChangeEmail
*/
namespace WorkOS\Auth\ChangeEmail;
defined( 'ABSPATH' ) || exit;
/**
* Adds a "Change email" row action under the WorkOS column. Mirrors
* {@see \WorkOS\Auth\PasswordResetAdmin\RowActions} so the two surfaces
* sit next to each other.
*
* The link is HTML-only; the click handler in
* {@see Assets}::ADMIN_SCRIPT_HANDLE prompts for the new email and POSTs
* to the initiate endpoint.
*/
class RowActions {
/**
* Register hooks.
*
* @return void
*/
public function register(): void {
add_filter( 'workos_user_list_column_actions', [ $this, 'add_action' ], 11, 3 );
}
/**
* Append the "Change email" action to the WorkOS column row actions.
*
* @param array<string,string> $actions Existing action HTML keyed by slug.
* @param int $user_id WordPress user ID.
* @param string $workos_id Linked WorkOS user ID.
*
* @return array<string,string>
*/
public function add_action( array $actions, int $user_id, string $workos_id ): array {
if ( '' === $workos_id ) {
return $actions;
}
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return $actions;
}
$actions['workos_change_email'] = sprintf(
'<span class="workos-change-email"><a href="#" class="workos-change-email-trigger" data-user-id="%d">%s</a></span>',
(int) $user_id,
esc_html__( 'Change email', 'integration-workos' )
);
return $actions;
}
}