0

I have created multiple user fields.
These fields are only managed by the administrator to add additional information about the user

Now the rules have changed. The users must gain access to their fields from the front end but are not allowed to edit all the fields.

So I want to show only the fields the user is allowed to change. I have created this but ran into a problem while saving.

If the form is saved it clears out all the fields that are not in the form. I would like to update the user fields that are in the form and the once that are not must remain untouched!

This is what I did.: I created a template file and added:

<?php 
global $current_user, $wp_roles;
get_currentuserinfo();
$error = array();    
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {
if ( !empty( $_POST['first_name'] ) )
    update_user_meta( $current_user->ID, 'first_name', esc_attr( $_POST['first_name'] ) );

if ( count($error) == 0 ) {
    do_action('edit_user_profile_update', $current_user->ID);
    wp_redirect( get_bloginfo('url').'/my-page/');
    exit;
}
}?>
<?php if ( count($error) > 0 ) echo '<p class="error">' . implode("<br />", $error) . '</p>'; ?>
    <form method="POST" id="adduser" action="<?php the_permalink(); ?>" enctype="multipart/form-data">
        <table>
            <tr>
                <td>Name:</td>
                <td><input class="profile_formfield" name="first_name" type="text" id="first_name" value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>" /></td>
            </tr>
            <tr>
                <td>
                    <p class="profile_form_submit">
                        <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Opslaan', 'profile'); ?>" />
                        <?php wp_nonce_field( 'update-user' ) ?>
                        <input name="action" type="hidden" id="action" value="update-user" />
                    </p>                        
                </td>
            </tr>
         </table>

An ugly solution could be to add all the fields as hidden fields. But I rather not!

See what I did wrong?

M.

0

I have found the solution

do_action('edit_user_profile_update', $current_user->ID); was the problem. After I commented it out the update went fine.

do_action is a plugin hook and expected way more that the from gave:
explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.