Commit fbb0bb87eb for wordpress.org

commit fbb0bb87ebcad3aaeb46b4ef2b9ec8ee965698a0
Author: westonruter <westonruter@git.wordpress.org>
Date:   Wed Nov 25 19:13:56 2026 +0000

    Code Quality: Resolve the empty.variable PHPStan errors.

    In `WP_Query::parse_search()` the search clause can never be empty after its loop, since at least one search term is always populated before the loop is reached, and in `WP_Query::get_posts()` every queried post type appends a clause to `$status_type_clauses`, so the checks guarding both are removed. In `wp_unique_term_slug()` the loop over parent terms is now a `do`/`while`, because the parent is already known to be non-empty before the first iteration, and the separate check for the end of the ancestry duplicated the loop condition. Behavior is unchanged in all three cases. Removing these empties the baseline, so it is removed.

    The term object passed to `wp_unique_term_slug()` is also documented with an object shape, which requires the `taxonomy` property that PHPStan otherwise reports as undefined on a plain `object`.

    Developed in https://github.com/WordPress/wordpress-develop/pull/16242.
    Follow-up to r51276, r63019.

    Props sunasty, westonruter, mukesh27.
    See #66739.

    Built from https://develop.svn.wordpress.org/trunk@65789


    git-svn-id: http://core.svn.wordpress.org/trunk@64818 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php
index c5e048efe3..5adeac3dd6 100644
--- a/wp-includes/class-wp-query.php
+++ b/wp-includes/class-wp-query.php
@@ -1554,11 +1554,9 @@ class WP_Query {
 			$searchand = ' AND ';
 		}

-		if ( ! empty( $search ) ) {
-			$search = " AND ({$search}) ";
-			if ( ! is_user_logged_in() ) {
-				$search .= " AND ({$wpdb->posts}.post_password = '') ";
-			}
+		$search = " AND ({$search}) ";
+		if ( ! is_user_logged_in() ) {
+			$search .= " AND ({$wpdb->posts}.post_password = '') ";
 		}

 		return $search;
@@ -2784,9 +2782,7 @@ class WP_Query {
 					$status_type_clauses[] = $type_where;
 				}

-				if ( ! empty( $status_type_clauses ) ) {
-					$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
-				}
+				$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
 			} else {
 				$where .= ' AND 1=0 ';
 			}
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
index d888833ecf..06d1d3581d 100644
--- a/wp-includes/taxonomy.php
+++ b/wp-includes/taxonomy.php
@@ -3271,6 +3271,8 @@ function wp_remove_object_terms( $object_id, $terms, $taxonomy ) {
  * @param string $slug The string that will be tried for a unique slug.
  * @param object $term The term object that the `$slug` will belong to.
  * @return string Will return a true unique slug.
+ *
+ * @phpstan-param object{ taxonomy: string, parent?: int, term_id?: int } $term
  */
 function wp_unique_term_slug( $slug, $term ) {
 	global $wpdb;
@@ -3290,7 +3292,7 @@ function wp_unique_term_slug( $slug, $term ) {
 	$parent_suffix = '';
 	if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) {
 		$the_parent = $term->parent;
-		while ( ! empty( $the_parent ) ) {
+		do {
 			$parent_term = get_term( $the_parent, $term->taxonomy );
 			if ( is_wp_error( $parent_term ) || empty( $parent_term ) ) {
 				break;
@@ -3300,11 +3302,8 @@ function wp_unique_term_slug( $slug, $term ) {
 				break;
 			}

-			if ( empty( $parent_term->parent ) ) {
-				break;
-			}
 			$the_parent = $parent_term->parent;
-		}
+		} while ( ! empty( $the_parent ) );
 	}

 	// If we didn't get a unique slug, try appending a number to make it unique.
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 071d31e564..ee10275810 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65788';
+$wp_version = '7.3-alpha-65789';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.