【发布时间】:2017-07-25 16:06:16
【问题描述】:
我有一个带有自定义表单的页面,它通过 admin-post.php 发送帖子数据。几天前这曾经可以正常工作,但现在似乎它甚至没有触发该功能。这是代码。 我在同一个网站上还有一些其他类似的表格,但它们都已停止工作。
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="POST">
<input type="hidden" name="action" value="create_user">
<?php wp_nonce_field('create_user'); ?>
<input type="text" class="form-control" name="first_name" placeholder="First Name" required/>
<input type="text" class="form-control" name="last_name" placeholder="Last Name" required/>
</form>
在我的functions.php中我有这个
function create_user() {
$retrieved_nonce = $_POST['_wpnonce'];
if (!wp_verify_nonce($retrieved_nonce, 'create_user' ) ){
$status = 'failed';
}else{
// My Code goes here
}
}
add_action( 'admin_post_create_user', 'estudy_create_user' );
我尝试过回显某些内容并删除脚本只是为了检查该功能是否被触发,但这也不起作用。
对正确方向的任何帮助都会很棒:)
【问题讨论】:
-
admin_post 仅适用于登录用户。遵循本指南:sitepoint.com/handling-post-requests-the-wordpress-way
-
@TomBroucke 我已经登录并分配了一个自定义角色。这个角色过去工作得很好。