Add Custom Fields In Accounts Edit Page For WordPress

目錄

Original Posts

Add Custom Fields In Accounts Edit Page For WordPress


add_action( 'show_user_profile', 'add_birthday_meta' );
add_action( 'edit_user_profile', 'add_birthday_meta' );
function add_birthday_meta( $user ) {
  $birthday = get_user_meta ($user->ID , 'birthday', true); ?>
  <table class="form-table">
    <tr>
      <th><label for="birthday">生日</label></th>
        <td><input type="text" id="birthday" name="birthday" value="<?php echo $birthday ; ?>"></td>
      </tr>
  </table>
  <?php
}

add_action( 'personal_options_update', 'save_user_birthday' );
add_action( 'edit_user_profile_update', 'save_user_birthday' );
function save_user_birthday( $user_id ) {
  if ( ! current_user_can( 'edit_user', $user_id ) ) {
    return false;
  }
  update_user_meta( $user_id, 'birthday', $_POST['birthday'] );
}

Related Posts

The Complete WordPress Customization Tutorial – Just Copy And Paste And Work

Content Protection by DMCA.com
A
Aron

Leave a Reply

Your email address will not be published. Required fields are marked *