From 956be813b63b225142e50db7fc87cf8d8822b233 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 25 May 2023 12:55:19 +0000 Subject: [PATCH] Coding Standards: Improve formatting of some SQL queries for better readability. This corrects the placement of double quotes around the query and makes sure the alignment is consistent. Props umeshmcakadi, mukesh27, krupalpanchal, dhrumilk, SergeyBiryukov. Fixes #58372. Built from https://develop.svn.wordpress.org/trunk@55857 git-svn-id: http://core.svn.wordpress.org/trunk@55369 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/export.php | 10 ++++------ wp-admin/includes/class-wp-list-table.php | 12 +++++------- wp-admin/includes/post.php | 9 ++++----- wp-includes/class-wp-tax-query.php | 14 +++++++------- wp-includes/class-wp-user-query.php | 3 +-- wp-includes/deprecated.php | 12 ++++-------- wp-includes/general-template.php | 8 ++++---- wp-includes/media.php | 22 ++++++++-------------- wp-includes/user.php | 10 ++++------ wp-includes/version.php | 2 +- 10 files changed, 42 insertions(+), 60 deletions(-) diff --git a/wp-admin/export.php b/wp-admin/export.php index 6e4c335190..7c59c9e6c0 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -141,12 +141,10 @@ function export_date_options( $post_type = 'post' ) { $months = $wpdb->get_results( $wpdb->prepare( - " - SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month - FROM $wpdb->posts - WHERE post_type = %s AND post_status != 'auto-draft' - ORDER BY post_date DESC - ", + "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month + FROM $wpdb->posts + WHERE post_type = %s AND post_status != 'auto-draft' + ORDER BY post_date DESC", $post_type ) ); diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index 9ecbe37487..8fe580bdc7 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -698,13 +698,11 @@ class WP_List_Table { $months = $wpdb->get_results( $wpdb->prepare( - " - SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month - FROM $wpdb->posts - WHERE post_type = %s - $extra_checks - ORDER BY post_date DESC - ", + "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month + FROM $wpdb->posts + WHERE post_type = %s + $extra_checks + ORDER BY post_date DESC", $post_type ) ); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index f11771ec8e..93cd9a7db5 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1010,11 +1010,10 @@ function get_meta_keys() { global $wpdb; $keys = $wpdb->get_col( - " - SELECT meta_key - FROM $wpdb->postmeta - GROUP BY meta_key - ORDER BY meta_key" + "SELECT meta_key + FROM $wpdb->postmeta + GROUP BY meta_key + ORDER BY meta_key" ); return $keys; diff --git a/wp-includes/class-wp-tax-query.php b/wp-includes/class-wp-tax-query.php index afb7dc8db9..b41f1b238e 100644 --- a/wp-includes/class-wp-tax-query.php +++ b/wp-includes/class-wp-tax-query.php @@ -466,13 +466,13 @@ class WP_Tax_Query { $where = $wpdb->prepare( "$operator ( - SELECT 1 - FROM $wpdb->term_relationships - INNER JOIN $wpdb->term_taxonomy - ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id - WHERE $wpdb->term_taxonomy.taxonomy = %s - AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column - )", + SELECT 1 + FROM $wpdb->term_relationships + INNER JOIN $wpdb->term_taxonomy + ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id + WHERE $wpdb->term_taxonomy.taxonomy = %s + AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column + )", $clause['taxonomy'] ); diff --git a/wp-includes/class-wp-user-query.php b/wp-includes/class-wp-user-query.php index 99bdd7fac0..60190ac838 100644 --- a/wp-includes/class-wp-user-query.php +++ b/wp-includes/class-wp-user-query.php @@ -1009,8 +1009,7 @@ class WP_User_Query { FROM $wpdb->posts $where GROUP BY post_author - ) p ON ({$wpdb->users}.ID = p.post_author) - "; + ) p ON ({$wpdb->users}.ID = p.post_author)"; $_orderby = 'post_count'; } elseif ( 'ID' === $orderby || 'id' === $orderby ) { $_orderby = 'ID'; diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 564bbc2a86..ca760ff786 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -4562,22 +4562,18 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) $post_type = esc_sql( $post_type ); $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; $sql = $wpdb->prepare( - " - SELECT ID + "SELECT ID FROM $wpdb->posts WHERE post_title = %s - AND post_type IN ($post_type_in_string) - ", + AND post_type IN ($post_type_in_string)", $page_title ); } else { $sql = $wpdb->prepare( - " - SELECT ID + "SELECT ID FROM $wpdb->posts WHERE post_title = %s - AND post_type = %s - ", + AND post_type = %s", $page_title, $post_type ); diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 9c889d8198..aa37eef12c 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2298,16 +2298,16 @@ function get_calendar( $initial = true, $display = true ) { FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' - ORDER BY post_date DESC - LIMIT 1" + ORDER BY post_date DESC + LIMIT 1" ); $next = $wpdb->get_row( "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = 'post' AND post_status = 'publish' - ORDER BY post_date ASC - LIMIT 1" + ORDER BY post_date ASC + LIMIT 1" ); /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ diff --git a/wp-includes/media.php b/wp-includes/media.php index b7d525555b..b74933881f 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -4484,13 +4484,11 @@ function wp_enqueue_media( $args = array() ) { $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true ); if ( null === $show_audio_playlist ) { $show_audio_playlist = $wpdb->get_var( - " - SELECT ID + "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'audio%' - LIMIT 1 - " + LIMIT 1" ); } @@ -4514,13 +4512,11 @@ function wp_enqueue_media( $args = array() ) { $show_video_playlist = apply_filters( 'media_library_show_video_playlist', true ); if ( null === $show_video_playlist ) { $show_video_playlist = $wpdb->get_var( - " - SELECT ID + "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'video%' - LIMIT 1 - " + LIMIT 1" ); } @@ -4543,12 +4539,10 @@ function wp_enqueue_media( $args = array() ) { if ( ! is_array( $months ) ) { $months = $wpdb->get_results( $wpdb->prepare( - " - SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month - FROM $wpdb->posts - WHERE post_type = %s - ORDER BY post_date DESC - ", + "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month + FROM $wpdb->posts + WHERE post_type = %s + ORDER BY post_date DESC", 'attachment' ) ); diff --git a/wp-includes/user.php b/wp-includes/user.php index 0669a052d0..8453c22a80 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -3545,12 +3545,10 @@ function wp_get_users_with_no_role( $site_id = null ) { $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); $users = $wpdb->get_col( $wpdb->prepare( - " - SELECT user_id - FROM $wpdb->usermeta - WHERE meta_key = '{$prefix}capabilities' - AND meta_value NOT REGEXP %s - ", + "SELECT user_id + FROM $wpdb->usermeta + WHERE meta_key = '{$prefix}capabilities' + AND meta_value NOT REGEXP %s", $regex ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 6098702f73..5e4ebdb16b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55856'; +$wp_version = '6.3-alpha-55857'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.