WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#33320 closed feature request (worksforme)

Custom table names for all wordpress tables for wpdb

Reported by: soodl Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Database Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Wordpress let's you define custom table prefixes and totally custom names for the users table (and therefore user meta table). I guess this is done to enable multiple blogs to share a userbase, but why stop here?

Please consider to give users the ability to choose names for all tables completely by themselves if they want to. You can't estimate what a user tries to achieve with this and therefore only custom user table names is quite limiting and inconsistent.

Please also see this ticket: #7008

The only way to accomplish custom table names besides user tables is to patch wpdb.php which causes headaches on updates.

Attachments (1)

db.php (607 bytes) - added by pento 5 years ago.

Download all attachments as: .zip

Change History (7)

#1 @pento
5 years ago

Thank you for the feature request, @soodl!

Could you please give an example of what you would use this for?

#2 @soodl
5 years ago

Thank you for your immediate answer @pento.

My use case would be to be able to share users AND content across multiple installs, e.g only a custom wp_options table.

Loading a different set of plugins or theme on the same user base and connected posts opens up some interesting possibilities in my opinion.

SEO problems might pop up but only if you let both installs show the same content.
That's only an idea you could do much more but I think it's important to have to ability to do so if you wish. Not everyone is using wordpress simply as a blogging platform. Sharing some tables across installs would be a huge advantage in flexibility in general.

Besides I do not understand the decision to give users the freedom to choose custom table names but limiting them to user tables at the same time. I think this feature would be easy to implement, brings consistency to the custom table names approach and users would gain flexibility.


#3 @SergeyBiryukov
5 years ago

  • Description modified (diff)

@pento
5 years ago

#4 @pento
5 years ago

Thanks for the extra information, @soodl.

Rather than adding new defines, it's possible for you to do this using a db.php dropin as a replacement for WPDB.

wpdb::tables() is used throughout core to retrieve table lists, as well as to set the WPDB table name members - $wpdb->posts, for example, so well written plugins (that don't assume the table name) will continue to function correctly.

By extending it as in the example I've attached, you can replace a few or all table names.

#5 @soodl
5 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Thank you very much for this elegant solution, @pento.

I didn't know this is possible. I already used drop-ins like advanced-cache.php but never looked up their behavior in general. This is by far the best solution in terms of simplicity and updates.

It would be good to let people know about this solution, who might want to use custom table names after reading this codex article (https://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables) and start to wonder why you can only set custom names on those tables.

Really learned something today, thank you.

#6 @netweb
5 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.