I would maybe split this function up into more clearly named pieces (e.g. `replace_post_save_hooks`, `replace_settings`). Not a big issue -- just flagging for consideration.