Skip to content

Commit

Permalink
Add Admin user data to JetPack connected event
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-vara committed Nov 11, 2024
1 parent ddfeb6e commit 8b17c7c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions includes/Listeners/Jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function connected( $id, $secret, $is_public ) {
array(
'id' => $id,
'public' => $is_public,
'users' => array( $this, 'get_admin_users' ),
)
);
}
Expand Down Expand Up @@ -133,4 +134,31 @@ public function detect_plugin_activation( $plugin ) {
update_option( 'jetpack_affiliate_code', $this->brand_code[ $brand ] );
}
}

/**
* Get Admin and SuperAdmin user accounts
*
* @return $users Array of Admin & Super Admin users
*/
private function get_admin_users() {
// Get all admin users
$admin_users = get_users([
'role' => 'administrator',
]);
$users = [];

// Add administrators to the $users and check for super admin
foreach ($admin_users as $user) {
$users[] = [
'id' => $user->ID,
'username' => $user->user_login,
'email' => $user->user_email,
'name' => $user->display_name,
'roles' => $user->roles,
'super_admin' => is_super_admin($user->ID),
];
}

return $users;
}
}

0 comments on commit 8b17c7c

Please sign in to comment.