我正在创建一个用户编辑管理页面上的自定义字段。我将自定义代码添加到functions.php中。
问题:有时更新db,有时不更新db。
我以为这是缓存,但不是那样。有人能告诉我为什么有时更新,但不是总是更新?你看到我的代码有问题了吗?
代码:
add_action( 'show_user_profile', 'be_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'be_show_extra_profile_fields' );
function be_show_extra_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th><label for="contact">Phone</label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Enter phone number.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'be_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'be_save_extra_profile_fields' );
function be_save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_usermeta( $user_id, 'phone', esc_attr( $_POST['phone'] ) );
}更新
我现在知道为什么admin表单有时更新db,有时不更新db。管理表单有一个电话字段,在配置文件页面上也有电话字段。当我在admin中更新电话并刷新配置文件页上的页面时,它会在文本框未填写时更新它。当textbox被填写,我在admin中更新表单时,刷新配置文件页面将从配置文件页面中插入电话号码。因此,配置文件页面有一个问题,它在刷新时插入数据。
发布于 2018-03-26 23:35:12
我现在知道为什么admin表单有时更新db,有时不更新db。管理表单有一个电话字段,在配置文件页面上也有电话字段。当我在admin中更新电话并刷新配置文件页上的页面时,它会在文本框未填写时更新它。当textbox被填写,我在admin中更新表单时,刷新配置文件页面将从配置文件页面中插入电话号码。因此,配置文件页面有一个问题,它在刷新时插入数据。管理表单正在更新数据库。profile表单使它看起来没有更新,因为刷新时它将用该值更新db。
https://stackoverflow.com/questions/49500747
复制相似问题