简体   繁体   English

如何在编辑用户页面中添加自定义字段

[英]How to add custom field in edit user page

I would like to add new field in contact info section of edit user profile page. 我想在“编辑用户个人资料”页面的“联系信息”部分添加新字段。 I am using this code but it is adding new section after account management section but i want add it after email in contact info section. 我正在使用此代码,但是它在帐户管理部分之后添加了新部分,但是我想在联系信息部分中的电子邮件之后添加它。

<?php

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("User profile information", "blank"); ?></h3>
    <table class="form-table">
        <tr>
            <th><label for="phone"><?php _e("Operational Manager Email"); ?></label></th>
            <td>
                <input type="text"
                       name="operational_email"
                       class="regular-text" 
                       value="<?php echo esc_attr( get_the_author_meta( 'operational_email', $user->ID ) ); ?>"/>
                <br />
                <span class="description">
                    <?php _e("Please enter opertional manager email.">
                </span>
            </td>
        </tr>
    </table>
<?php
}

add_action( 'personal_options_update', 'yoursite_save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'yoursite_save_extra_user_profile_fields' );

function yoursite_save_extra_user_profile_fields( $user_id ) {
    $saved = false;
    if ( current_user_can( 'edit_user', $user_id ) ) {
        update_user_meta(
            $user_id,
            'operational_email', 
            $_POST['operational_email']
        );
        $saved = true;
    }
    return true;
}

在此处输入图片说明

在此处输入图片说明

Well i had it done in my theme in recent project but i did it from the filter name 'user_contactmethods' Read documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/contactmethods 好吧,我在最近的项目中以主题完成了此操作,但是我是通过过滤器名称“ user_contactmethods”完成的:阅读文档: https : //codex.wordpress.org/Plugin_API/Filter_Reference/contactmethods

add_filter( 'user_contactmethods', 'extra_contact_info' );

function extra_contact_info( $fields ) {
  $fields['email'] = __( 'Operational Manager Email' );
  return $fields;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将自定义字段添加到编辑订单页面 - How to add a custom field to the Edit Order page 在 Woocommerce 编辑帐户页面中添加自定义字段 - Add a custom field in Woocommerce Edit Account page 将自定义字段添加到现有部分中的用户编辑页面 - Adding a custom field to the user edit page within an existing section 如何在magento的注册页面上添加自定义字段 - How to add a custom field on register page in magento 如何在Wordpress的发布框内的编辑帖子页面中添加一个字段? - How to add a field in edit post page inside Publish box in Wordpress? 如何在wordpress的“添加新页面”页面中添加自定义字段 - how to add a custom field in the “Add New page” page in wordpress 将高级自定义字段添加到 Dokan 上的现有表单 - 添加产品和编辑产品页面 (WordPress/WooCommerce) - Add Advanced Custom Field to existing form on Dokan- Add product & edit product page (WordPress/WooCommerce) php - 如何将自定义模式添加到管理编辑帖子页面 - php - How to add a custom modal to the admin edit posts page 在用户编辑页面Drupal 8上添加用户角色 - Add user role on user edit page Drupal 8 在添加/编辑产品页面上添加自定义按钮 - Add custom button on add/edit product page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM