首页 文章

WP编辑用户自定义字段更新

提问于
浏览
0

所以我已经如此接近,但这里有一个错误 . 我正在做的是我已经为WP wooCommerce安装添加了3个自定义字段 . 我已经通过钩子和woo模板添加到注册和我的帐户页面 . 我可以从他们的 Profiles 区/前端成功更新为用户 . 我坚持的是让编辑用户管理表单更新这些字段 . 我可以让字段显示,但它们只是没有更新 .

寻找想法和帮助 . 我错过了什么?提前致谢 .

这是我的子主题函数中的代码.php - ADMIN EDIT USER

function sbb_custom_user_profile_fields($user) {
?>
<legend><h4>Reseller Info</h4></legend>
<table class="form-table">
<tr>
<th>
    <label for="ssb_reseller_tax_id"><?php _e('Resseller Tax ID'); ?></label>
</th>
<td>
    <input type="text" name="sbb_reseller_tax_id" id="sbb_reseller_tax_id" 
value="<?php echo esc_attr( get_the_author_meta( 'reseller_tax_id', $user->ID 
) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th>
    <label for="sbb_title"><?php _e('Title'); ?></label>
</th>
<td>
<input type="text" name="sbb_title" id="sbb_title" value="<?php echo esc_attr( get_the_author_meta( 'title', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th>
    <label for="sbb_fax"><?php _e('Fax'); ?></label>
</th>
<td>
    <input type="text" name="sbb_fax" id="sbb_fax" value="<?php echo esc_attr( get_the_author_meta( 'fax', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
</table>
<?php
update_user_meta( get_the_author_meta( $user->ID ), 'reseller_tax_id', htmlentities( $_POST[ 'reseller_tax_id' ] ) );
update_user_meta( get_the_author_meta( $user->ID ), 'fax', htmlentities( $_POST[ 'fax' ] ) );
update_user_meta( get_the_author_meta( $user->ID ), 'title', htmlentities( $_POST[ 'title' ] ) );
}

add_action('show_user_profile', 'sbb_custom_user_profile_fields');
add_action('edit_user_profile', 'sbb_custom_user_profile_fields');
add_action('edit_user_profile_update', 'sbb_custom_user_profile_fields' );

1 回答

  • 0

    我在代码中看到的直接问题是've posted is you'为输入名称添加前缀 . 您可以使用 reseller_tax_id 的元键保存值,但输入名称为 sbb_reseller_tax_id . 这是您需要在 $_POST 中使用的输入名称 .

    $_POST[ 'reseller_tax_id' ] ) 将成为 $_POST['sbb_reseller_tax_id'] )

    在尝试保存之前,我建议检查表单是否已提交,并且您有输入值 . 仅查看页面不应具有执行更新的效果 .

相关问题