[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

Make WordPress Core

Opened 13 years ago

Closed 11 years ago

Last modified 10 years ago

#18709 closed enhancement (fixed)

Hooks in user-new.php

Reported by: standardtoaster's profile standardtoaster Owned by: helen's profile helen
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.2.1
Component: Administration Keywords: commit has-patch
Focuses: Cc:

Description

It would be nice to be able to enter extra metadata for users when manually creating them from the admin control panel.

I assume it should be as simple as adding a new action, along the lines of the edit_user_profile_update one?

Attachments (6)

new-user-profile.diff (443 bytes) - added by strangerstudios 13 years ago.
Diff to add a "new_user_profile" action to user-new.php
18709.patch (2.4 KB) - added by johnjamesjacoby 12 years ago.
Refresh, use existing naming conventions, and add actions before and after
18709.2.patch (2.6 KB) - added by strangerstudios 11 years ago.
user_new_form_before and user_new_form_after hooks
18709.3.patch (3.4 KB) - added by DrewAPicture 11 years ago.
hooks + passed context + hook docs
18709.4.patch (3.4 KB) - added by DrewAPicture 11 years ago.
typo
18709.diff (2.1 KB) - added by jeremyfelt 11 years ago.

Download all attachments as: .zip

Change History (49)

#1 @standardtoaster
13 years ago

  • Version changed from 3.3 to 3.2.1

#2 @SergeyBiryukov
13 years ago

Isn't that already possible by hooking to user_register and checking is_admin() if needed?

#3 @standardtoaster
13 years ago

It looks like the user_register hook is called AFTER the form is filled out, making it unsuitable for requested user metadata during the account creation process.

I'd like to add fields to the new user form (in the admin interface only). the form appears to be statically defined in user-new.php.

@strangerstudios
13 years ago

Diff to add a "new_user_profile" action to user-new.php

#4 follow-up: @strangerstudios
13 years ago

I think the OP meant to add form fields and other code to the actual form in user-new.php... similar to "edit_user_profile" and "show_user_profile" in user-edit.php.

I'd like to do something similar, and wonder why this hook isn't in place already.

Attached is a patch which just adds a "new_user_profile" action above the roles. (FYI, I created the diff against 3.3-beta2-19067)

A hack to work around not having this hook is to use the "show_password_fields" hook/filter. That hook seems to only be used on the user-new.php and user-edit.php page. It's meant to check if the password field should be shown, but you can output code at that point to add things to the form. You can check FILE or $_SERVERPHP_SELF? to distinguish between the new/edit user pages.

#5 in reply to: ↑ 4 @DrewAPicture
13 years ago

Replying to strangerstudios:

I think the OP meant to add form fields and other code to the actual form in user-new.php... similar to "edit_user_profile" and "show_user_profile" in user-edit.php.

I'd like to do something similar, and wonder why this hook isn't in place already.

+1 for this. A lot of us have had to work around tacking fields on using the show_password_fields hook before.

#6 @aaroncampbell
13 years ago

  • Cc aaroncampbell added
  • Keywords dev-feedback added

I just recently had to hack fields into the user-new form using the 'show_password_fields' filter. It's hacky and not an ideal place for the fields. I'd love to see something like this make it in. I'd probably add it to the end of the form, just above the submit button, but where it is in the patch isn't too bad either.

#7 @toscho
12 years ago

  • Cc info@… added

Currently we have to use JavaScript or output buffering to add custom fields. A real hook would be very useful. The patch looks fine for me.

#8 @l3rady
12 years ago

  • Cc scott@… added

Please can we have a hook here? WordPress has my my life more difficult due to the lack of hook at that point.

#9 @SergeyBiryukov
12 years ago

Related/duplicate: #13548

#10 @stephenh1988
12 years ago

  • Cc contact@… added

#11 @knutsp
12 years ago

  • Cc knut@… added

#12 @mtekk
12 years ago

  • Cc mtekkmonkey@… added

#13 @andyadams
12 years ago

  • Cc andyadamscp@… added

#14 @RyanGannon
12 years ago

  • Cc RyanGannon added

#15 @versusbassz
12 years ago

  • Cc versusbassz added

#16 @mordauk
12 years ago

  • Cc pippin@… added

#17 @johnjamesjacoby
12 years ago

  • Cc johnjamesjacoby added
  • Keywords has-patch added; dev-feedback removed
  • Milestone changed from Awaiting Review to 3.6

Necessary for a bbPress enhancement. #BB2223

Last edited 12 years ago by SergeyBiryukov (previous) (diff)

#18 @nacin
12 years ago

This hook is different from edit_user_profile and show_user_profile, as it actually takes place between table rows, rather than between tables.

Ideally, the hook would be placed in such a way that it does not rely on a table being there. One of these days, all of these tables will go away, and a hook like new-user-profile.diff will make that difficult if not impossible.

#19 @aaroncampbell
12 years ago

I was just talking through this in IRC and was voicing the same concerns. I like the idea of having a hook here, but I'd prefer it be moved outside the table to just before the submit button.

@johnjamesjacoby
12 years ago

Refresh, use existing naming conventions, and add actions before and after

#20 @johnjamesjacoby
12 years ago

18709.patch also adds actions to the network admin page.

#21 @sunnyratilal
12 years ago

  • Cc sunnyratilal5@… added

#22 @JG Visual
12 years ago

  • Cc JG Visual added

#23 @ocean90
12 years ago

  • Milestone changed from 3.6 to Future Release

#24 @strangerstudios
11 years ago

I like @johnjamesjacoby's patch. Let's get it pushed.

For those wondering how you would process the POST data of any fields added using the new hooks, you can use the user_register and added_existing_user hooks to check $_POST, nonces, and update user meta, etc.

#25 @strangerstudios
11 years ago

FYI, JJJ's patch might be outdated. I will get an updated one posted tomorrow.

@strangerstudios
11 years ago

user_new_form_before and user_new_form_after hooks

#26 @strangerstudios
11 years ago

18709.2 attached. This patch changes the names of the hooks added in the previous patch. The two hooks added now are:

  • user_new_form_before
  • user_new_form_after

First, I made both the network version and non-network version use the same set of hooks. The previous patch added new_user_form_before/after and add_user_form_before/after. I think this may have been a typo, but might have been intentional. If intentional, I think that it makes sense to use one set of hooks and let the plugin authors decide if they want to do something different for network sites and non-network sites. This is similar to the edit_user_profile hook which appears in the network and non-network version of user-edit.php.

I also switched the order from new_user to user_new to match the filename and another hook already in place there (user_new_form_tag).

I tested 18709.2 on the latest codebase (as of posting) and it works great. I'm open to double checks and ideas around the hook naming/etc.

#27 @strangerstudios
11 years ago

  • Cc strangerstudios added
  • Version changed from 3.2.1 to 3.6

#28 follow-up: @ocean90
11 years ago

  • Version changed from 3.6 to 3.2.1

Version field indicates when the enhancement was initially suggested.

#29 in reply to: ↑ 28 @strangerstudios
11 years ago

Replying to ocean90:

Version field indicates when the enhancement was initially suggested.

Thanks.

#30 @MZAWeb
11 years ago

Used the last patch for this http://bbpress.trac.wordpress.org/ticket/2223 and works great.

It'd be great to have this into 3.7

#31 @jeremyfelt
11 years ago

  • Milestone changed from Future Release to 3.7

#32 @desrosj
11 years ago

  • Cc desrosj@… added

#34 @DrewAPicture
11 years ago

  • Keywords commit added; needs-docs removed

Since we're using the same two hooks in three different places, we should pass a context string with the actions to make targeting an 'Add Existing User' vs an 'Add New User' form a lot easier.

This is done + hook docs in 18709.3.patch.

@DrewAPicture
11 years ago

hooks + passed context + hook docs

@DrewAPicture
11 years ago

typo

#35 @jeremyfelt
11 years ago

Semantics...both actions fire inside the form, not before or after. Not sure if we have a pattern around that.

Seems ok to go in as it shouldn't have too much of an impact on any future revamps of the table structure in new/edit user. The latest patches don't add table rows. The only restricting aspect is that the actions both fire inside <form>, and before <submit>, but those shouldn't be a big deal.

#36 @jeremyfelt
11 years ago

ignore the double submit

Looking at #BB2223, only the after hook is used. I wonder if that alone would be useful enough to enable plugins to introduce extra fields before the <submit>.

Last edited 11 years ago by jeremyfelt (previous) (diff)

#37 @helen
11 years ago

I'm pretty wary of a hook firing before, given that all these forms are pretty normalized with username at top. One at the bottom, outside the table, seems okay, if maybe a little less than ideal. Can probably just be user_new_form in that case.

#38 @nacin
11 years ago

  • Keywords needs-patch added; has-patch removed

Okay, let's add a single hook after the table, inside the form, before the submit button. Needs patch.

@jeremyfelt
11 years ago

#39 @jeremyfelt
11 years ago

  • Keywords has-patch added; needs-patch removed

18709.diff introduces one action, user_new_form.

#40 @helen
11 years ago

  • Owner set to helen
  • Resolution set to fixed
  • Status changed from new to closed

In 25629:

Add a user_new_form hook, with context. props johnjamesjacoby, strangerstudios, jeremyfelt, DrewAPicture. fixes #18709.

#41 @nacin
11 years ago

I'm reverting this from the network admin. It was modeled after the profile editing hooks, but the profile editor in the network admin is a direct inclusion of wp-admin/user-edit.php.

In this case, wp-admin/network/user-new.php is *not* the same as wp-admin/user-new.php. The function edit_user() is not used. We could rename the hook to network_user_new_form, but there is no obvious hook to manipulate the data that is coming in. wpmu_create_user() is used directly in this context.

wp-admin/user-new.php and wp-admin/network/user-new.php need a bit of an overhaul to clean up the supremely hacky multisite handling in both contexts. The network form is also a skeleton — user and email only. The context is significantly different, and while it can be handled with an is_network_admin() check, it's more likely that someone will attach a callback to user_new_form and end up creating a non-working field in the network admin.

#42 @nacin
11 years ago

In 25631:

Remove the new user_new_form hook from the network admin, pending further review. see #18709.

#43 @jeremyfelt
10 years ago

Related #13339, which requests a hook for the network admin new user form.

Note: See TracTickets for help on using tickets.