5

I'm looking for the hook that fires when a user's information are updated. Specifically, I want to update a post with the value of a custom profile field (in my example info) everytime that user's profile is updated.

I tried the profile_update hook, but it doesn't seem to fire:

add_action( 'profile_update', 'add_info_to_post' );
function add_info_to_post( $user_id ) {

        $info=get_user_meta($user_id,'info',true);

        //get all items of that user
        $args=array(
                'author' => $user_id,
                'post_type' => 'item',
        );

        $items=get_posts($args);            
        foreach ($items as $item){
        update_post_meta($item->ID,'user_info',$info);
        }
}

Any suggestions how to make this work?

EDIT: Maybe I should mention that I access the users' profile pages through the backend..

  • In your code the function name and the function you have in the add_action don't match. – Nicolai Jun 5 '14 at 10:25
  • right! corrected – SPi Jun 5 '14 at 10:26
5

From Codex: Plugin API - Action Reference - profile_update:

Note: This hook is not used on user edit/profile pages. To hook into the admin's user edit pages, use the hook edit_user_profile_update which is located in /wp-includes/user-edit.php instead.

From Codex: Plugin API - Action Reference - edit_user_profile_update:

This hook only triggers when a user is viewing another user's profile page (not their own). If you want to apply your hook to ALL profile pages (including the current user) then you also need to use the personal_options_update hook.

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.