向WordPress注册表表单添加字段

时间:2012-12-11 作者:JacobTheDev

如何在WordPress注册表中添加字段?例如,我想将用户配置文件中的“名字”字段添加到注册表表单中,但我不知道如何操作。

字段名称为first\\u name,但添加<input type="text" name="first_name" id="first_name" value="<?php echo $_POST[\'first_name\']; ?>" required="required" placeholder="<?php _e(\'First Name\'); ?>" /> 因为某种原因不起作用。表单提交很好,但是概要文件没有在后端填写“名字”字段。

我正在编辑此插件以调整注册表表单:http://wordpress.org/extend/plugins/s8-custom-login-and-registration/

2 个回复
最合适的回答,由SO网友:JacobTheDev 整理而成

我找到了一个出色的免费插件,可以完成这项工作。

http://wordpress.org/extend/plugins/user-registration-aide/

非常容易使用,将字段添加到寄存器和配置文件页面。

SO网友:Ahmad M

我不知道您正在使用的插件,但将自定义字段添加到注册表并将其保存到用户配置文件的方法是register_form 操作挂钩输出字段,然后使用适当的过滤器/操作挂钩更新/保存用户配置文件。

您的案例,例如:

<?php
// output the form field
add_action(\'register_form\', \'ad_register_fields\');
function ad_register_fields() {
?>
    <p>
        <label for="firstname"><?php _e(\'First Name\') ?><br />
        <input type="firstname" name="firstname" id="firstname" class="input" value="<?php echo esc_attr($_POST[\'firstname\']); ?>" size="25" tabindex="20" />
        </label>
    </p>
<?php
}

// save new first name
add_filter(\'pre_user_first_name\', \'ad_user_firstname\');
function ad_user_firstname($firstname) {
    if (isset($_POST[\'firstname\'])) {
        $firstname = $_POST[\'firstname\'];
    }
    return $firstname;
}
?>

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register