Wordpress获取由管理员在编辑用户页面上发送的帖子变量

I want to detect in my plugin (or functions.php), if a variable POST is just sent. I mean, when the admin change the role of a user, the variable post ROLE is sent.

<select name="role" id="role">
<option value="shop_manager">Shop manager</option>
<option value="customer">Customer</option>
<option selected="selected" value="level_1">Level 1</option>
<option value="subscriber">Subscriber</option>
<option value="contributor">Contributor</option>
<option value="author">Author</option>
<option value="editor">Editor</option>
<option value="administrator">Administrator</option><option value="">— No role for this site —</option>

add_action('edit_user_profile', 'CheckPost', 10, 1);//loading on user-edit.php

$rolemodified = $_POST['role'];
function CheckPost(){
if( !empty($rolemodified) ){ echo "ROLE: $rolemodified ";  } 
}

I want to retrieve this $_POST['role']; or show it on an alert

echo "<script type='text/javascript'>alert('post:');</script>";

Thanks

I think this is a variable scoping issue.

$rolemodified is not available within your function.

Try to add it as a global variable in your function like this:

add_action('edit_user_profile', 'CheckPost', 10, 1);//loading on user-edit.php

$rolemodified = $_POST['role'];
function CheckPost() {
    global $rolemodified; // or set $rolemodified here
    if( !empty($rolemodified) ){ echo "ROLE: $rolemodified ";  } 
}

EDIT: I just noticed that you are also using the edit_user_profile hook. You will need to use the edit_user_profile_update hook to get the post values.