php – 如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?我尝试使用配置文件构建器插件,但无法插入自定义字段,如性别广播框等.
您可以在wp-admin中为用户添加额外的用户字段.
在functions.PHP插件文件夹中使用它:
//extra user info in wp-admin
add_action( 'show_user_PRofile','yoursITe_extra_user_profile_fields' );
add_action( 'edit_user_profile','yoursite_extra_user_profile_fields' );
function yoursite_extra_user_profile_fields( $user ) {
?>
  <h3><?PHP _e("Extra profile information","blank"); ?></h3>
  <table class="form-table">
    <tr>
      <th><label for="company"><?PHP _e("Company"); ?></label></th>
      <td>
        <input tyPE="text" name="company" id="company" class="regular-text" 
            value="<?PHP echo esc_attr( get_the_author_Meta( 'company',$user->ID ) ); ?>" /><br />
    </td>
    </tr>   
    <tr>
      <th><label for="job"><?PHP _e("Job"); ?></label></th>
      <td>
        <input type="text" name="job" id="job" class="regular-text" 
            value="<?PHP echo esc_attr( get_the_author_Meta( 'job',$user->ID ) ); ?>" /><br />
    </td>
    </tr>    
    <tr>
      <th><label for="country"><?PHP _e("Country"); ?></label></th>
      <td>
        <input type="text" name="country" id="country" class="regular-text" 
            value="<?PHP echo esc_attr( get_the_author_Meta( 'country',$user->ID ) ); ?>" /><br />
    </td>
    </tr>
    <tr>
      <th><label for="city"><?PHP _e("City"); ?></label></th>
      <td>
        <input type="text" name="city" id="city" class="regular-text" 
            value="<?PHP echo esc_attr( get_the_author_Meta( 'city',$user->ID ) ); ?>" /><br />
    </td>
    </tr>     
    <tr>
      <th><label for="phone"><?PHP _e("Phone"); ?></label></th>
      <td>
        <input type="text" name="phone" id="phone" class="regular-text" 
            value="<?PHP echo esc_attr( get_the_author_Meta( 'phone',$user->ID ) ); ?>" /><br />
    </td>
    </tr>

  </table>
<?PHP
}

之后,您必须在wp-admin中进行编辑时保存字段

//Save our extra registration user Meta.
add_action('user_register','myplugin_user_register'); 
function myplugin_user_register ($user_id) {
    if ( isset( $_POST['phone'] ) )
        update_user_Meta($user_id,'phone',$_POST['phone']);   

    if ( isset( $_POST['company'] ) )
        update_user_Meta($user_id,'company',$_POST['company']);

    if ( isset( $_POST['job'] ) )
        update_user_Meta($user_id,'job',$_POST['job']);   

    if ( isset( $_POST['country'] ) )
        update_user_Meta($user_id,'country',$_POST['country']);   

    if ( isset( $_POST['city'] ) )
        update_user_Meta($user_id,'city',$_POST['city']);

    if ( isset( $_POST['user_interest'] ) )
        update_user_Meta($user_id,'user_interest',$_POST['user_interest']);

}

功能将为您的用户添加自定义字段.

在那之后,在前端,你当然可以使用wp_insert_user(); function和wp_update_user();使用您创建的所有自定义字段注册和编辑用户.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?全部内容,希望文章能够帮你解决php – 如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。