用户元-额外的配置文件字段-不显示在添加新用户- Wordpress



我在Wordpress用户配置文件中添加了两个额外的用户配置文件字段。一切似乎都工作得很好,查看,编辑和更新,除了字段没有显示在"添加新"用户配置文件创建。

这里有user_register动作add_action('user_register', 'tbc_save_extra_profile_fields', 10, 1);

也尝试了add_action('user_register', 'tbc_show_extra_profile_fields', 10, 1);

但是新帐户的字段仍然没有出现。

我做错了什么?

下面是我的完整代码:

function tbc_custom_define() {
$custom_meta_fields = array();
$custom_meta_fields['tbc_company_name'] = 'Company name';
$custom_meta_fields['tbc_company_website'] = 'Company website';
return $custom_meta_fields;
}
function tbc_show_extra_profile_fields($user) {
print('<h3>Business information</h3>');
print('<table class="form-table">');
$meta_number = 0;
$custom_meta_fields = tbc_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
print('<tr>');
print('<th><label for="' . $meta_field_name . '">' . $meta_disp_name . '</label></th>');
print('<td>');
print('<input type="text" name="' . $meta_field_name . '" id="' . $meta_field_name . '" value="' . esc_attr( get_the_author_meta($meta_field_name, $user->ID ) ) . '" class="regular-text" /><br />');
print('<span class="description"></span>');
print('</td>');
print('</tr>');
}
print('</table>');
}
function tbc_save_extra_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id))
return false;
$meta_number = 0;
$custom_meta_fields = cdl_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
update_user_meta( $user_id, $meta_field_name, $_POST[$meta_field_name] );
}
}
add_action('show_user_profile', 'tbc_show_extra_profile_fields');
add_action('edit_user_profile', 'tbc_show_extra_profile_fields');
add_action('personal_options_update', 'tbc_save_extra_profile_fields');
add_action('edit_user_profile_update', 'tbc_save_extra_profile_fields');
add_action('user_register', 'tbc_save_extra_profile_fields', 10, 1);

新用户表单的钩子是user_new_form:

add_action('user_new_form', 'tbc_show_extra_profile_fields', 99, 1);
add_action('show_user_profile', 'tbc_show_extra_profile_fields', 99, 1);
add_action('edit_user_profile', 'tbc_show_extra_profile_fields', 99, 1);

注意:

当user_new_form被调用时,第一个参数是:

(string)指定新用户表单类型的上下文字符串钩子紧随其后。

因此,如果您要对所有钩子使用相同的tbc_show_extra_profile_fields(),请记住正确处理$user_id变量。

相关内容

最新更新