2

To customize a fresh new WP install, there are a bunch of pluginable functions that can be overridden. Namely wp_install() and wp_install_defaults(). And wp_new_blog_notification().

I'd like to override a couple of default options without needing to keep custom versions of the latter in sync with core in my wp-content/install.php file.

I'm not finding any obvious hook to do so in the wp-includes/upgrade.php file, however. Might I be missing anything?


Edit: so, the pre_option_$option_name is valid for options. Is there another, or some not-too-twisted procedure, that would allow to auto-enable permalinks, including (important) writing to the htaccess file as needed?

1

if you have a file at WP_CONTENT_DIR/install.php it will be run before the upgrade starts. If you want to override specific option then you can use the pre_update_option_$optionname filter to control the value written to the DB.

something like

add_filter('pre_update_option_admin_email','wpse_120475_myadminmail',10,2);

function wpse_120475_myadminmail($newemail,$oldemail) {
  return 'evil@me.com';
}

caution - wasn't tested but I assume that the filter API is available at that stage.

As for rewrite rules, the tricky part is generating the .htaccess file but since you obviously create your own installation image then you can add to it the .htaccess file in the root directory (the .htaccess is very generic and not tied to a specific domain name or directory location). Then all that is left to do is to control the rewrite rules options using the technique described above.

  • +1, since that would work for options. I'll edit my question, however, because I was hoping for one that might also allow to auto-enable permalinks. – Denis de Bernardy Oct 29 '13 at 13:10
  • updated the answer for that – Mark Kaplun Oct 29 '13 at 13:43
  • I wish it were that simple. There are a few side effects that occur when the rules are flushed. :-) But it's a good lead indeed. – Denis de Bernardy Oct 29 '13 at 14:05
  • you right, I forgot that there is some writing to the DB, but guess it is only and AI call away, just don't ask me which :) – Mark Kaplun Oct 29 '13 at 16:32
  • *chuckle*. But my question precisely is: which one? :-) Anyway, I'll keep looking… – Denis de Bernardy Oct 29 '13 at 16:33
0

There are a couple of interesting hooks for use in an install.php:

  • pre_update_option_{$option_name}
    Generally useful to override defaults as they get stored.

  • added_user_meta
    Allows to disable the welcome screen

But for heavy listing such as changing the default category's name, the default post and page, or changing permalinks, hooks are definitely missing. In particular, a bunch of options are added using populate_options(), and do so without any plugin hook whatsoever.

I've opened a ticket requesting new hooks here:

http://core.trac.wordpress.org/ticket/25762

The easiest in the meanwhile is to override wp_new_blog_notification() — the function is relatively simple to keep in sync with the WP core.

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.