From 50bb23e860da86cd67e4f1d388767314bf09ea21 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 25 Mar 2025 18:34:48 +0000 Subject: [PATCH] Coding Standards: Remove a one-time `$sql` variable in `WP_Importer` methods. This allows the `$wpdb::prepare()` calls to be picked up correctly by PHPCS. Follow-up to [14760]. Props aristath, poena, afercia, SergeyBiryukov. See #63168. git-svn-id: https://develop.svn.wordpress.org/trunk@60094 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-importer.php | 28 +++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/includes/class-wp-importer.php b/src/wp-admin/includes/class-wp-importer.php index 8edef7dba5..8489919f8a 100644 --- a/src/wp-admin/includes/class-wp-importer.php +++ b/src/wp-admin/includes/class-wp-importer.php @@ -29,8 +29,14 @@ class WP_Importer { // Grab all posts in chunks. do { $meta_key = $importer_name . '_' . $blog_id . '_permalink'; - $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit ); - $results = $wpdb->get_results( $sql ); + $results = $wpdb->get_results( + $wpdb->prepare( + "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", + $meta_key, + $offset, + $limit + ) + ); // Increment offset. $offset = ( $limit + $offset ); @@ -62,9 +68,12 @@ class WP_Importer { // Get count of permalinks. $meta_key = $importer_name . '_' . $blog_id . '_permalink'; - $sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key ); - - $result = $wpdb->get_results( $sql ); + $result = $wpdb->get_results( + $wpdb->prepare( + "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = %s", + $meta_key + ) + ); if ( ! empty( $result ) ) { $count = (int) $result[0]->cnt; @@ -91,8 +100,13 @@ class WP_Importer { // Grab all comments in chunks. do { - $sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit ); - $results = $wpdb->get_results( $sql ); + $results = $wpdb->get_results( + $wpdb->prepare( + "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", + $offset, + $limit + ) + ); // Increment offset. $offset = ( $limit + $offset );