WordPress.org

Make WordPress Core

#25762 closed enhancement (fixed)

Make it easier to customize the install process

Reported by: Denis-de-Bernardy Owned by: nacin
Milestone: 3.9 Priority: normal
Severity: minor Version: 3.7
Component: Upgrade/Install Keywords: has-patch
Focuses: Cc:

Description

It's currently possible to override a couple of functions in a wp-content/install.php file, namely:

  • wp_install() - top level install function
  • wp_install_defaults() - Installs default post, page, links, cat, etc.
  • wp_new_blog_notification() - Sends the new blog email.
  • wp_upgrade() - Top level upgrade function.

However, they severely lack plugin hooks, which would allow developers to simply hack in there accordingly without needing to keep install functions in sync with core when they want to tweak them.

I'd like to suggest adding hooks named after those functions at the end of each of them.

Attachments (11)

25762.diff (772 bytes) - added by Denis-de-Bernardy 15 months ago.
25762.2.diff (681 bytes) - added by Denis-de-Bernardy 15 months ago.
25762.3.diff (999 bytes) - added by Denis-de-Bernardy 15 months ago.
25762.4.diff (1021 bytes) - added by nacin 15 months ago.
25762.5.diff (1016 bytes) - added by nacin 15 months ago.
Pass $user instead of $user_id since we have it.
25762.6.diff (1.4 KB) - added by Denis-de-Bernardy 15 months ago.
25762.7.diff (1.4 KB) - added by Denis-de-Bernardy 15 months ago.
fix space vs tab
25762.8.diff (2.4 KB) - added by Denis-de-Bernardy 15 months ago.
add wp_install_defaults hook, and switch to user_id for wp_install for consistency
25762.9.diff (6.3 KB) - added by Denis-de-Bernardy 15 months ago.
Fix #11210 as well
25762.10.diff (6.2 KB) - added by Denis-de-Bernardy 15 months ago.
Same as the previous one, s/4space/tab/
25762.11.diff (4.0 KB) - added by Denis-de-Bernardy 15 months ago.
Per IRC discussions

Download all attachments as: .zip

Change History (29)

comment:1 @DrewAPicture18 months ago

  • Cc xoodrew@… added

+1 for adding these hooks.

comment:2 @Denis-de-Bernardy18 months ago

Adding this back link for reference, since the question originating from there:

http://wordpress.stackexchange.com/a/120539/1208

comment:3 @johnbillion18 months ago

  • Cc johnbillion added

comment:4 follow-up: @nacin15 months ago

  • Component changed from General to Upgrade/Install
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from feature request to enhancement

Would definitely like more hooks here.

comment:5 in reply to: ↑ 4 ; follow-up: @Denis-de-Bernardy15 months ago

Replying to nacin:

Would definitely like more hooks here.

Will a patch make it into the next WP version if supplied, or does it need a crazy amount of discussion before getting checked in?

comment:6 in reply to: ↑ 5 @nacin15 months ago

  • Milestone changed from Future Release to 3.9

Replying to Denis-de-Bernardy:

Will a patch make it into the next WP version if supplied, or does it need a crazy amount of discussion before getting checked in?

The original suggestion seem straightforward enough to me:

I'd like to suggest adding hooks named after those functions at the end of each of them.

I wouldn't be surprised if there are additional opportunities for well-placed actions or filters, but one per function would certainly be a good start. Would be happy to check in a patch this week.

@Denis-de-Bernardy15 months ago

comment:7 @Denis-de-Bernardy15 months ago

  • Keywords has-patch added

Replying to nacin:

I wouldn't be surprised if there are additional opportunities for well-placed actions or filters, but one per function would certainly be a good start. Would be happy to check in a patch this week.

I stuck to two hooks, seeing that those two would have been more than enough for use-cases that I've run into over the years:

  • one at the very end of wp_install, that passes user_id
  • another at the very end of wp_upgrade, that passes the new and old database version

The second patch should be svn-compatible (generated using git diff --noprefix).

Last edited 15 months ago by Denis-de-Bernardy (previous) (diff)

comment:8 @DrewAPicture15 months ago

  • Keywords needs-docs added

We'll need docs for these hooks, wherever they land per the Inline Docs standards.

comment:9 @Denis-de-Bernardy15 months ago

  • Keywords needs-docs removed

comment:10 @ircbot15 months ago

This ticket was mentioned in IRC in #wordpress-dev by nacin. View the logs.

@nacin15 months ago

comment:11 follow-up: @nacin15 months ago

This looks great. Some little things:

  • These are actual doc blocks, they need /**
  • 3.9.0 versus 3.9

Also, you put the wp_upgrade hook in upgrade_all(), not wp_upgrade(). Intentional? Looks like wp_upgrade() is indeed the right place for it, as your comment above suggested.

@nacin15 months ago

Pass $user instead of $user_id since we have it.

comment:12 in reply to: ↑ 11 ; follow-up: @Denis-de-Bernardy15 months ago

Replying to nacin:

This looks great. Some little things:

  • These are actual doc blocks, they need /**
  • 3.9.0 versus 3.9

Looks like you did that in your amended patch.

Also, you put the wp_upgrade hook in upgrade_all(), not wp_upgrade(). Intentional? Looks like wp_upgrade() is indeed the right place for it, as your comment above suggested.

It was in the wrong function, ya. *tired*… I see you fixed that too.

comment:13 in reply to: ↑ 12 @nacin15 months ago

Replying to Denis-de-Bernardy:

It was in the wrong function, ya. *tired*… I see you fixed that too.

All good, just wanted to double-check!

comment:14 @nacin15 months ago

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

In 27045:

Add wp_install and wp_upgrade hooks to the respective functions.

props Denis-de-Bernardy.
fixes #25762.

comment:15 @Denis-de-Bernardy15 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

The wp_install hook never gets called in a multisite environment. Placing it in wp_install_defaults was in fact correct.

@Denis-de-Bernardy15 months ago

fix space vs tab

@Denis-de-Bernardy15 months ago

add wp_install_defaults hook, and switch to user_id for wp_install for consistency

comment:16 @Denis-de-Bernardy15 months ago

Marked #11210 as related.

@Denis-de-Bernardy15 months ago

Fix #11210 as well

@Denis-de-Bernardy15 months ago

Same as the previous one, s/4space/tab/

comment:17 @ircbot15 months ago

This ticket was mentioned in IRC in #wordpress-dev by ddebernardy. View the logs.

@Denis-de-Bernardy15 months ago

Per IRC discussions

comment:18 @nacin14 months ago

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

I'm closing this as fixed based on the [27045]. I think the additional proposals are significantly less straightforward and need a new ticket.

Note: See TracTickets for help on using tickets.