WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9302 closed enhancement (fixed)

Add hook for update profile

Reported by: Cimmo Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Users Keywords: profile hook
Focuses: Cc:

Description

As today there is no possibility to add some checks to profile update, this is limiting Cimy User Extra Fields.

I suggest to add this hook, see patch.

Attachments (3)

profile_update_post.diff (373 bytes) - added by Cimmo 5 years ago.
patch_ticket9302_v2.diff (476 bytes) - added by Cimmo 5 years ago.
Patch v2 against WordPress 2.8 beta1
patch_ticket9302_v3.diff (488 bytes) - added by Cimmo 5 years ago.
Ok this is the correct patch against WordPress 2.8 beta1 that I propose

Download all attachments as: .zip

Change History (21)

Cimmo5 years ago

comment:1 azaozz5 years ago

Do we need a new action or perhaps do_action('edit_user_profile_update'); can be used?

comment:2 Cimmo5 years ago

No that hook is not useful, because the $errors array is not passed and user is updated anyway if there are errors on extra fields.

comment:3 Nicholas915 years ago

  • Keywords dev-feedback added; cimy removed

comment:4 follow-up: Denis-de-Bernardy5 years ago

  • Keywords reporter-feedback added; profile hook dev-feedback removed

I use the following hooks in my author images plugin:

  • edit_user_profile
  • show_user_profile
  • profile_update

can you confirm they're not enough?

comment:5 in reply to: ↑ 4 Cimmo5 years ago

  • Keywords profile hook dev-feedback added; reporter-feedback removed

Replying to Denis-de-Bernardy:

I use the following hooks in my author images plugin:

  • edit_user_profile
  • show_user_profile
  • profile_update

can you confirm they're not enough?

If you can show me that with those three I can prevent an user to be updated because some extra fields didn't pass some checks/rules then yes, but I doubt you can.

comment:6 follow-up: Denis-de-Bernardy5 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

you can redirect/die on pre_user_login

comment:7 in reply to: ↑ 6 Cimmo5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Replying to Denis-de-Bernardy:

you can redirect/die on pre_user_login

but WordPress crew got a course for people closing bugs? Seems you answer with the silliest answer all the time.

HOW can I add errors to be displayed with your filter?

comment:8 Cimmo5 years ago

I mean to the $error array, not somewhere else!

comment:9 follow-up: Denis-de-Bernardy5 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

you can pass an error_id argument in the url you redirect to.

plus, there are like... so many other hooks you can hook into. like load-profile.php, load-user-edit.php, load-user-new.php. not to mention personal_options_update and edit_user_profile_update, which occur before the update.

if anything, the real trouble is choosing the one you'd rather use...

comment:10 in reply to: ↑ 9 ; follow-up: Cimmo5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Replying to Denis-de-Bernardy:

you can pass an error_id argument in the url you redirect to.

I do NOT redirect anything, I use the form already present under profile, so can you explain it better?


plus, there are like... so many other hooks you can hook into. like load-profile.php,

is this a file? an hook? can you show me where is that searching for it I didn't find it?

load-user-edit.php, load-user-new.php.

and those? Same as above.

not to mention personal_options_update and edit_user_profile_update, which occur before the update.

yea not to mentioned that I _already_ mentioned that those hooks are useless since $errors array is NOT passed, so profile is updated ANYWAY, regardless my errors.

if anything, the real trouble is choosing the one you'd rather use...

if anything, the real trouble is finding people that read carefully instead of trolling around.

comment:11 Cimmo5 years ago

Summerizing my patch does:
0) enable extra check on fields
1) enable you to stop updating profile if some extra errors are added by plug-in
2) display _automatically_ those errors at the top of the profile, together with other

NOW:
is there a possibility to do 1+2+3 with actual WordPress? Looking at the code I do not see the possibility, with my 1 line patch that does not hurt anyone, you can do all the three at once.

NOT to mention that a similar hook is present for registration, so there is no point why there and not here.

comment:12 in reply to: ↑ 10 Denis-de-Bernardy5 years ago

Replying to Cimmo:

plus, there are like... so many other hooks you can hook into. like load-profile.php,

is this a file? an hook? can you show me where is that searching for it I didn't find it?

wp-admin/admin.php

every default admin page has a load-something hook that gets called before the page is actually loaded, and every plugin page gets two: load-something_plugin and something_plugin.

personally, I usually use the first to load files only when needed, and the second to trigger save procedures -- because by then, you know the user is valid so don't need to worry about permissions.

if anything, the real trouble is finding people that read carefully instead of trolling around.

I'd actually take offense on that if you had authored as many WP plugins as I have...

comment:13 azaozz5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [11096]) Add hook for update profile, props Cimmo, fixes #9302

Cimmo5 years ago

Patch v2 against WordPress 2.8 beta1

comment:14 Cimmo5 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I have seen that under wp-login.php "same" hook pass also $user_login and $user_email so I thought we can enhance my original patch before breaking compatibility on a stable release :)

Cimmo5 years ago

Ok this is the correct patch against WordPress 2.8 beta1 that I propose

comment:15 Denis-de-Bernardy5 years ago

shouldn't this hook be using something like do_action_ref_array()?

comment:16 Denis-de-Bernardy5 years ago

  • Component changed from Validation to Users
  • Milestone set to 2.8
  • Version set to 2.8

comment:17 westi5 years ago

  • Keywords dev-feedback removed

Well in PHP5 it will get passed by reference here. But I believe in PHP4 it will not!

So currently this works for PHP5 and not PHP4 I suspect (no PHP4 test setup here at the moment)

So yeah we need to use references here otherwise the hooked function can't change what's in the $errors in all PHP versions.

As for passing in the user_login and user_email I'm not sure why they should be treated as special here. Why not just pass in the currently processed $user object?

comment:18 westi5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [11441]) Pass references and more context to the new 'user_profile_update_errors' hook. Fixes #9302.

Note: See TracTickets for help on using tickets.