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
This commit is contained in:
Sergey Biryukov 2023-05-25 12:55:19 +00:00
parent d8c4000c53
commit 956be813b6
10 changed files with 42 additions and 60 deletions

View File

@ -141,12 +141,10 @@ function export_date_options( $post_type = 'post' ) {
$months = $wpdb->get_results( $months = $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
" "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts
FROM $wpdb->posts WHERE post_type = %s AND post_status != 'auto-draft'
WHERE post_type = %s AND post_status != 'auto-draft' ORDER BY post_date DESC",
ORDER BY post_date DESC
",
$post_type $post_type
) )
); );

View File

@ -698,13 +698,11 @@ class WP_List_Table {
$months = $wpdb->get_results( $months = $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
" "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts
FROM $wpdb->posts WHERE post_type = %s
WHERE post_type = %s $extra_checks
$extra_checks ORDER BY post_date DESC",
ORDER BY post_date DESC
",
$post_type $post_type
) )
); );

View File

@ -1010,11 +1010,10 @@ function get_meta_keys() {
global $wpdb; global $wpdb;
$keys = $wpdb->get_col( $keys = $wpdb->get_col(
" "SELECT meta_key
SELECT meta_key FROM $wpdb->postmeta
FROM $wpdb->postmeta GROUP BY meta_key
GROUP BY meta_key ORDER BY meta_key"
ORDER BY meta_key"
); );
return $keys; return $keys;

View File

@ -466,13 +466,13 @@ class WP_Tax_Query {
$where = $wpdb->prepare( $where = $wpdb->prepare(
"$operator ( "$operator (
SELECT 1 SELECT 1
FROM $wpdb->term_relationships FROM $wpdb->term_relationships
INNER JOIN $wpdb->term_taxonomy INNER JOIN $wpdb->term_taxonomy
ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id
WHERE $wpdb->term_taxonomy.taxonomy = %s WHERE $wpdb->term_taxonomy.taxonomy = %s
AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column
)", )",
$clause['taxonomy'] $clause['taxonomy']
); );

View File

@ -1009,8 +1009,7 @@ class WP_User_Query {
FROM $wpdb->posts FROM $wpdb->posts
$where $where
GROUP BY post_author GROUP BY post_author
) p ON ({$wpdb->users}.ID = p.post_author) ) p ON ({$wpdb->users}.ID = p.post_author)";
";
$_orderby = 'post_count'; $_orderby = 'post_count';
} elseif ( 'ID' === $orderby || 'id' === $orderby ) { } elseif ( 'ID' === $orderby || 'id' === $orderby ) {
$_orderby = 'ID'; $_orderby = 'ID';

View File

@ -4562,22 +4562,18 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' )
$post_type = esc_sql( $post_type ); $post_type = esc_sql( $post_type );
$post_type_in_string = "'" . implode( "','", $post_type ) . "'"; $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
$sql = $wpdb->prepare( $sql = $wpdb->prepare(
" "SELECT ID
SELECT ID
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_title = %s WHERE post_title = %s
AND post_type IN ($post_type_in_string) AND post_type IN ($post_type_in_string)",
",
$page_title $page_title
); );
} else { } else {
$sql = $wpdb->prepare( $sql = $wpdb->prepare(
" "SELECT ID
SELECT ID
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_title = %s WHERE post_title = %s
AND post_type = %s AND post_type = %s",
",
$page_title, $page_title,
$post_type $post_type
); );

View File

@ -2298,16 +2298,16 @@ function get_calendar( $initial = true, $display = true ) {
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_date < '$thisyear-$thismonth-01' WHERE post_date < '$thisyear-$thismonth-01'
AND post_type = 'post' AND post_status = 'publish' AND post_type = 'post' AND post_status = 'publish'
ORDER BY post_date DESC ORDER BY post_date DESC
LIMIT 1" LIMIT 1"
); );
$next = $wpdb->get_row( $next = $wpdb->get_row(
"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
AND post_type = 'post' AND post_status = 'publish' AND post_type = 'post' AND post_status = 'publish'
ORDER BY post_date ASC ORDER BY post_date ASC
LIMIT 1" LIMIT 1"
); );
/* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */

View File

@ -4484,13 +4484,11 @@ function wp_enqueue_media( $args = array() ) {
$show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true ); $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true );
if ( null === $show_audio_playlist ) { if ( null === $show_audio_playlist ) {
$show_audio_playlist = $wpdb->get_var( $show_audio_playlist = $wpdb->get_var(
" "SELECT ID
SELECT ID
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_type = 'attachment' WHERE post_type = 'attachment'
AND post_mime_type LIKE 'audio%' 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 ); $show_video_playlist = apply_filters( 'media_library_show_video_playlist', true );
if ( null === $show_video_playlist ) { if ( null === $show_video_playlist ) {
$show_video_playlist = $wpdb->get_var( $show_video_playlist = $wpdb->get_var(
" "SELECT ID
SELECT ID
FROM $wpdb->posts FROM $wpdb->posts
WHERE post_type = 'attachment' WHERE post_type = 'attachment'
AND post_mime_type LIKE 'video%' AND post_mime_type LIKE 'video%'
LIMIT 1 LIMIT 1"
"
); );
} }
@ -4543,12 +4539,10 @@ function wp_enqueue_media( $args = array() ) {
if ( ! is_array( $months ) ) { if ( ! is_array( $months ) ) {
$months = $wpdb->get_results( $months = $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
" "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts
FROM $wpdb->posts WHERE post_type = %s
WHERE post_type = %s ORDER BY post_date DESC",
ORDER BY post_date DESC
",
'attachment' 'attachment'
) )
); );

View File

@ -3545,12 +3545,10 @@ function wp_get_users_with_no_role( $site_id = null ) {
$regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
$users = $wpdb->get_col( $users = $wpdb->get_col(
$wpdb->prepare( $wpdb->prepare(
" "SELECT user_id
SELECT user_id FROM $wpdb->usermeta
FROM $wpdb->usermeta WHERE meta_key = '{$prefix}capabilities'
WHERE meta_key = '{$prefix}capabilities' AND meta_value NOT REGEXP %s",
AND meta_value NOT REGEXP %s
",
$regex $regex
) )
); );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.