Skip to content

Commit 64bba14

Browse files
committed
Add module to notify-privileged-activity
1 parent 3bff939 commit 64bba14

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

.wpvip/vip-dev-env.yml.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ multisite: true
99
phpmyadmin: true
1010
elasticsearch: false
1111
xdebug: true
12-
mailpit: false
12+
mailpit: true
1313
photon: false
1414
cron: false
1515
overrides: |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
namespace Automattic\VIP\Security\PrivilegedActivityNotifier;
3+
4+
class Notify_Privileged_Activity {
5+
public static function init() {
6+
add_action( 'user_register', [ __CLASS__, 'notify_admin_user_creation' ] );
7+
}
8+
9+
/**
10+
* Handle new user creation.
11+
*
12+
* @param int $user_id The ID of the newly registered user.
13+
*/
14+
public static function notify_admin_user_creation( $user_id ) {
15+
$user = get_userdata( $user_id );
16+
if ( ! $user ) {
17+
return;
18+
}
19+
20+
if ( in_array( 'administrator', (array) $user->roles, true ) ) {
21+
$admin_email = get_option( 'admin_email' );
22+
23+
if ( empty( $admin_email ) || ! is_email( $admin_email ) ) {
24+
return;
25+
}
26+
27+
$subject = sprintf( __( '[%s] New Administrator User Created', 'wpvip' ),
28+
get_bloginfo( 'name' )
29+
);
30+
31+
$message = sprintf(
32+
/* Translators: %1$s is the username, %2$s is the user email. */
33+
__( 'A new user with administrator privileges has been created:\nUsername: %1$s\nEmail: %2$s', 'wpvip' ),
34+
$user->user_login,
35+
$user->user_email
36+
);
37+
38+
wp_mail( $admin_email, $subject, $message );
39+
}
40+
}
41+
}
42+
43+
44+
Notify_Privileged_Activity::init();

utils/dev-env.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Automattic\VIP\Security\Utils;
44

55
function load_integration_configs_from_url() {
6-
if ( defined( 'WP_CLI' ) && constant( 'WP_CLI' ) ) {
7-
return;
8-
}
6+
// Removed for testing user creation (i.e. notify-privileged-activity)
7+
// if ( defined( 'WP_CLI' ) && constant( 'WP_CLI' ) ) {
8+
// return;
9+
// }
910

1011
$config_api_url = vip_get_env_var( 'VIP_CONFIG_API_URL', getenv( 'VIP_CONFIG_API_URL' ) );
1112

0 commit comments

Comments
 (0)