我正在互联网上搜索,但在用户激活他们的博客/网站后找不到如何添加或更新元数据。
我想添加这些字段,以便用户可以在其个人资料页面中看到他们的附加元/自定义字段。
我的 wp-signup.php 文件中有以下代码:
$signup_meta = array(
'organization_address'=>$_POST['organization_address'],
'organization_name'=>$_POST['organization_name'],
'organization_number'=>$_POST['organization_number'],
'organization_address'=>$_POST['organization_address'],
'organization_zip'=>$_POST['organization_zip'],
'organization_city'=>$_POST['organization_city'],
'organization_country'=>$_POST['organization_country'],
'first_name'=>$_POST['first_name'],
'last_name'=>$_POST['last_name'],
'phone'=>$_POST['phone'],
'lang_id' => 1,
'public' => $public
);
wpmu_signup_blog($domain, $path, $blog_title, $email, $email, $signup_meta);
add_action('user_register', 'custom_register_extra_fields');
add_action('wpmu_activate_user', 'stjert_register_user_meta', 10, 3);
$meta_defaults = apply_filters( 'signup_create_blog_meta', $signup_meta );
confirm_blog_signup($domain, $path, $blog_title, $email, $email, $signup_meta);
然后在我的functions.php
文件中,我有以下代码:
add_action ( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields ( $user )
{
<h3>Kontaktinformasjon</h3>
<table class="form-table">
<tr>
<th><label for="first_name">Fornavn:</label></th>
<td>
<input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( get_the_author_meta( 'first_name', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th><label>Etternavn:</label></th>
<td>
<input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( get_the_author_meta( 'last_name', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th><label>Telefon:</label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
</table>
我删减了代码,因为它太长了。
当我转到个人资料页面(wp-admin)时,我没有看到我在注册期间拥有的那些自定义字段/元值,我在想也许它没有保存或其他什么?
对此有任何帮助吗?请。我对wordpress真的很陌生,"Wordpress方式"对我来说非常困难。感觉与MVC框架非常不同。
您的帮助将不胜感激!
谢谢!
PS:这是我的整个wp注册代码.php http://pastebin.com/YcvHeHkC
我认为
我还没有完全理解这里的问题......但我看到的是,您正在尝试使用非常规字段制作注册表并将其另存为元数据。你的思维方式是正确的,但我不太确定功能......
目前尚不清楚您是否要在管理面板内部或外部执行此操作,因此,我的建议是
创建检索其用户名、密码和电子邮件的用户,使用
wp_create_user( $username, $password, $email ); // Go to codex
http://codex.wordpress.org/Function_Reference/wp_create_user
此函数将返回给定创建的用户的 ID,然后您获得所有这些帖子,并在 foreach 或其他东西中使用这个其他函数
add_user_meta( $user_id, $meta_key, $meta_value, $unique ); // Go to codex
http://codex.wordpress.org/Function_Reference/add_user_meta
最后,在编辑页面上,或者您想要显示它的位置,您可以使用
get_user_meta($user_id, $key, $single); // Go to codex
http://codex.wordpress.org/Function_Reference/get_user_meta