WordPress / WordPress/WordPress-Coding-Standards
SQL queries should not use hardcoded table names
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem?
Using hardcoded table names in SQL queries causes problems for multisite installations, or users who have changed the default table prefix.
Describe the solution you'd like
Queries that do not use the $wpdb->prefix to determine table names, should trigger a CS error.
$wpdb->prepare( "SELECT * FROM wordpress.wp_posts WHERE id = %d", $id);
Additional context (optional)
see also (loosely related) https://github.com/WordPress/WordPress-Coding-Standards/issues/1589
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the requested example in issue #2008 and review the loosely related issue #1589 for existing discussion. Determine how the coding-standard sniff should identify hardcoded table names versus $wpdb->prefix usage, and consider the request complete when matching queries produce a CS error without flagging supported prefixed queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100