You can use jQuery or plain javascript to add event listener to the role select
element. E.g.
jQuery(document).on('ready', function(){
jQuery('select#role').on('change', function(){
// some if statement here
alert('Role changed');
});
});
To add this to your admin you can either use admin_enqueue_scripts
or admin_footer
hooks.
To enqueue script file,
function my_admin_enqueue_scripts( $hook_suffix ) {
if ( 'user-edit.php' === $hook_suffix || 'user-new.php' === $hook_suffix ) {
wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false );
}
}
add_action('admin_enqueue_scripts', 'my_admin_enqueue_scripts');
To inline the script in admin footer,
function my_admin_enqueue_scripts() {
global $pagenow;
if ( 'user-edit.php' !== $pagenow && 'user-new.php' !== $pagenow ) {
return;
}
?>
<script>
jQuery(document).on('ready', function(){
jQuery('select#role').on('change', function(){
alert('Role changed');
});
});
</script>
<?php
}
add_action('admin_footer', 'my_admin_enqueue_scripts');
If there’s a popup you want to show, when a certain role is selected, then you could add the popup html to the admin footer and have the change action make it visible. Should you need styling for the popup, use wp_enqueue_style()
in admin_enqueue_scripts
.
P.s I added the user-new.php check as an extra example.