「Theme My Login」の登録フォームの項目に「blog上の表示名」をつけたい
-
「Theme My Login」というテンプレートを用いて会員サイトを構築しています。
会員登録フォームを作成するに当たり、下記のコードを利用して項目に「ニックネーム」を追加することができました。
このコードを利用して「ブログ上の表示名」も自動登録したいのですが、コーディングで行き詰っております。。
大変お手数でございますが
どなたかご教示いただけましたら幸いです。■[function.php]
/***********************************************
* ユーザープロフィールの項目の追加と削除
***********************************************/
function my_user_meta($contactmethods) {//不要な項目の削除
unset($contactmethods[‘aim’]);
unset($contactmethods[‘jabber’]);
unset($contactmethods[‘yim’]);
unset($contactmethods[‘user_name_kana’]);
unset($contactmethods[‘user_sex’]);
unset($contactmethods[‘user_company’]);
unset($contactmethods[‘user_tel’]);
unset($contactmethods[‘user_fax’]);
unset($contactmethods[‘user_addr_zip’]);
unset($contactmethods[‘user_addr_pref’]);
unset($contactmethods[‘user_addr’]);
unset($contactmethods[‘user_confirm’]);//項目の追加
$contactmethods[‘nickname’] = ‘ニックネーム’;
// $contactmethods[”] = ‘フリガナ’;
// $contactmethods[”] = ‘性別’;
// $contactmethods[”] = ‘会社名’;
// $contactmethods[”] = ‘電話番号’;
// $contactmethods[”] = ‘FAX番号’;
// $contactmethods[”] = ‘郵便番号’;
// $contactmethods[”] = ‘都道府県’;
// $contactmethods[”] = ‘住所’;
// $contactmethods[”] = ‘会員規約に同意’;
return $contactmethods;
}
add_filter(‘user_contactmethods’, ‘my_user_meta’, 10, 1);/***********************************************
* ユーザープロフィール項目の登録時の保存
***********************************************/
function tml_user_register( $user_id ) {
if ( !empty( $_POST[‘nickname’ ] ) ) update_user_meta( $user_id, ‘nickname’, $_POST[‘nickname’ ] );
// if ( !empty( $_POST[‘last_name’ ] ) ) update_user_meta( $user_id, ‘last_name’, $_POST[‘last_name’ ] );
// if ( !empty( $_POST[‘user_name_kana’] ) ) update_user_meta( $user_id, ‘user_name_kana’, $_POST[‘user_name_kana’] );
// if ( !empty( $_POST[‘user_sex’ ] ) ) update_user_meta( $user_id, ‘user_sex’ , $_POST[‘user_sex’ ] );
// if ( !empty( $_POST[‘user_company’ ] ) ) update_user_meta( $user_id, ‘user_company’, $_POST[‘user_company’ ] );
// if ( !empty( $_POST[‘user_addr_zip’ ] ) ) update_user_meta( $user_id, ‘user_addr_zip’, $_POST[‘user_addr_zip’ ] );
// if ( !empty( $_POST[‘user_tel’ ] ) ) update_user_meta( $user_id, ‘user_tel’, $_POST[‘user_tel’ ] );
// if ( !empty( $_POST[‘user_fax’ ] ) ) update_user_meta( $user_id, ‘user_fax’, $_POST[‘user_fax’ ] );
// if ( !empty( $_POST[‘user_addr_pref’] ) ) update_user_meta( $user_id, ‘user_addr_pref’, $_POST[‘user_addr_pref’] );
// if ( !empty( $_POST[‘user_addr’ ] ) ) update_user_meta( $user_id, ‘user_addr’, $_POST[‘user_addr’ ] );
// if ( !empty( $_POST[‘user_confirm’ ] ) ) update_user_meta( $user_id, ‘user_confirm’, $_POST[‘user_confirm’ ] );
}
add_action( ‘user_register’, ‘tml_user_register’ );/***********************************************
* 新規ユーザー登録時のバリデート
***********************************************/
function tml_registration_errors( $errors ) {// $tel_format=”/^[0-9]{2,3}\-[0-9]{3,4}\-[0-9]{3,4}$/”;
if ( empty( $_POST[‘nickname’ ] ) ) $errors->add( ‘empty_nickname’, ‘エラー: お名前を入力してください’);
// if ( empty( $_POST[‘user_name_kana’] ) ) $errors->add( ‘empty_user_name_kana’, ‘エラー: お名前フリガナを入力してください’ );
// if ( empty( $_POST[‘user_tel’] ) ) {
//電話番号が入力されていな場合のエラー
// $errors->add( ‘empty_user_tel’, ‘エラー: 電話番号を入力してください’ );
// } else {
//電話番号は入力されているが書式が間違っている場合のエラー
// if ( !preg_match($tel_format,$_POST[“user_tel”]) ) {
// $errors->add( ‘error_user_tel’, ‘エラー: 電話番号の書式が間違っています’ );
// }
// }
// if ( !empty( $_POST[‘user_fax’] ) && !preg_match($tel_format,$_POST[“user_fax”]) ) {
//FAX番号は入力されているが書式が間違っている場合のエラー(空はOK)
// $errors->add( ‘error_user_fax’, ‘エラー: FAX番号の書式が間違っています’ );
// }
// if ( empty( $_POST[‘user_confirm’ ] ) ) $errors->add( ‘empty_user_confirm’, ‘エラー: 会員規約に同意をチェックしてください’ );return $errors;
}add_filter( ‘registration_errors’, ‘tml_registration_errors’ );
■[register-form.php]
<?php
/*
If you would like to edit this file, copy it to your current theme’s directory and edit it there.
Theme My Login will always look in your theme’s directory first, before using this default template.
*/
?>
<div class=”tml tml-register” id=”theme-my-login<?php $template->the_instance(); ?>”>
<?php $template->the_action_template_message( ‘register’ ); ?>
<?php $template->the_errors(); ?>
<form name=”registerform” id=”registerform<?php $template->the_instance(); ?>” action=”<?php $template->the_action_url( ‘register’, ‘login_post’ ); ?>” method=”post”>
<?php if ( ‘email’ != $theme_my_login->get_option( ‘login_type’ ) ) : ?>
<p class=”tml-user-login-wrap”>
<label for=”user_login<?php $template->the_instance(); ?>”><?php _e( ‘Username’, ‘theme-my-login’ ); ?></label>
<input type=”text” name=”user_login” id=”user_login<?php $template->the_instance(); ?>” class=”input” value=”<?php $template->the_posted_value( ‘user_login’ ); ?>” size=”20″ />
</p>
<?php endif; ?><p class=”tml-user-email-wrap”>
<label for=”user_email<?php $template->the_instance(); ?>”><?php _e( ‘E-mail’, ‘theme-my-login’ ); ?></label>
<input type=”text” name=”user_email” id=”user_email<?php $template->the_instance(); ?>” class=”input” value=”<?php $template->the_posted_value( ‘user_email’ ); ?>” size=”20″ />
</p><?php do_action( ‘register_form’ ); ?>
<!– ▼▼▼ 追加ここから ▼▼▼ –>
<p>
<label for=”nickname<?php $template->the_instance(); ?>”>ニックネーム</label>
<input type=”text” name=”nickname” id=”nickname<?php $template->the_instance(); ?>” class=”input” value=”<?php $template->the_posted_value( ‘nickname’ ); ?>” size=”40″ />
</p><!– ▲▲▲ 追加ここまで ▲▲▲ –>
<p class=”tml-registration-confirmation” id=”reg_passmail<?php $template->the_instance(); ?>”><?php echo apply_filters( ‘tml_register_passmail_template_message’, __( ‘Registration confirmation will be e-mailed to you.’, ‘theme-my-login’ ) ); ?></p>
<p class=”tml-submit-wrap”>
<input type=”submit” name=”wp-submit” id=”wp-submit<?php $template->the_instance(); ?>” value=”<?php esc_attr_e( ‘Register’, ‘theme-my-login’ ); ?>” />
<input type=”hidden” name=”redirect_to” value=”<?php $template->the_redirect_url( ‘register’ ); ?>” />
<input type=”hidden” name=”instance” value=”<?php $template->the_instance(); ?>” />
<input type=”hidden” name=”action” value=”register” />
</p>
</form>
<?php $template->the_action_links( array( ‘register’ => false ) ); ?>
</div>■参照サイトはこちら
http://yahss.net/wordpress/765-registration-form2-with-theme-my-login/
- トピック「「Theme My Login」の登録フォームの項目に「blog上の表示名」をつけたい」には新たに返信することはできません。