dp13668681869 2018-11-19 22: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-20 02: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.

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

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入