Skip to content

Commit

Permalink
Coding Standards: Use multi-line strings for the $this->request pro…
Browse files Browse the repository at this point in the history
…perty in `wp-includes/class-wp-*-query.php`.

This further improves the readability by replacing `implode()` calls with string interpolation.

Follow-up to [52973].

Props jrf.
See #54728.
Built from https://develop.svn.wordpress.org/trunk@52977


git-svn-id: http://core.svn.wordpress.org/trunk@52566 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Mar 22, 2022
1 parent 51d4723 commit 6f5f187
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 76 deletions.
19 changes: 8 additions & 11 deletions wp-includes/class-wp-comment-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,17 +961,14 @@ protected function get_comment_ids() {
$this->sql_clauses['orderby'] = $orderby;
$this->sql_clauses['limits'] = $limits;

$this->request = implode(
' ',
array(
$this->sql_clauses['select'],
$this->sql_clauses['from'],
$where,
$this->sql_clauses['groupby'],
$this->sql_clauses['orderby'],
$this->sql_clauses['limits'],
)
);
$this->request = "
{$this->sql_clauses['select']}
{$this->sql_clauses['from']}
{$where}
{$this->sql_clauses['groupby']}
{$this->sql_clauses['orderby']}
{$this->sql_clauses['limits']}
";

if ( $this->query_vars['count'] ) {
return (int) $wpdb->get_var( $this->request );
Expand Down
19 changes: 8 additions & 11 deletions wp-includes/class-wp-network-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,14 @@ protected function get_network_ids() {
$this->sql_clauses['orderby'] = $orderby;
$this->sql_clauses['limits'] = $limits;

$this->request = implode(
' ',
array(
$this->sql_clauses['select'],
$this->sql_clauses['from'],
$where,
$this->sql_clauses['groupby'],
$this->sql_clauses['orderby'],
$this->sql_clauses['limits'],
)
);
$this->request = "
{$this->sql_clauses['select']}
{$this->sql_clauses['from']}
{$where}
{$this->sql_clauses['groupby']}
{$this->sql_clauses['orderby']}
{$this->sql_clauses['limits']}
";

if ( $this->query_vars['count'] ) {
return (int) $wpdb->get_var( $this->request );
Expand Down
38 changes: 16 additions & 22 deletions wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3000,17 +3000,14 @@ public function get_posts() {
$found_rows = 'SQL_CALC_FOUND_ROWS';
}

$old_request = implode(
' ',
array(
"SELECT $found_rows $distinct $fields",
"FROM {$wpdb->posts} $join",
"WHERE 1=1 $where",
$groupby,
$orderby,
$limits,
)
);
$old_request = "
SELECT $found_rows $distinct $fields
FROM {$wpdb->posts} $join
WHERE 1=1 $where
$groupby
$orderby
$limits
";

$this->request = $old_request;

Expand Down Expand Up @@ -3097,17 +3094,14 @@ public function get_posts() {
if ( $split_the_query ) {
// First get the IDs and then fill in the objects.

$this->request = implode(
' ',
array(
"SELECT $found_rows $distinct {$wpdb->posts}.ID",
"FROM {$wpdb->posts} $join",
"WHERE 1=1 $where",
$groupby,
$orderby,
$limits,
)
);
$this->request = "
SELECT $found_rows $distinct {$wpdb->posts}.ID
FROM {$wpdb->posts} $join
WHERE 1=1 $where
$groupby
$orderby
$limits
";

/**
* Filters the Post IDs SQL request before sending.
Expand Down
19 changes: 8 additions & 11 deletions wp-includes/class-wp-site-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,14 @@ protected function get_site_ids() {
$this->sql_clauses['orderby'] = $orderby;
$this->sql_clauses['limits'] = $limits;

$this->request = implode(
' ',
array(
$this->sql_clauses['select'],
$this->sql_clauses['from'],
$where,
$this->sql_clauses['groupby'],
$this->sql_clauses['orderby'],
$this->sql_clauses['limits'],
)
);
$this->request = "
{$this->sql_clauses['select']}
{$this->sql_clauses['from']}
{$where}
{$this->sql_clauses['groupby']}
{$this->sql_clauses['orderby']}
{$this->sql_clauses['limits']}
";

if ( $this->query_vars['count'] ) {
return (int) $wpdb->get_var( $this->request );
Expand Down
17 changes: 7 additions & 10 deletions wp-includes/class-wp-term-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,13 @@ public function get_terms() {
$this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
$this->sql_clauses['limits'] = $limits;

$this->request = implode(
' ',
array(
$this->sql_clauses['select'],
$this->sql_clauses['from'],
$where,
$this->sql_clauses['orderby'],
$this->sql_clauses['limits'],
)
);
$this->request = "
{$this->sql_clauses['select']}
{$this->sql_clauses['from']}
{$where}
{$this->sql_clauses['orderby']}
{$this->sql_clauses['limits']}
";

$this->terms = null;

Expand Down
17 changes: 7 additions & 10 deletions wp-includes/class-wp-user-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,16 +770,13 @@ public function query() {
$this->results = apply_filters_ref_array( 'users_pre_query', array( null, &$this ) );

if ( null === $this->results ) {
$this->request = implode(
' ',
array(
"SELECT {$this->query_fields}",
$this->query_from,
$this->query_where,
$this->query_orderby,
$this->query_limit,
)
);
$this->request = "
SELECT {$this->query_fields}
{$this->query_from}
{$this->query_where}
{$this->query_orderby}
{$this->query_limit}
";

if ( is_array( $qv['fields'] ) || 'all' === $qv['fields'] ) {
$this->results = $wpdb->get_results( $this->request );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52976';
$wp_version = '6.0-alpha-52977';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 6f5f187

Please sign in to comment.