WordPress nonce快把我逼疯了!当我启动插件并删除它时,我遇到了这个问题,但现在我又回来了,仍然不知道该怎么办。
我到处寻找解决办法。我的代码与其他示例相同/相似。我得到一个“未定义索引‘mrlpt\\u client\\u check’”错误。
在基于用户功能检查权限时,我也会遇到与“mrlpt\\U客户端”相同的错误,但这是我创建的自定义帖子类型,所以我不确定为什么这也不起作用?
这是nonce元素所在的代码。include只是在一个自定义元框中包含一个简短的表单,其中有两个输入字段,一个用于电子邮件地址,一个用于电话号码。
我已经尝试将wp\\u nonce\\u字段()包含在HTML表单include中,但同样的错误也不起作用。
有人能帮忙吗?谢谢
function mrlpt_client_details( $client_post ) {
// Retrieve saved metadata if it exists
$mrlpt_clientEmail = get_post_meta( $client_post->ID, \'_mrlpt_client_email\', true );
$mrlpt_clientPhoneNum = get_post_meta( $client_post->ID, \'_mrlpt_client_phone_num\', true );
// Create a nonce field for verification
wp_nonce_field( \'mrlpt_submit_client\', \'mrlpt_client_check\' );
// Includes the form elements inside the meta box
require_once( \'includes/mrlpt-client-form.php\' );
}
// Update/Save client meta data
add_action( \'save_post\', \'save_client_metadata\' );
function save_client_metadata( $client_post_id ) {
// Verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) {
return;
}
// Verify this came from the our screen and with proper authorization, because save_post can be triggered at other times
if ( !isset( $_POST[\'mrlpt_client_check\'] ) && !wp_verify_nonce( $_POST[\'mrlpt_client_check\'], \'mrlpt_submit_client\' ) ) {
return;
}
// Check permissions - If the post type is mrlpt_client
if ( \'post\' == $_POST[\'mrlpt_client\'] ) {
// If the user cannot publish posts
if ( !current_user_can_for_blog( $blog_id, \'publish-post\' ) ) { // Checks by capability, not role
wp_die( \'Insufficient privileges: Sorry, you do not have access to this page.\' );
}
}
// OK, we\'re authenticated: we need to find and save the data
// Verify the meta data is set
if ( isset( $_POST[\'mrlpt_client_email\'] ) && isset( $_POST[\'mrlpt_client_phone_num\'] ) ) {
// Save meta data
update_post_meta( $client_post_id, \'_mrlpt_client_email\', strip_tags( $_POST[\'mrlpt_client_email\'] ) );
update_post_meta( $client_post_id, \'_mrlpt_client_phone_num\', strip_tags( $_POST[\'mrlpt_client_phone_num\'] ) );
}
}