From cfd09a412765e072b842e3216605c577f667d462 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 19 Nov 2022 15:40:11 +0000 Subject: [PATCH] Coding Standards: Fix WPCS issues in `wp-admin/install-helper.php`. This commit adds inline comments instructing PHPCS to ignore some lines for database queries. An explanation is provided with each instruction. This resolves a few WPCS warnings along the lines of: {{{ Use placeholders and $wpdb->prepare(); found interpolated variable $table_name at "DESC $table_name" }}} Follow-up to [236], [265], [5778]. Props jipmoors, costdev, jrf, SergeyBiryukov. Fixes #43761. git-svn-id: https://develop.svn.wordpress.org/trunk@54858 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/install-helper.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/install-helper.php b/src/wp-admin/install-helper.php index 733321c13e..e07b3d8edd 100644 --- a/src/wp-admin/install-helper.php +++ b/src/wp-admin/install-helper.php @@ -59,6 +59,7 @@ if ( ! function_exists( 'maybe_create_table' ) ) : } // Didn't find it, so try to create it. + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query. $wpdb->query( $create_ddl ); // We cannot directly tell that whether this succeeded! @@ -88,6 +89,7 @@ if ( ! function_exists( 'maybe_add_column' ) ) : function maybe_add_column( $table_name, $column_name, $create_ddl ) { global $wpdb; + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names. foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { return true; @@ -95,9 +97,11 @@ if ( ! function_exists( 'maybe_add_column' ) ) : } // Didn't find it, so try to create it. + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query. $wpdb->query( $create_ddl ); // We cannot directly tell that whether this succeeded! + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names. foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { return true; @@ -123,13 +127,16 @@ endif; function maybe_drop_column( $table_name, $column_name, $drop_ddl ) { global $wpdb; + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names. foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { // Found it, so try to drop it. + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query. $wpdb->query( $drop_ddl ); // We cannot directly tell that whether this succeeded! + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names. foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { return false; @@ -174,7 +181,9 @@ function maybe_drop_column( $table_name, $column_name, $drop_ddl ) { function check_column( $table_name, $col_name, $col_type, $is_null = null, $key = null, $default_value = null, $extra = null ) { global $wpdb; - $diffs = 0; + $diffs = 0; + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names. $results = $wpdb->get_results( "DESC $table_name" ); foreach ( $results as $row ) {