【问题标题】:Wordpress add user number field in contact information partWordpress 在联系信息部分添加用户编号字段
【发布时间】:2020-12-07 11:26:34
【问题描述】:

我想知道如何实现以下目标。 我尝试在联系信息下的 wordpress 用户配置文件中创建一个数字字段输入。

到目前为止,如果我使用 show_user_profile 和 edit_user_profile 挂钩,该字段将出现在个人资料页面的底部。

是否可以在联系信息部分下创建一个数字字段(wordpress中的标准?)

我尝试为操作添加不同的优先级,但这并没有解决问题。

到目前为止,我有以下内容:

function addurenuser(){
    $userid = get_current_user_id();
    if ( current_user_can('update_plugins',$userid)){ ?>
        <table class="form-table">
            <tr>
            <th>
            <label>Uren</label>
                </th>
                <td>
            <input type="number" name="uren" id="uren" value="<?php echo esc_attr( get_the_author_meta( 'uren', $user->ID ) ); ?>">
            </td>
            </tr>
</table> <?php
    }
}
add_action( 'show_user_profile', 'addurenuser' );
add_action( 'edit_user_profile', 'addurenuser' );

【问题讨论】:

    标签: wordpress user-profile


    【解决方案1】:

    使用此代码

    function addurenuser()
      {
        echo '<script>
        jQuery(document).ready(function($){
    $(".your-custom-field").insertAfter($(".user-email-wrap").closest("table"));
        });
        </script>';
        $userid = get_current_user_id();
        if (current_user_can('update_plugins', $userid)) { ?>
        <table class="form-table your-custom-field">
          <tr>
            <th>
              <label>Uren</label>
            </th>
            <td>
              <input type="number" name="uren" id="uren" value="<?php echo esc_attr(get_the_author_meta('uren', $userid->ID)); ?>">
            </td>
          </tr>
        </table> <?php
                    }
                  }
                  add_action('show_user_profile', 'addurenuser');
                  add_action('edit_user_profile', 'addurenuser');
    

    【讨论】:

      猜你喜欢
      • 2010-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多