[wp-hackers] Why do some user meta entries use the table prefix in the meta key?
david at wordshell.net
Sat May 11 20:51:30 UTC 2013
I've developed some code that imports a WordPress database, and allows a
change of $table_prefix whilst you do so. i.e. If the site you're
importing had a different table prefix, then you can change it as you
The running of the SQL import itself works fine - that's just some
regexes before executing the SQL.
However, testing it out has revealed something I did not know before -
that various entries in the usermeta table have meta_key entries that
depend upon the table prefix. Essential example: if your prefix is wp_,
then your user will have an entry wp_capabilities, which contains your
So, those also need renaming - otherwise you can't even log in (because
the entries being looked for aren't there).
Whilst researching, I came across this plugin:
It appears to know about this phenomena. It makes two adjustments:
i. (prefix)_user_roles in the options table
ii. Then all those beginning with (prefix) in the user meta table.
1. Why does WordPress do this? On the face of it, it seems like a gross
layering violation - table keys depend on the names of tables. But the
WP core coders are smart guys, so there must be a reason.
2. Are there any others that anyone knows about? Any other hidden
hazards to changing your table prefix?
WordShell - WordPress fast from the CLI - www.wordshell.net
More information about the wp-hackers