実現したいこと
wordpress(ワードプレス)のプロフィールで、動作させる。
前提
プロフィールで、新しい項目を追加しました。
ここの解説通りにしました。ラジオボタンのみを作成して、もう1つ増やしました。
https://increment-log.com/wordpress-user-profile-add-meta-field/
エラーが出て動きません。なぜか、わかる方いますか?
発生している問題・エラーメッセージ
function add_profile_sample_fields( $user ) {
?>
<h2><?php _e( '追加情報' ); ?></h2>
<table class="form-table">
<tr>
<th><?php _e( 'お得なメール' ); ?></th>
<td>
<fieldset>
<label>
<input type="radio" name="radio-1" value="ON" <?php checked( get_user_meta( $user->ID, 'radio-1', true ), 'ON' ); ?> />ON
</label>
<label>
<input type="radio" name="radio-1" value="OFF" <?php checked( get_user_meta( $user->ID, 'radio-1', true ), 'OFF' ); ?> />OFF
</label>
</fieldset>
</td>
</tr>
<tr>
<th><?php _e( 'お得なお知らせ' ); ?></th>
<td>
<fieldset>
<label>
<input type="radio" name="radio-2" value="ON" <?php checked( get_user_meta( $user->ID, 'radio-2', true ), 'ON' ); ?> />ON
</label>
<label>
<input type="radio" name="radio-2" value="OFF" <?php checked( get_user_meta( $user->ID, 'radio-2', true ), 'OFF' ); ?> />OFF
</label>
</fieldset>
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'add_profile_sample_fields' );
add_action( 'edit_user_profile', 'add_profile_sample_fields' );
function update_profile_sample_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
$meta_keys = array( 'radio-1' => $_POST['radio-1'] 'radio-2' => $_POST['radio-2'] //ここでエラーが発生します。また、項目も保存されません。 ); foreach( $meta_keys as $key => $value ) { update_user_meta( $user_id, $key, $value ); } return true;
}
add_action( 'personal_options_update', 'update_profile_sample_fields' );
add_action( 'edit_user_profile_update', 'update_profile_sample_fields' );
該当のソースコード
PHP
試したこと
'radio-2' => $_POST['radio-2']
の部分を省くとエラーが出なくなるが、保存はされず、機能もしません。

0 コメント