WordPress.org

Make WordPress Core

Opened 13 days ago

Closed 10 days ago

#54769 closed enhancement (fixed)

INNER JOIN missing "AS" in /wp-includes/link-template.php

Reported by: domainsupport Owned by: SergeyBiryukov
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch
Focuses: Cc:

Description

Line 1833 of /wp-includes/link-template.php reads ...

<?php
                                $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";

... but I believe it should read ...

<?php
                                $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";

It appears to be missing an "AS" after the second INNER JOIN.

Oliver

Attachments (1)

54769.diff (2.0 KB) - added by costdev 13 days ago.
Add missing AS keywords to src/wp-includes/link-template.php and src/wp-includes/taxonomy.php.

Download all attachments as: .zip

Change History (5)

#1 @costdev
13 days ago

  • Milestone changed from Awaiting Review to 6.0
  • Type changed from defect (bug) to enhancement

@domainsupport thanks for opening this ticket.

While AS is an optional keyword in SQL, meaning that this isn't a defect (bug), it is commonly considered best practice to include the AS keyword for better readability and compatibility.

To my knowledge, this doesn't fall under any of the official coding standards in WordPress, but this query and almost every other INNER JOIN that uses aliases in Core includes the AS keyword - the one other exception I could find was in src/wp-includes/taxonomy.php:2536.

For the reason(s) above as well as consistency in Core, I think we should add the AS keyword in both of these files.

Milestoning this for 6.0 and marking as an enhancement.

Last edited 13 days ago by costdev (previous) (diff)

@costdev
13 days ago

Add missing AS keywords to src/wp-includes/link-template.php and src/wp-includes/taxonomy.php.

#2 @costdev
13 days ago

  • Keywords has-patch added

#3 @johnbillion
13 days ago

  • Version trunk deleted

#4 @SergeyBiryukov
10 days ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 52553:

Database: Add missing AS after INNER JOIN in some queries.

While AS is an optional keyword in SQL, it is commonly considered best practice to include it for better readability and compatibility. This also makes the queries more consistent with other queries using aliases in core.

Follow-up to [6359], [30238].

Props costdev, domainsupport.
Fixes #54769.

Note: See TracTickets for help on using tickets.