wp/wp-includes/class-wp-meta-query.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/class-wp-meta-query.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/class-wp-meta-query.php	Tue Sep 27 16:37:53 2022 +0200
@@ -99,37 +99,68 @@
 	 *
 	 * @since 3.2.0
 	 * @since 4.2.0 Introduced support for naming query clauses by associative array keys.
-	 * @since 5.1.0 Introduced $compare_key clause parameter, which enables LIKE key matches.
-	 * @since 5.3.0 Increased the number of operators available to $compare_key. Introduced $type_key,
-	 *              which enables the $key to be cast to a new data type for comparisons.
+	 * @since 5.1.0 Introduced `$compare_key` clause parameter, which enables LIKE key matches.
+	 * @since 5.3.0 Increased the number of operators available to `$compare_key`. Introduced `$type_key`,
+	 *              which enables the `$key` to be cast to a new data type for comparisons.
 	 *
 	 * @param array $meta_query {
 	 *     Array of meta query clauses. When first-order clauses or sub-clauses use strings as
 	 *     their array keys, they may be referenced in the 'orderby' parameter of the parent query.
 	 *
-	 *     @type string $relation Optional. The MySQL keyword used to join
-	 *                            the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.
+	 *     @type string $relation Optional. The MySQL keyword used to join the clauses of the query.
+	 *                            Accepts 'AND' or 'OR'. Default 'AND'.
 	 *     @type array  ...$0 {
 	 *         Optional. An array of first-order clause parameters, or another fully-formed meta query.
 	 *
-	 *         @type string $key         Meta key to filter by.
-	 *         @type string $compare_key MySQL operator used for comparing the $key. Accepts '=', '!='
-	 *                                   'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'REGEXP', 'NOT REGEXP', 'RLIKE',
-	 *                                   'EXISTS' (alias of '=') or 'NOT EXISTS' (alias of '!=').
-	 *                                   Default is 'IN' when `$key` is an array, '=' otherwise.
-	 *         @type string $type_key    MySQL data type that the meta_key column will be CAST to for
-	 *                                   comparisons. Accepts 'BINARY' for case-sensitive regular expression
-	 *                                   comparisons. Default is ''.
-	 *         @type string $value       Meta value to filter by.
-	 *         @type string $compare     MySQL operator used for comparing the $value. Accepts '=',
-	 *                                   '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE',
-	 *                                   'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP',
-	 *                                   'NOT REGEXP', 'RLIKE', 'EXISTS' or 'NOT EXISTS'.
-	 *                                   Default is 'IN' when `$value` is an array, '=' otherwise.
-	 *         @type string $type        MySQL data type that the meta_value column will be CAST to for
-	 *                                   comparisons. Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE',
-	 *                                   'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'.
-	 *                                   Default is 'CHAR'.
+	 *         @type string|string[] $key         Meta key or keys to filter by.
+	 *         @type string          $compare_key MySQL operator used for comparing the $key. Accepts:
+	 *                                            - '='
+	 *                                            - '!='
+	 *                                            - 'LIKE'
+	 *                                            - 'NOT LIKE'
+	 *                                            - 'IN'
+	 *                                            - 'NOT IN'
+	 *                                            - 'REGEXP'
+	 *                                            - 'NOT REGEXP'
+	 *                                            - 'RLIKE',
+	 *                                            - 'EXISTS' (alias of '=')
+	 *                                            - 'NOT EXISTS' (alias of '!=')
+	 *                                            Default is 'IN' when `$key` is an array, '=' otherwise.
+	 *         @type string          $type_key    MySQL data type that the meta_key column will be CAST to for
+	 *                                            comparisons. Accepts 'BINARY' for case-sensitive regular expression
+	 *                                            comparisons. Default is ''.
+	 *         @type string|string[] $value       Meta value or values to filter by.
+	 *         @type string          $compare     MySQL operator used for comparing the $value. Accepts:
+	 *                                            - '=',
+	 *                                            - '!='
+	 *                                            - '>'
+	 *                                            - '>='
+	 *                                            - '<'
+	 *                                            - '<='
+	 *                                            - 'LIKE'
+	 *                                            - 'NOT LIKE'
+	 *                                            - 'IN'
+	 *                                            - 'NOT IN'
+	 *                                            - 'BETWEEN'
+	 *                                            - 'NOT BETWEEN'
+	 *                                            - 'REGEXP'
+	 *                                            - 'NOT REGEXP'
+	 *                                            - 'RLIKE'
+	 *                                            - 'EXISTS'
+	 *                                            - 'NOT EXISTS'
+	 *                                            Default is 'IN' when `$value` is an array, '=' otherwise.
+	 *         @type string          $type        MySQL data type that the meta_value column will be CAST to for
+	 *                                            comparisons. Accepts:
+	 *                                            - 'NUMERIC'
+	 *                                            - 'BINARY'
+	 *                                            - 'CHAR'
+	 *                                            - 'DATE'
+	 *                                            - 'DATETIME'
+	 *                                            - 'DECIMAL'
+	 *                                            - 'SIGNED'
+	 *                                            - 'TIME'
+	 *                                            - 'UNSIGNED'
+	 *                                            Default is 'CHAR'.
 	 *     }
 	 * }
 	 */
