dp13668681869 2018-11-19 14:38
浏览 67
已采纳

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

  • 写回答

1条回答 默认 最新

  • duanbei6427 2018-11-19 18:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部