[英]Wordpress Multisite Add custom fields on registration then show in Profile Page
[英]Add custom profile fields
我正在嘗試將2個電話號碼的自定義用戶個人資料字段添加到我正在工作的WordPress網站上。 此時,我已經嘗試了互聯網上的所有內容,因此可以聯系到這里。
我還需要將字段添加到注冊頁面以與另一個插件集成,因為我已經是WordPress的本地注冊人了,所以只需在注冊中添加字段即可。
我已經能夠將字段添加到wp-admin編輯概要文件頁面中的編輯概要文件頁面。 但是我不能將它們添加到注冊頁面。
這是我到目前為止工作過的代碼:
$extra_fields = array(
array( 'company_phone', __('Company Phone', 'rc_cucm'), true ),
array( 'personal_phone', __('Personal Phone', 'rc_cucm'), true ),
);
// Use the user_contactmethods to add new fields
add_filter( 'user_contactmethods', 'rc_add_user_contactmethods' );
/**
* Add custom users custom contact methods
*
* @access public
* @since 1.0
* @return void
*/
function rc_add_user_contactmethods( $user_contactmethods ) {
// Get fields
global $extra_fields;
// Display each fields
foreach( $extra_fields as $field ) {
if ( !isset( $contactmethods[ $field[0] ] ) )
$user_contactmethods[ $field[0] ] = $field[1];
}
// Returns the contact methods
return $user_contactmethods;
}
當我為注冊頁面添加此部分時,出現錯誤“解析錯誤:語法錯誤,
在第44行的/home/content/e/t/e/eternalreefs/html/affiliates/wp-content/plugins/custom-user-contact-methods/rc-custom-user-contact-methods.php中出現意外的T_STRING”
:
//This is where the error occur when I try to add fields to the registration page
// Add our fields to the registration process
2
add_action( 'register_form', 'rc_register_form_display_extra_fields' );
3
add_action( 'user_register', 'rc_user_register_save_extra_fields', 100 );
/**
* Show custom fields on registration page
*
* Show custom fields on registration if field third parameter is set to true
*
* @access public
* @since 1.0
* @return void
*/
function rc_register_form_display_extra_fields() {
// Get fields
global $extra_fields;
// Display each field if 3th parameter set to "true"
foreach( $extra_fields as $field ) {
if( $field[2] == true ) {
if( isset( $_POST[ $field[0] ] ) ) { $field_value = $_POST[ $field[0] ]; } else { $field_value = ''; }
?>
<p>
<label for="<?php echo $field[0]; ?>"><?php echo $field[1]; ?><br />
<input type="text" name="<?php echo $field[0]; ?>" id="<?php echo $field[0]; ?>" class="input" value="<?php echo $field_value; ?>" size="20" /></label>
</label>
</p>
<?php
} // endif
} // end foreach
}
/**
* Save field values
*
* @access public
* @since 1.0
* @return void
*/
function rc_user_register_save_extra_fields( $user_id, $password = '', $meta = array() ) {
// Get fields
global $extra_fields;
$userdata = array();
$userdata['ID'] = $user_id;
// Save each field
foreach( $extra_fields as $field ) {
if( $field[2] == true ) {
$userdata[ $field[0] ] = $_POST[ $field[0] ];
} // endif
} // end foreach
$new_user_id = wp_update_user( $userdata );
}
如果我對自己的問題很了解,那么對發生問題的任何見解都會有所幫助。如果我做錯了,請告訴我。
看一下Profile Builder 。 您可以根據需要添加任意數量的額外自定義用戶字段。
我真的會考慮看看一個名為Advanced Custom Fields的插件。 讓我們將所有類型的自定義字段添加到頁面,帖子,自定義帖子類型,附件甚至用戶!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.