wp/wp-admin/install-helper.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
--- a/wp/wp-admin/install-helper.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-admin/install-helper.php	Fri Sep 05 18:40:08 2025 +0200
@@ -1,28 +1,30 @@
 <?php
 /**
- * Plugins may load this file to gain access to special helper functions for
- * plugin installation. This file is not included by WordPress and it is
+ * Plugins may load this file to gain access to special helper functions
+ * for plugin installation. This file is not included by WordPress and it is
  * recommended, to prevent fatal errors, that this file is included using
  * require_once.
  *
  * These functions are not optimized for speed, but they should only be used
  * once in a while, so speed shouldn't be a concern. If it is and you are
- * needing to use these functions a lot, you might experience time outs. If you
- * do, then it is advised to just write the SQL code yourself.
+ * needing to use these functions a lot, you might experience timeouts.
+ * If you do, then it is advised to just write the SQL code yourself.
  *
  *     check_column( 'wp_links', 'link_description', 'mediumtext' );
+ *
  *     if ( check_column( $wpdb->comments, 'comment_author', 'tinytext' ) ) {
  *         echo "ok\n";
  *     }
  *
- *     $error_count = 0;
- *     $tablename = $wpdb->links;
  *     // Check the column.
  *     if ( ! check_column( $wpdb->links, 'link_description', 'varchar( 255 )' ) ) {
  *         $ddl = "ALTER TABLE $wpdb->links MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
  *         $q = $wpdb->query( $ddl );
  *     }
  *
+ *     $error_count = 0;
+ *     $tablename   = $wpdb->links;
+ *
  *     if ( check_column( $wpdb->links, 'link_description', 'varchar( 255 )' ) ) {
  *         $res .= $tablename . ' - ok <br />';
  *     } else {
@@ -59,9 +61,10 @@
 		}
 
 		// 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!
+		// We cannot directly tell whether this succeeded!
 		foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
 			if ( $table === $table_name ) {
 				return true;
@@ -88,6 +91,7 @@
 	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 +99,11 @@
 		}
 
 		// 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!
+		// We cannot directly tell 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 +129,16 @@
 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!
+			// We cannot directly tell 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;
@@ -147,16 +156,16 @@
  *
  * Uses the SQL DESC for retrieving the table info for the column. It will help
  * understand the parameters, if you do more research on what column information
- * is returned by the SQL statement. Pass in null to skip checking that
- * criteria.
+ * is returned by the SQL statement. Pass in null to skip checking that criteria.
+ *
+ * Column names returned from DESC table are case sensitive and are as listed:
  *
- * Column names returned from DESC table are case sensitive and are listed:
- *      Field
- *      Type
- *      Null
- *      Key
- *      Default
- *      Extra
+ *  - Field
+ *  - Type
+ *  - Null
+ *  - Key
+ *  - Default
+ *  - Extra
  *
  * @since 1.0.0
  *
@@ -174,7 +183,9 @@
 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 ) {