Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Add additional custom fields to profile page
- */
- 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 ( $profileuser ) {
- ?>
- <h3>Extra profile information</h3>
- <table class="form-table">
- <tr>
- <th>E-mail updates</th>
- <td>
- <label for="e_mail_updates"><input type="checkbox" name="e_mail_updates" id="e_mail_updates" <?php checked('true', $profileuser->e_mail_updates); ?> value="true" /> I would like to receive e-mail updates</label>
- </td>
- </tr>
- </table>
- <?php
- }
- /**
- * Save data input from custom field on profile page
- */
- add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
- add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
- function my_save_extra_profile_fields( $user_id ) {
- if ( !current_user_can( 'edit_user', $user_id ) )
- return false;
- /* Copy and paste this line for additional fields. Make sure to change 'e_mail_updates' to the field ID. */
- update_usermeta( $user_id, 'e_mail_updates', $_POST['e_mail_updates'] );
- }
- /**
- * Add cutom field to WPMU registration form
- */
- add_action('signup_extra_fields','custom_signup_extra_fields', $errors);
- // this in an example with a text input
- function custom_signup_extra_fields($errors) {
- ?>
- <label for="e_mail_updates"><input type="checkbox" name="e_mail_updates" id="e_mail_updates" <?php if(isset($_POST['e_mail_updates'])) checked('true', $_POST['e_mail_updates']); ?> value="true" /> I would like to receive e-mail updates
- </label>
- <br />
- <?php
- }
- /**
- * Save custom field input to wp_signups table
- */
- add_filter( 'add_signup_meta', 'custom_add_signup_meta' );
- function custom_add_signup_meta ( $meta = array() ) {
- // create an array of custom meta fields
- $meta['custom_usermeta'] = array(
- // 'meta_key' => $_POST['input_field'],
- 'e_mail_updates' => $_POST['e_mail_updates']
- );
- return $meta;
- }
- /**
- * Set new usermeta upon new user activation
- */
- add_action( 'wpmu_activate_user', 'custom_add_new_user_meta', 10, 3 );
- function custom_add_new_user_meta( $user_id, $email, $meta ) {
- if ( $meta['custom_usermeta'] ) {
- // loop through array of custom meta fields
- foreach ( $meta['custom_usermeta'] as $key => $value ) {
- // and set each one as a meta field
- update_user_meta( $user_id, $key, $value );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment