Avoiding the options table when retrieving a user option
|Reported by:||nacin||Owned by:|
Follow up to #11385.
We're querying the options table unnecessarily and unexpectedly on some calls to get_user_option(). This function first checks if the user option (say, 'rich_editing') exists at the per-blog per-user level, then the per-user level, then the per-blog level. The per-blog level can be turned off via one of the arguments but it is on by default.
There are currently seven different user options we check the options table for. Four (use_ssl, admin_color, comment_shortcuts, rich_editing) are set in wp_insert_user(), so unless a plugin deliberately removes the user meta there and wants the options table to be queried, we'll never generate needless queries on that.
On the other hand, screen_layout_$screen, plugins_last_view, and autosave_draft_ids are generating unnecessary queries on the options table when they have yet to be initialized. Patch here changes those.
Bigger picture here: We should come up with a new get_user_option() that doesn't check the options table by default. Since there is no use of get_user_option() in core that should fall back by default, I'm thinking that the options table check could perhaps be better served by a filter.