Open jrfnl opened 5 years ago
Naming conventions for tables themselves should be straightforward.
That alone would save people much drama!
The fields and columns though ... that’s going to need a lot more thought. Camelcasing columns and field names has been drama for me as a host, but in general it’s supported all down the line.
It’s just when someone’s doofy and uses FieldName and fieldname in the same table...
Having something laid out that emphasized something along the vain of "table names should always be lowercase with underscores used for spacing", would help in eliminating a repeat of the discovery I raised to @jrfnl (in #core-coding-standard).
Is your feature request related to a problem?
The WP Coding Standards handbook currently covers naming conventions for all sorts of structures, but does not formalize any naming conventions for database tables, nor table fields/columns.
As case-sensitive names can cause issues with cross-platform compatibility, the unofficial guideline is to always use lowercase names with words underscore separated.
This unofficial convention is largely complied with within WP core at the moment, with some notable exceptions, such as the
comment_ID
,comment_post_ID
andcomment_author_IP
fields in thecomments
table,ID
in theposts
andusers
tables andID
andIP
in the multisiteregistration_log
tables.Based on a brief discussion about this in the #core-coding-standards Slack channel, we are proposing to formalize this naming convention and add a rule to that effect to the handbook.
Describe the solution you'd like
If this proposal is accepted and a rule to this effect added to the handbook, a sniff can be written which would examine any
CREATE TABLE
andALTER TABLE
database queries to verify that table names and field names comply with this requirement.I'm proposing that existing exceptions in Core as listed above will not be changed as the BC-break would be too large.
Additional context (optional)
$wpdb
, such as$wpdb->terms
can be ignored by the sniff. For any other variables/constants, we will need to decide whether to err on the side of caution and throw a warning which will often turn out to be a false positive or to err on avoiding annoyance, which may lead to false negatives./cc @pento @Ipstenu