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 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合