@@ -307,12 +338,15 @@
 	 *
 	 * @since 3.2.0
 	 *
-	 * @param string $type              Type of meta, eg 'user', 'post'.
+	 * @param string $type              Type of meta. Possible values include but are not limited
+	 *                                  to 'post', 'comment', 'blog', 'term', and 'user'.
 	 * @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.
-	 * @param object $context           Optional. The main query object.
-	 * @return array|false {
-	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
+	 * @param object $context           Optional. The main query object that corresponds to the type, for
+	 *                                  example a `WP_Query`, `WP_User_Query`, or `WP_Site_Query`.
+	 * @return string[]|false {
+	 *     Array containing JOIN and WHERE SQL clauses to append to the main query,
+	 *     or false if no table exists for the requested meta type.
 	 *
 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
 	 *     @type string $where SQL fragment to append to the main WHERE clause.
@@ -347,12 +381,14 @@
 		 *
 		 * @since 3.1.0
 		 *
-		 * @param array  $sql               Array containing the query's JOIN and WHERE clauses.
-		 * @param array  $queries           Array of meta queries.
-		 * @param string $type              Type of meta.
-		 * @param string $primary_table     Primary table.
-		 * @param string $primary_id_column Primary column ID.
-		 * @param object $context           The main query object.
+		 * @param string[] $sql               Array containing the query's JOIN and WHERE clauses.
+		 * @param array    $queries           Array of meta queries.
+		 * @param string   $type              Type of meta. Possible values include but are not limited
+		 *                                    to 'post', 'comment', 'blog', 'term', and 'user'.
+		 * @param string   $primary_table     Primary table.
+		 * @param string   $primary_id_column Primary column ID.
+		 * @param object   $context           The main query object that corresponds to the type, for
+		 *                                    example a `WP_Query`, `WP_User_Query`, or `WP_Site_Query`.
 		 */
 		return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type, $primary_table, $primary_id_column, $context ) );
 	}
@@ -365,7 +401,7 @@
 	 *
 	 * @since 4.1.0
 	 *
-	 * @return array {
+	 * @return string[] {
 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
 	 *
 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
@@ -398,7 +434,7 @@
 	 * @param array $query Query to parse (passed by reference).
 	 * @param int   $depth Optional. Number of tree levels deep we currently are.
 	 *                     Used to calculate indentation. Default 0.
-	 * @return array {
+	 * @return string[] {
 	 *     Array containing JOIN and WHERE SQL clauses to append to a single query array.
 	 *
 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
@@ -484,7 +520,7 @@
 	 * @param array  $parent_query Parent query array.
 	 * @param string $clause_key   Optional. The array key used to name the clause in the original `$meta_query`
 	 *                             parameters. If not provided, a key will be generated automatically.
-	 * @return array {
+	 * @return string[] {
 	 *     Array containing JOIN and WHERE SQL clauses to append to a first-order query.
 	 *
 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
@@ -691,7 +727,7 @@
 				if ( ! is_array( $meta_value ) ) {
 					$meta_value = preg_split( '/[,\s]+/', $meta_value );
 				}
-			} else {
+			} elseif ( is_string( $meta_value ) ) {
 				$meta_value = trim( $meta_value );
 			}
 
@@ -812,7 +848,7 @@
 			$clause_compare  = strtoupper( $clause['compare'] );
 			$sibling_compare = strtoupper( $sibling['compare'] );
 			if ( in_array( $clause_compare, $compatible_compares, true ) && in_array( $sibling_compare, $compatible_compares, true ) ) {
-				$alias = $sibling['alias'];
+				$alias = preg_replace( '/\W/', '_', $sibling['alias'] );
 				break;
 			}
 		}
@@ -825,7 +861,7 @@
 		 * @param string|false  $alias        Table alias, or false if none was found.
 		 * @param array         $clause       First-order query clause.
 		 * @param array         $parent_query Parent of $clause.
-		 * @param WP_Meta_Query $this         WP_Meta_Query object.
+		 * @param WP_Meta_Query $query        WP_Meta_Query object.
 		 */
 		return apply_filters( 'meta_query_find_compatible_table_alias', $alias, $clause, $parent_query, $this );
 	}