wp/wp-includes/class-wp-tax-query.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/class-wp-tax-query.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/class-wp-tax-query.php	Mon Oct 14 18:28:13 2019 +0200
@@ -43,11 +43,12 @@
 	 * Standard response when the query should not return any rows.
 	 *
 	 * @since 3.2.0
-	 *
-	 * @static
 	 * @var string
 	 */
-	private static $no_results = array( 'join' => array( '' ), 'where' => array( '0 = 1' ) );
+	private static $no_results = array(
+		'join'  => array( '' ),
+		'where' => array( '0 = 1' ),
+	);
 
 	/**
 	 * A flat list of table aliases used in the JOIN clauses.
@@ -135,10 +136,10 @@
 		$cleaned_query = array();
 
 		$defaults = array(
-			'taxonomy' => '',
-			'terms' => array(),
-			'field' => 'term_id',
-			'operator' => 'IN',
+			'taxonomy'         => '',
+			'terms'            => array(),
+			'field'            => 'term_id',
+			'operator'         => 'IN',
 			'include_children' => true,
 		);
 
@@ -146,12 +147,12 @@
 			if ( 'relation' === $key ) {
 				$cleaned_query['relation'] = $this->sanitize_relation( $query );
 
-			// First-order clause.
+				// First-order clause.
 			} elseif ( self::is_first_order_clause( $query ) ) {
 
-				$cleaned_clause = array_merge( $defaults, $query );
+				$cleaned_clause          = array_merge( $defaults, $query );
 				$cleaned_clause['terms'] = (array) $cleaned_clause['terms'];
-				$cleaned_query[] = $cleaned_clause;
+				$cleaned_query[]         = $cleaned_clause;
 
 				/*
 				 * Keep a copy of the clause in the flate
@@ -176,7 +177,7 @@
 					}
 				}
 
-			// Otherwise, it's a nested query, so we recurse.
+				// Otherwise, it's a nested query, so we recurse.
 			} elseif ( is_array( $query ) ) {
 				$cleaned_subquery = $this->sanitize_query( $query );
 
@@ -221,8 +222,6 @@
 	 *
 	 * @since 4.1.0
 	 *
-	 * @static
-	 *
 	 * @param array $query Tax query arguments.
 	 * @return bool Whether the query clause is a first-order clause.
 	 */
@@ -235,8 +234,6 @@
 	 *
 	 * @since 3.1.0
 	 *
-	 * @static
-	 *
 	 * @param string $primary_table     Database table where the object being filtered is stored (eg wp_users).
 	 * @param string $primary_id_column ID column for the filtered object in $primary_table.
 	 * @return array {
@@ -247,7 +244,7 @@
 	 * }
 	 */
 	public function get_sql( $primary_table, $primary_id_column ) {
-		$this->primary_table = $primary_table;
+		$this->primary_table     = $primary_table;
 		$this->primary_id_column = $primary_id_column;
 
 		return $this->get_sql_clauses();
@@ -274,7 +271,7 @@
 		 * To keep $this->queries unaltered, pass a copy.
 		 */
 		$queries = $this->queries;
-		$sql = $this->get_sql_for_query( $queries );
+		$sql     = $this->get_sql_for_query( $queries );
 
 		if ( ! empty( $sql['where'] ) ) {
 			$sql['where'] = ' AND ' . $sql['where'];
@@ -314,7 +311,7 @@
 
 		$indent = '';
 		for ( $i = 0; $i < $depth; $i++ ) {
-			$indent .= "  ";
+			$indent .= '  ';
 		}
 
 		foreach ( $query as $key => &$clause ) {
@@ -336,7 +333,7 @@
 					}
 
 					$sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] );
-				// This is a subquery, so we recurse.
+					// This is a subquery, so we recurse.
 				} else {
 					$clause_sql = $this->get_sql_for_query( $clause, $depth + 1 );
 
@@ -399,7 +396,7 @@
 			return self::$no_results;
 		}
 
-		$terms = $clause['terms'];
+		$terms    = $clause['terms'];
 		$operator = strtoupper( $clause['operator'] );
 
 		if ( 'IN' == $operator ) {
@@ -416,7 +413,7 @@
 			 */
 			$alias = $this->find_compatible_table_alias( $clause, $parent_query );
 			if ( false === $alias ) {
-				$i = count( $this->table_aliases );
+				$i     = count( $this->table_aliases );
 				$alias = $i ? 'tt' . $i : $wpdb->term_relationships;
 
 				// Store the alias as part of a flat array to build future iterators.
@@ -430,7 +427,6 @@
 				$join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)";
 			}
 
-
 			$where = "$alias.term_taxonomy_id $operator ($terms)";
 
 		} elseif ( 'NOT IN' == $operator ) {
@@ -466,14 +462,17 @@
 
 		} elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) {
 
-			$where = $wpdb->prepare( "$operator (
+			$where = $wpdb->prepare(
+				"$operator (
 				SELECT 1
 				FROM $wpdb->term_relationships
 				INNER JOIN $wpdb->term_taxonomy
 				ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id
 				WHERE $wpdb->term_taxonomy.taxonomy = %s
 				AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column
-			)", $clause['taxonomy'] );
+			)",
+				$clause['taxonomy']
+			);
 
 		}
 
@@ -561,12 +560,13 @@
 		if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
 			$this->transform_query( $query, 'term_id' );
 
-			if ( is_wp_error( $query ) )
+			if ( is_wp_error( $query ) ) {
 				return;
+			}
 
 			$children = array();
 			foreach ( $query['terms'] as $term ) {
-				$children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );
+				$children   = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );
 				$children[] = $term;
 			}
 			$query['terms'] = $children;
@@ -590,11 +590,13 @@
 	 *                                or 'term_id'. Default 'term_id'.
 	 */
 	public function transform_query( &$query, $resulting_field ) {
-		if ( empty( $query['terms'] ) )
+		if ( empty( $query['terms'] ) ) {
 			return;
+		}
 
-		if ( $query['field'] == $resulting_field )
+		if ( $query['field'] == $resulting_field ) {
 			return;
+		}
 
 		$resulting_field = sanitize_key( $resulting_field );