Ticket #35658: 35658.17.diff
File 35658.17.diff, 44.8 KB (added by , 8 years ago) |
---|
-
www/wp-includes/class-wp-object-type.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
1 <?php 2 3 /** 4 * Class WP_Object_Type 5 * 6 * Object Type is an infrastructure class used to classify fields and forms with 7 * other potential classification use cases in the future. 8 * 9 * Registered fields are often intended to be for specific post types and as such 10 * post types need to be specified. However, Fields should not be specific to 11 * post types as fields would be beneficial for users, comments, options, and more. 12 * 13 * So the Object Type was designed to capture and allow developers to specify both 14 * the $type_group of object (i.e. 'post', 'user', 'comment', etc.) as well as the 15 * $subtype specific to the type, (i.e. 'post', 'page', 'attachment', etc. for 16 * Object Types of $class 'post.') 17 * 18 * Object Types literals are specified in string form with a colon separating $class 19 * from $subtype, which looks like this: 20 * 21 * 'post:post' 22 * 'post:page' 23 * 'post:attachment' 24 * 'post:my_post_type' 25 * 26 * Object can be comparied with $object_type where is_object($object_type) is 27 * true (because of the Object Type's __toString() method.): 28 * 29 * $object_type = new WP_Object_Type( 'post:my_post_type' ); 30 * 31 * if ( 'post:my_post_type' == $object_type ) { 32 * echo 'They *are* equal!' 33 * } 34 * 35 * The 'any' subtype will match any item of the specified type group, and if subtype 36 * is ommitted then it implies 'any'. All of these are equivalent: 37 * 38 * 'post:any' 39 * 'post:' 40 * 'post' 41 * 42 * All of these groups of three are equivalent: 43 * 44 * 'term' 45 * 'term:' 46 * 'term:any' 47 * 48 * 'user' 49 * 'user:' 50 * 'user:any' 51 * 52 * 'comment' 53 * 'comment:' 54 * 'comment:any' 55 * 56 */ 57 final class WP_Object_Type { 58 59 /** 60 * The $_type property is used to contain the type group of object 61 * such as 'post', 'user', 'comment', 'option', etc. 62 * 63 * @var null|string 64 */ 65 private $_type_group = null; 66 67 /** 68 * The $_subtype property is to contain the 'type' relevant to the Object Type's 69 * $_type, i.e. for 'post' there is 'post', 'page', 'attachment' and whatever 70 * custom post types have been defined. 71 * 72 * For $_type values of 'user' we are currently assuming role will used for $_subtype. 73 * 74 * For all other $_type values the value of $_subtype is TBD. 75 * 76 * @var null|string[] 77 */ 78 private $_subtype = null; 79 80 /** 81 * The $_as_string property will contain the string representation of the Object Type 82 * 83 * @var null|string[] 84 */ 85 private $_as_string = null; 86 87 /** 88 * List of valid Object Type Names 89 * 90 * @var string[] 91 */ 92 private static $_object_type_names = array( 93 'post', 94 'term', 95 'user', 96 'ccomment', 97 ); 98 99 /** 100 * List of Object Types to be dispensed by get_instance() 101 * 102 * @var self[] 103 */ 104 private static $_object_types = array(); 105 106 /** 107 * Returns an immutable instance of WP_Object_Type, reusing when object types match 108 * 109 * @example: 110 * 111 * $object_type = WP_Object_Type()::get_instance( 'post:my_post_type' ); 112 * $object_type2 = WP_Object_Type()::get_instance( $object_type ); 113 * $object_type3 = WP_Object_Type()::get_instance( 'post:my_post_type' ); 114 * 115 * echo $object_type === $object_type2 // true 116 * echo $object_type === $object_type3 // true 117 * 118 * @param WP_Object_Type|object|array|string $object_type 119 * @return WP_Object_Type 120 * 121 */ 122 static function get_instance( $object_type ) { 123 124 do { 125 if ( $object_type instanceof WP_Object_Type ) { 126 break; 127 } 128 129 if ( is_string( $object_type ) && isset( self::$_object_types[ $object_type ] ) ) { 130 $object_type = self::$_object_types[ $object_type ]; 131 break; 132 } 133 134 list( $type, $subtype ) = self::parse_object_type( $object_type ); 135 136 $as_string = self::_as_string( $type, $subtype ); 137 138 if ( ! isset( self::$_object_types[ $as_string ] ) ) { 139 140 $object_type = new WP_Object_Type(); 141 142 $object_type->_type = $type; 143 $object_type->_subtype = $subtypes; 144 $object_type->_as_string = $as_string; 145 146 self::$_object_types[ $as_string ] = $object_type; 147 148 } 149 150 $object_type = self::$_object_types[ $as_string ]; 151 152 } while ( false ); 153 154 return $object_type; 155 156 } 157 158 /** 159 * Parses an $object_type include and returns a 2 element array 160 * 161 * @example: 162 * 163 * $result = WP_Object_Type::parse( 'post:my_type1' ) 164 * echo count( $result ); // 2 165 * echo $result[1]; // post 166 * echo $result[2]; // my_type3 167 * 168 * @param string|WP_Object_Type $object_type 169 * @return string[] 170 * 171 */ 172 static function parse_object_type( $object_type ) { 173 174 do { 175 176 if ( empty( $object_type ) ) { 177 178 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Empty parameter \$object_type' ) ), '4.6.0' ); 179 180 $result = array( null, null ); 181 182 break; 183 184 } 185 186 if ( is_a( $object_type, __CLASS__ ) ) { 187 188 /** 189 * If a WP_Object_Type object was passed in then copy it's values. 190 * 191 * @see The PHPDoc for __construct() to understand why accepting an 192 * object in addition to a string literal is useful. 193 */ 194 $result = array( $object_type->_type_group, $object_type->_subtype ); 195 196 break; 197 198 } 199 200 if ( is_string( $object_type ) ) { 201 202 203 /** 204 * Otherwise split the Object Type literal on a colon and assign 205 * to $class and $subtypes, respectively. 206 */ 207 list( $type, $subtypes ) = array_map( 'trim', explode( ':', "{$object_type}:" ) ); 208 209 $result = array( $type, $subtypes ); 210 211 break; 212 213 } 214 215 if ( is_array( $object_type ) && 2 === count( $object_type ) && isset( $object_type[0] ) && isset( $object_type[1] ) ) { 216 217 /** 218 * A 2 element numerically indexed array where the first element is 219 * $class and the 2nd is $subtype. So assign it. 220 */ 221 222 $result = $object_type; 223 224 break; 225 226 } 227 228 if ( ! in_array( $result[ 0 ], self::$_object_types ) ) { 229 230 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid "type" %s for \$object_type.' ), $result[ 0 ] ), '4.6.0' ); 231 232 break; 233 234 } 235 236 if ( 'post' === $result[ 0 ] ) { 237 238 global $wp_post_types; 239 if ( ! in_array( $result[ 1 ], $wp_post_types ) ) { 240 241 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid post type: %s.' ), $result[ 1 ] ), '4.6.0' ); 242 $result[ 1 ] = false; 243 244 } 245 break; 246 } 247 248 if ( 'term' === $result[ 0 ] ) { 249 250 global $wp_taxonomies; 251 if ( ! in_array( $result[ 1 ], $wp_taxonomies ) ) { 252 253 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $result[ 1 ] ), '4.6.0' ); 254 $result[ 1 ] = false; 255 256 } 257 break; 258 } 259 260 if ( ! $result[ 1 ] ) { 261 262 /** 263 * Default to 'any'. 264 */ 265 $result[ 1 ] = array( 'any' ); 266 267 } 268 269 } while ( false ); 270 271 272 return $result; 273 274 } 275 276 /** 277 * Method to access type property 278 * 279 * @return string 280 */ 281 function type_group() { 282 283 return $this->_type_group; 284 285 } 286 287 288 /** 289 * Method to access $this->_subtype property 290 * 291 * @return array 292 */ 293 function subtype() { 294 295 return $this->_subtype; 296 297 } 298 299 /** 300 * Return the post_type for a post 301 * 302 * @return array 303 */ 304 function post_type() { 305 306 return 'post' === $this->_type_group ? $this->_subtype : null; 307 308 } 309 310 /** 311 * Return the taxonomy for a term 312 * 313 * @return array 314 */ 315 function taxonomy() { 316 317 return 'term' === $this->_type_group ? $this->_subtype : null; 318 319 } 320 321 322 /** 323 * Method to extract ab Object Type to an array. 324 * 325 * @return array 326 */ 327 function to_array() { 328 329 return array( $this->_type_group, $this->_subtype ); 330 331 } 332 333 /** 334 * @return string[] 335 */ 336 static function object_type_names() { 337 338 return self::$_object_type_names; 339 340 } 341 342 /** 343 * @return bool 344 */ 345 function is_post_type_group() { 346 347 return 'post' === $this->_type_group; 348 349 } 350 351 /** 352 * @return bool 353 */ 354 function is_term_type_group() { 355 356 return 'term' === $this->_type_group; 357 358 } 359 360 /** 361 * @return bool 362 */ 363 function is_user_type_group() { 364 365 return 'user' === $this->_type_group; 366 367 } 368 369 /** 370 * @return bool 371 */ 372 function is_comment_type_group() { 373 374 return 'comment' === $this->_type_group; 375 376 } 377 378 /** 379 * Check if the current Object Type is valid. 380 * 381 * Validity is determined by having a non-empty $type_group value. 382 * 383 * @return bool Is the Object Type valid? 384 */ 385 function is_valid() { 386 387 return ! empty( $this->_type_group ); 388 389 } 390 391 /** 392 * Check if the current Object Type is equivalent to the one passed in. 393 * 394 * Equivalency is true if both objects have the same values for their $_type and $_subtype properties. 395 * 396 * If not parameter is passed then this method assume an object type based on the global $post object. 397 * 398 * @param WP_Object_Type|string| $object_type The Object Type to compare with $this. 399 * 400 * @return bool If $object_type is equivalent to $this. 401 */ 402 function is_equivalent( $object_type ) { 403 404 if ( ! is_a( $object_type, __CLASS__ ) ) { 405 /* 406 * First check to see if the passed in parameter is a WP_Object_Type object. 407 * If not, instantiate a new object with the passed $arg. 408 */ 409 $object_type = self::get_instance( $object_type ); 410 411 } 412 413 /** 414 * Check for object equivalency 415 * Yes this is correct (if you thought it was not, like I did at first.) 416 */ 417 return $this->_as_string === (string) $object_type; 418 419 } 420 421 /** 422 * Magic method to convert the Object Type into it's string literal form. 423 * 424 * @return string An Object Type literal representing $this, the current Object Type. 425 */ 426 function __toString() { 427 428 return $this->_as_string; 429 430 } 431 432 /** 433 * @param string $type 434 * @param string $subtype 435 * 436 * @return string 437 */ 438 private static function _as_string( $type, $subtype ) { 439 return "{$type}:{$subtype}"; 440 441 } 442 443 } -
www/wp-includes/meta.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
17 17 * 18 18 * @global wpdb $wpdb WordPress database abstraction object. 19 19 * 20 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)20 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 21 21 * @param int $object_id ID of the object metadata is for 22 22 * @param string $meta_key Metadata key 23 23 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. … … 27 27 * no change will be made. 28 28 * @return int|false The meta ID on success, false on failure. 29 29 */ 30 function add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique = false) {30 function add_metadata( $object_type, $object_id, $meta_key, $meta_value, $unique = false ) { 31 31 global $wpdb; 32 32 33 if ( ! $ meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {33 if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) ) { 34 34 return false; 35 35 } 36 36 … … 39 39 return false; 40 40 } 41 41 42 $object_type = WP_Object_Type::get_instance( $object_type ); 43 44 $meta_type = $object_type->type_group(); 45 42 46 $table = _get_meta_table( $meta_type ); 43 47 if ( ! $table ) { 44 48 return false; … … 49 53 // expected_slashed ($meta_key) 50 54 $meta_key = wp_unslash($meta_key); 51 55 $meta_value = wp_unslash($meta_value); 52 $meta_value = sanitize_meta( $meta_key, $meta_value, $ meta_type );56 $meta_value = sanitize_meta( $meta_key, $meta_value, $object_type ); 53 57 54 58 /** 55 59 * Filters whether to add metadata of a specific type. … … 66 70 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 67 71 * @param bool $unique Whether the specified meta key should be unique 68 72 * for the object. Optional. Default false. 73 * @param WP_Object_Type $object_type Type and subtype of object 69 74 */ 70 $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );75 $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique, $object_type ); 71 76 if ( null !== $check ) 72 77 return $check; 73 78 … … 90 95 * @param int $object_id Object ID. 91 96 * @param string $meta_key Meta key. 92 97 * @param mixed $meta_value Meta value. 98 * @param WP_Object_Type $object_type Type and subtype of object 93 99 */ 94 do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );100 do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value, $object_type ); 95 101 96 102 $result = $wpdb->insert( $table, array( 97 103 $column => $object_id, … … 118 124 * @param int $object_id Object ID. 119 125 * @param string $meta_key Meta key. 120 126 * @param mixed $meta_value Meta value. 127 * @param WP_Object_Type $object_type Type and subtype of object 121 128 */ 122 do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );129 do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value, $object_type ); 123 130 124 131 return $mid; 125 132 } … … 132 139 * 133 140 * @global wpdb $wpdb WordPress database abstraction object. 134 141 * 135 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)142 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 136 143 * @param int $object_id ID of the object metadata is for 137 144 * @param string $meta_key Metadata key 138 145 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. … … 140 147 * the specified value. Otherwise, update all entries. 141 148 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 142 149 */ 143 function update_metadata( $meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') {150 function update_metadata( $object_type, $object_id, $meta_key, $meta_value, $prev_value = '' ) { 144 151 global $wpdb; 145 152 146 if ( ! $ meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {153 if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) ) { 147 154 return false; 148 155 } 149 156 … … 152 159 return false; 153 160 } 154 161 162 $object_type = WP_Object_Type::get_instance( $object_type ); 163 164 $meta_type = $object_type->type_group(); 165 155 166 $table = _get_meta_table( $meta_type ); 156 167 if ( ! $table ) { 157 168 return false; … … 165 176 $meta_key = wp_unslash($meta_key); 166 177 $passed_value = $meta_value; 167 178 $meta_value = wp_unslash($meta_value); 168 $meta_value = sanitize_meta( $meta_key, $meta_value, $ meta_type );179 $meta_value = sanitize_meta( $meta_key, $meta_value, $object_type ); 169 180 170 181 /** 171 182 * Filters whether to update metadata of a specific type. … … 183 194 * @param mixed $prev_value Optional. If specified, only update existing 184 195 * metadata entries with the specified value. 185 196 * Otherwise, update all entries. 197 * @param WP_Object_Type $object_type Type and subtype of object 186 198 */ 187 $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );199 $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value, $object_type ); 188 200 if ( null !== $check ) 189 201 return (bool) $check; 190 202 … … 226 238 * @param int $object_id Object ID. 227 239 * @param string $meta_key Meta key. 228 240 * @param mixed $meta_value Meta value. 241 * @param WP_Object_Type $object_type Type and subtype of object 229 242 */ 230 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );243 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type ); 231 244 232 245 if ( 'post' == $meta_type ) { 233 246 /** … … 239 252 * @param int $object_id Object ID. 240 253 * @param string $meta_key Meta key. 241 254 * @param mixed $meta_value Meta value. 255 * @param WP_Object_Type $object_type Type and subtype of object 242 256 */ 243 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );257 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type ); 244 258 } 245 259 } 246 260 … … 263 277 * @param int $object_id Object ID. 264 278 * @param string $meta_key Meta key. 265 279 * @param mixed $meta_value Meta value. 280 * @param WP_Object_Type $object_type Type and subtype of object 266 281 */ 267 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );282 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type ); 268 283 269 284 if ( 'post' == $meta_type ) { 270 285 /** … … 276 291 * @param int $object_id Object ID. 277 292 * @param string $meta_key Meta key. 278 293 * @param mixed $meta_value Meta value. 294 * @param WP_Object_Type $object_type Type and subtype of object 279 295 */ 280 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );296 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type ); 281 297 } 282 298 } 283 299 … … 291 307 * 292 308 * @global wpdb $wpdb WordPress database abstraction object. 293 309 * 294 * @param string $meta_typeType of object metadata is for (e.g., comment, post, or user)310 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 295 311 * @param int $object_id ID of the object metadata is for 296 312 * @param string $meta_key Metadata key 297 313 * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete … … 304 320 * the specified object_id. 305 321 * @return bool True on successful delete, false on failure. 306 322 */ 307 function delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) {323 function delete_metadata( $object_type, $object_id, $meta_key, $meta_value = '', $delete_all = false ) { 308 324 global $wpdb; 309 325 310 if ( ! $ meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) {326 if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) { 311 327 return false; 312 328 } 313 329 … … 316 332 return false; 317 333 } 318 334 335 $object_type = WP_Object_Type::get_instance( $object_type ); 336 337 $meta_type = $object_type->type_group(); 338 319 339 $table = _get_meta_table( $meta_type ); 320 340 if ( ! $table ) { 321 341 return false; … … 343 363 * @param bool $delete_all Whether to delete the matching metadata entries 344 364 * for all objects, ignoring the specified $object_id. 345 365 * Default false. 366 * @param WP_Object_Type $object_type Type and subtype of object 346 367 */ 347 $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );368 $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all, $object_type ); 348 369 if ( null !== $check ) 349 370 return (bool) $check; 350 371 … … 384 405 * @param int $object_id Object ID. 385 406 * @param string $meta_key Meta key. 386 407 * @param mixed $meta_value Meta value. 408 * @param WP_Object_Type $object_type Type and subtype of object 387 409 */ 388 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );410 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value, $object_type ); 389 411 390 412 // Old-style action. 391 413 if ( 'post' == $meta_type ) { … … 395 417 * @since 2.9.0 396 418 * 397 419 * @param array $meta_ids An array of post metadata entry IDs to delete. 420 * @param WP_Object_Type $object_type Type and subtype of object 398 421 */ 399 do_action( 'delete_postmeta', $meta_ids );422 do_action( 'delete_postmeta', $meta_ids, $object_type ); 400 423 } 401 424 402 425 $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; … … 426 449 * @param int $object_id Object ID. 427 450 * @param string $meta_key Meta key. 428 451 * @param mixed $meta_value Meta value. 452 * @param WP_Object_Type $object_type Type and subtype of object 429 453 */ 430 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );454 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value, $object_type ); 431 455 432 456 // Old-style action. 433 457 if ( 'post' == $meta_type ) { … … 437 461 * @since 2.9.0 438 462 * 439 463 * @param array $meta_ids An array of deleted post metadata entry IDs. 464 * @param WP_Object_Type $object_type Type and subtype of object 440 465 */ 441 do_action( 'deleted_postmeta', $meta_ids );466 do_action( 'deleted_postmeta', $meta_ids, $object_type ); 442 467 } 443 468 444 469 return true; … … 449 474 * 450 475 * @since 2.9.0 451 476 * 452 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)477 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 453 478 * @param int $object_id ID of the object metadata is for 454 479 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 455 480 * the specified object. … … 458 483 * This parameter has no effect if meta_key is not specified. 459 484 * @return mixed Single metadata value, or array of values 460 485 */ 461 function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { 462 if ( ! $meta_type || ! is_numeric( $object_id ) ) { 486 function get_metadata( $object_type, $object_id, $meta_key = '', $single = false ) { 487 488 if ( ! $object_type || ! is_numeric( $object_id ) ) { 463 489 return false; 464 490 } 465 491 … … 468 494 return false; 469 495 } 470 496 497 $object_type = WP_Object_Type::get_instance( $object_type ); 498 499 $meta_type = $object_type->type_group(); 500 471 501 /** 472 502 * Filters whether to retrieve metadata of a specific type. 473 503 * … … 482 512 * @param int $object_id Object ID. 483 513 * @param string $meta_key Meta key. 484 514 * @param bool $single Whether to return only the first value of the specified $meta_key. 515 * @param WP_Object_Type $object_type Type and subtype of object 485 516 */ 486 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );517 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $object_type ); 487 518 if ( null !== $check ) { 488 519 if ( $single && is_array( $check ) ) 489 520 return $check[0]; … … 520 551 * 521 552 * @since 3.3.0 522 553 * 523 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)554 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 524 555 * @param int $object_id ID of the object metadata is for 525 556 * @param string $meta_key Metadata key. 526 557 * @return bool True of the key is set, false if not. 527 558 */ 528 function metadata_exists( $ meta_type, $object_id, $meta_key ) {529 if ( ! $ meta_type || ! is_numeric( $object_id ) ) {559 function metadata_exists( $object_type, $object_id, $meta_key ) { 560 if ( ! $object_type || ! is_numeric( $object_id ) ) { 530 561 return false; 531 562 } 532 563 … … 535 566 return false; 536 567 } 537 568 569 $object_type = WP_Object_Type::get_instance( $object_type ); 570 571 $meta_type = $object_type->type_group(); 572 538 573 /** This filter is documented in wp-includes/meta.php */ 539 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );574 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true , $object_type); 540 575 if ( null !== $check ) 541 576 return (bool) $check; 542 577 … … 560 595 * 561 596 * @global wpdb $wpdb WordPress database abstraction object. 562 597 * 563 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).598 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 564 599 * @param int $meta_id ID for a specific meta row 565 600 * @return object|false Meta object or false. 566 601 */ 567 function get_metadata_by_mid( $ meta_type, $meta_id ) {602 function get_metadata_by_mid( $object_type, $meta_id ) { 568 603 global $wpdb; 569 604 570 if ( ! $ meta_type || ! is_numeric( $meta_id ) ) {605 if ( ! $object_type || ! is_numeric( $meta_id ) ) { 571 606 return false; 572 607 } 573 608 … … 576 611 return false; 577 612 } 578 613 614 $object_type = WP_Object_Type::get_instance( $object_type ); 615 616 $meta_type = $object_type->type_group(); 617 579 618 $table = _get_meta_table( $meta_type ); 580 619 if ( ! $table ) { 581 620 return false; … … 601 640 * 602 641 * @global wpdb $wpdb WordPress database abstraction object. 603 642 * 604 * @param string $meta_typeType of object metadata is for (e.g., comment, post, or user)643 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 605 644 * @param int $meta_id ID for a specific meta row 606 645 * @param string $meta_value Metadata value 607 * @param string $meta_key Optional, you can provide a meta key to update it646 * @param string|bool $meta_key Optional, you can provide a meta key to update it 608 647 * @return bool True on successful update, false on failure. 609 648 */ 610 function update_metadata_by_mid( $ meta_type, $meta_id, $meta_value, $meta_key = false ) {649 function update_metadata_by_mid( $object_type, $meta_id, $meta_value, $meta_key = false ) { 611 650 global $wpdb; 612 651 613 652 // Make sure everything is valid. 614 if ( ! $ meta_type || ! is_numeric( $meta_id ) ) {653 if ( ! $object_type || ! is_numeric( $meta_id ) ) { 615 654 return false; 616 655 } 617 656 … … 620 659 return false; 621 660 } 622 661 662 $object_type = WP_Object_Type::get_instance( $object_type ); 663 664 $meta_type = $object_type->type_group(); 665 623 666 $table = _get_meta_table( $meta_type ); 624 667 if ( ! $table ) { 625 668 return false; … … 643 686 644 687 // Sanitize the meta 645 688 $_meta_value = $meta_value; 646 $meta_value = sanitize_meta( $meta_key, $meta_value, $ meta_type );689 $meta_value = sanitize_meta( $meta_key, $meta_value, $object_type ); 647 690 $meta_value = maybe_serialize( $meta_value ); 648 691 649 692 // Format the data query arguments. … … 657 700 $where[$id_column] = $meta_id; 658 701 659 702 /** This action is documented in wp-includes/meta.php */ 660 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );703 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type ); 661 704 662 705 if ( 'post' == $meta_type ) { 663 706 /** This action is documented in wp-includes/meta.php */ 664 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );707 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type ); 665 708 } 666 709 667 710 // Run the update query, all fields in $data are %s, $where is a %d. … … 673 716 wp_cache_delete($object_id, $meta_type . '_meta'); 674 717 675 718 /** This action is documented in wp-includes/meta.php */ 676 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );719 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type ); 677 720 678 721 if ( 'post' == $meta_type ) { 679 722 /** This action is documented in wp-includes/meta.php */ 680 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );723 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type ); 681 724 } 682 725 683 726 return true; … … 694 737 * 695 738 * @global wpdb $wpdb WordPress database abstraction object. 696 739 * 697 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).740 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 698 741 * @param int $meta_id ID for a specific meta row 699 742 * @return bool True on successful delete, false on failure. 700 743 */ 701 function delete_metadata_by_mid( $ meta_type, $meta_id ) {744 function delete_metadata_by_mid( $object_type, $meta_id ) { 702 745 global $wpdb; 703 746 704 747 // Make sure everything is valid. 705 if ( ! $ meta_type || ! is_numeric( $meta_id ) ) {748 if ( ! $object_type || ! is_numeric( $meta_id ) ) { 706 749 return false; 707 750 } 708 751 … … 711 754 return false; 712 755 } 713 756 757 $object_type = WP_Object_Type::get_instance( $object_type ); 758 759 $meta_type = $object_type->type_group(); 760 714 761 $table = _get_meta_table( $meta_type ); 715 762 if ( ! $table ) { 716 763 return false; … … 725 772 $object_id = $meta->{$column}; 726 773 727 774 /** This action is documented in wp-includes/meta.php */ 728 do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );775 do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value, $object_type ); 729 776 730 777 // Old-style action. 731 778 if ( 'post' == $meta_type || 'comment' == $meta_type ) { … … 738 785 * @since 3.4.0 739 786 * 740 787 * @param int $meta_id ID of the metadata entry to delete. 788 * @param WP_Object_Type $object_type Type and subtype of object 741 789 */ 742 do_action( "delete_{$meta_type}meta", $meta_id );790 do_action( "delete_{$meta_type}meta", $meta_id, $object_type ); 743 791 } 744 792 745 793 // Run the query, will return true if deleted, false otherwise … … 749 797 wp_cache_delete($object_id, $meta_type . '_meta'); 750 798 751 799 /** This action is documented in wp-includes/meta.php */ 752 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );800 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value, $object_type ); 753 801 754 802 // Old-style action. 755 803 if ( 'post' == $meta_type || 'comment' == $meta_type ) { … … 762 810 * @since 3.4.0 763 811 * 764 812 * @param int $meta_ids Deleted metadata entry ID. 813 * @param WP_Object_Type $object_type Type and subtype of object 765 814 */ 766 do_action( "deleted_{$meta_type}meta", $meta_id );815 do_action( "deleted_{$meta_type}meta", $meta_id, $object_type ); 767 816 } 768 817 769 818 return $result; … … 781 830 * 782 831 * @global wpdb $wpdb WordPress database abstraction object. 783 832 * 784 * @param string $meta_typeType of object metadata is for (e.g., comment, post, or user)833 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 785 834 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for 786 835 * @return array|false Metadata cache for the specified objects, or false on failure. 787 836 */ 788 function update_meta_cache( $meta_type, $object_ids) {837 function update_meta_cache( $object_type, $object_ids) { 789 838 global $wpdb; 790 839 791 if ( ! $ meta_type || ! $object_ids ) {840 if ( ! $object_type || ! $object_ids ) { 792 841 return false; 793 842 } 794 843 844 $object_type = WP_Object_Type::get_instance( $object_type ); 845 846 $meta_type = $object_type->type_group(); 847 795 848 $table = _get_meta_table( $meta_type ); 796 849 if ( ! $table ) { 797 850 return false; … … 876 929 * @see WP_Meta_Query 877 930 * 878 931 * @param array $meta_query A meta query. 879 * @param string $type Type of meta.932 * @param string $type_group Type of meta: 'post', 'term', 'user', 'comment' 880 933 * @param string $primary_table Primary database table name. 881 934 * @param string $primary_id_column Primary ID column name. 882 935 * @param object $context Optional. The main query object 883 936 * @return array Associative array of `JOIN` and `WHERE` SQL. 884 937 */ 885 function get_meta_sql( $meta_query, $type , $primary_table, $primary_id_column, $context = null ) {938 function get_meta_sql( $meta_query, $type_group, $primary_table, $primary_id_column, $context = null ) { 886 939 $meta_query_obj = new WP_Meta_Query( $meta_query ); 887 return $meta_query_obj->get_sql( $type , $primary_table, $primary_id_column, $context );940 return $meta_query_obj->get_sql( $type_group, $primary_table, $primary_id_column, $context ); 888 941 } 889 942 890 943 /** … … 894 947 * 895 948 * @global wpdb $wpdb WordPress database abstraction object. 896 949 * 897 * @param string $type Type of object to get metadata tablefor (e.g., comment, post, or user)950 * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user) 898 951 * @return string|false Metadata table name, or false if no metadata table exists 899 952 */ 900 function _get_meta_table( $type) {953 function _get_meta_table( $object_type ) { 901 954 global $wpdb; 902 955 903 $ table_name = $type . 'meta';956 $object_type = WP_Object_Type::get_instance( $object_type ); 904 957 958 $table_name = $object_type->type_group() . 'meta'; 959 905 960 if ( empty($wpdb->$table_name) ) 906 961 return false; 907 962 … … 914 969 * @since 3.1.3 915 970 * 916 971 * @param string $meta_key Meta key 917 * @param string|null $meta_type972 * @param WP_Object_Type|string|null $object_type Type of object metadata is for (e.g., comment, post, or user) 918 973 * @return bool True if the key is protected, false otherwise. 919 974 */ 920 function is_protected_meta( $meta_key, $ meta_type = null ) {975 function is_protected_meta( $meta_key, $object_type = null ) { 921 976 $protected = ( '_' == $meta_key[0] ); 922 977 923 978 /** … … 929 984 * @param string $meta_key Meta key. 930 985 * @param string $meta_type Meta type. 931 986 */ 932 return apply_filters( 'is_protected_meta', $protected, $meta_key, $ meta_type );987 return apply_filters( 'is_protected_meta', $protected, $meta_key, $object_type->type_group(), $object_type ); 933 988 } 934 989 935 990 /** 936 991 * Sanitize meta value. 937 992 * 938 993 * @since 3.1.3 994 * @since 4.6.0 Added the `$object_subtype` parameter. 939 995 * 940 * @param string $meta_key Meta key 941 * @param mixed $meta_value Meta value to sanitize 942 * @param string $meta_type Type of meta 943 * @return mixed Sanitized $meta_value 996 * @param string $meta_key Meta key. 997 * @param mixed $meta_value Meta value to sanitize. 998 * @param WP_Object_Type|string $object_type Type of object the meta is registered to. 999 * 1000 * @return mixed Sanitized $meta_value. 944 1001 */ 945 function sanitize_meta( $meta_key, $meta_value, $ meta_type ) {1002 function sanitize_meta( $meta_key, $meta_value, $object_type ) { 946 1003 1004 $object_type = WP_Object_Type::get_instance( $object_type ); 1005 1006 $type_group = $object_type->type_group(); 1007 947 1008 /** 948 1009 * Filters the sanitization of a specific meta key of a specific meta type. 949 1010 * … … 958 1019 * @param string $meta_key Meta key. 959 1020 * @param string $meta_type Meta type. 960 1021 */ 961 return apply_filters( "sanitize_{$ meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type );1022 return apply_filters( "sanitize_{$type_group}_meta_{$meta_key}", $meta_value, $meta_key, $object_type ); 962 1023 } 963 1024 964 1025 /** 965 * Register meta key1026 * Registers a meta key. 966 1027 * 967 1028 * @since 3.3.0 1029 * @since 4.6.0 Modified to support an array of data to attach to registered meta keys. Previous arguments for 1030 * `$sanitize_callback` and `$auth_callback` have been folded into this array. 968 1031 * 969 * @param string $meta_type Type of meta 970 * @param string $meta_key Meta key 971 * @param string|array $sanitize_callback A function or method to call when sanitizing the value of $meta_key. 972 * @param string|array $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. 1032 * @param WP_Object_Type|string $object_type Type of object the meta is registered to. 1033 * @param string $meta_key Meta key to register. 1034 * @param array $args { 1035 * Data used to describe the meta key when registered. 1036 * 1037 * @type string $sanitize_callback A function or method to call when sanitizing `$meta_key` data. 1038 * @type string $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. 1039 * @type string $type_group The type of data associated with this meta key. 1040 * @type string $description A description of the data attached to this meta key. 1041 * @type bool $show_in_rest Whether data associated with this meta key can be considered public. 1042 * } 973 1043 */ 974 function register_meta( $meta_type, $meta_key, $sanitize_callback, $auth_callback = null ) { 975 if ( is_callable( $sanitize_callback ) ) 976 add_filter( "sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3 ); 1044 function register_meta( $object_type, $meta_key, $args ) { 1045 global $wp_meta_keys; 977 1046 978 if ( empty( $auth_callback ) ) { 979 if ( is_protected_meta( $meta_key, $meta_type ) ) 980 $auth_callback = '__return_false'; 981 else 982 $auth_callback = '__return_true'; 1047 if ( ! is_array( $wp_meta_keys ) ) { 1048 $wp_meta_keys = array(); 983 1049 } 984 1050 985 if ( is_callable( $auth_callback ) ) 986 add_filter( "auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6 ); 1051 $meta_args = (object) array( 1052 'sanitize_callback' => null, 1053 'old_sanitize_callback' => null, 1054 'auth_callback' => null, 1055 'old_auth_callback' => null, 1056 'type' => 'string', 1057 'description' => '', 1058 'show_in_rest' => false, 1059 ); 1060 1061 $passed_args = array_slice( func_get_args(), 2 ); 1062 1063 if ( is_callable( $passed_args[0] ) ) { 1064 $meta_args->old_sanitize_callback = $passed_args[0]; 1065 } elseif ( isset( $passed_args[0]['sanitize_callback'] ) ) { 1066 $meta_args->sanitize_callback = $passed_args[0]['sanitize_callback']; 1067 } 1068 1069 if ( isset( $passed_args[1] ) && is_callable( $passed_args[1] ) ) { 1070 $meta_args->old_auth_callback = $passed_args[1]; 1071 } elseif ( isset( $passed_args[0]['auth_callback'] ) ) { 1072 $meta_args->auth_callback = $passed_args[0]['auth_callback']; 1073 } 1074 1075 if ( isset( $passed_args[0]['show_in_rest'] ) && $passed_args[0]['show_in_rest'] ) { 1076 $meta_args->show_in_rest = true; 1077 } 1078 1079 if ( isset( $passed_args[0]['type'] ) ) { 1080 $meta_args->type = $passed_args[0]['type']; 1081 } 1082 1083 if ( isset( $passed_args[0]['description'] ) ) { 1084 $meta_args->description = $passed_args[0]['description']; 1085 } 1086 1087 $object_type = WP_Object_Type::get_instance( $object_type ); 1088 1089 $wp_meta_keys[ $type_group = $object_type->type_group() ][ $object_type->post_type() ][ $meta_key ] = $args; 1090 1091 if ( is_callable( $meta_args->old_sanitize_callback ) ) { 1092 add_filter( "sanitize_{$type_group}_meta_{$meta_key}", $meta_args->old_sanitize_callback, 10, 3 ); 1093 } 1094 1095 if ( is_callable( $meta_args->sanitize_callback ) ) { 1096 add_filter( "sanitize_{$type_group}_meta_{$meta_key}", $meta_args->sanitize_callback, 10, 3 ); 1097 } 1098 1099 // If neither new or legacy `auth_callback` is provided, fallback to `is_protected_meta()`. 1100 if ( empty( $meta_args->auth_callback ) && empty( $meta_args->old_auth_callback ) ) { 1101 if ( is_protected_meta( $meta_key, $object_type ) ) { 1102 $meta_args->auth_callback = '__return_false'; 1103 } else { 1104 $meta_args->auth_callback = '__return_true'; 1105 } 1106 } 1107 1108 // The auth here is currently used to edit or add meta, not to view, and only for posts. 1109 if ( 'post' === $type_group && is_callable( $meta_args->old_auth_callback ) ) { 1110 add_filter( "auth_{$type_group}_meta_{$meta_key}", $meta_args->old_auth_callback, 10, 6 ); 1111 } 1112 1113 if ( 'post' === $type_group && is_callable( $meta_args->auth_callback ) ) { 1114 add_filter( "auth_{$type_group}_meta_{$meta_key}", $meta_args->auth_callback, 10, 6 ); 1115 } 1116 } 1117 1118 /** 1119 * Checks if a meta key is registered. 1120 * 1121 * @since 4.6.0 1122 * 1123 * @param WP_Object_Type|string $object_type Type of object the meta is registered to. 1124 * @param string $meta_key 1125 * 1126 * @return bool True if the meta key is registered to the object type and subtype. False if not. 1127 */ 1128 function registered_meta_key_exists( $object_type, $meta_key ) { 1129 global $wp_meta_keys; 1130 1131 if ( ! is_array( $wp_meta_keys ) ) { 1132 return false; 1133 } 1134 1135 $object_type = WP_Object_Type::get_instance( $object_type ); 1136 1137 if ( ! isset( $wp_meta_keys[ $type_group = $object_type->type_group() ] ) ) { 1138 return false; 1139 } 1140 1141 if ( ! isset( $wp_meta_keys[ $type_group ][ $post_type = $object_type->post_type() ] ) ) { 1142 return false; 1143 } 1144 1145 if ( isset( $wp_meta_keys[ $type_group ][ $post_type ][ $meta_key ] ) ) { 1146 return true; 1147 } 1148 1149 return false; 1150 } 1151 1152 /** 1153 * Unregisters a meta key from the list of registered keys. 1154 * 1155 * @since 4.6.0 1156 * 1157 * @param WP_Object_Type|string $object_type Type of object the meta is registered to. 1158 * @param string $meta_key The meta key. 1159 * 1160 * @return bool|WP_Error True if successful. WP_Error if the meta key is invalid. 1161 */ 1162 function unregister_meta_key( $object_type, $meta_key ) { 1163 global $wp_meta_keys; 1164 1165 if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) { 1166 return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key' ) ); 1167 } 1168 1169 $object_type = WP_Object_Type::get_instance( $object_type ); 1170 1171 unset( $wp_meta_keys[ $object_type->type_group() ][ $object_type->post_type() ][ $meta_key ] ); 1172 1173 return true; 1174 } 1175 1176 /** 1177 * Retrieves a list of registered meta keys for an object type and subtype. 1178 * 1179 * @since 4.6.0 1180 * 1181 * @param WP_Object_Type|string $object_type Type of object the meta is registered to. 1182 * 1183 * @return array List of registered meta keys. 1184 */ 1185 function get_registered_meta_keys( $object_type ) { 1186 global $wp_meta_keys; 1187 1188 $object_type = WP_Object_Type::get_instance( $object_type ); 1189 1190 if ( ! isset( $wp_meta_keys[ $type_group = $object_type->type_group() ] ) ) { 1191 return array(); 1192 } 1193 1194 if ( ! isset( $wp_meta_keys[ $type_group ][ $post_type = $object_type->post_type() ] ) ) { 1195 return array(); 1196 } 1197 1198 return $wp_meta_keys[ $type_group ][ $post_type ]; 1199 } 1200 1201 /** 1202 * Retrieves registered metadata for a specified object. 1203 * 1204 * @since 4.6.0 1205 * 1206 * @param WP_Object_Type|string $object_type Type of object to request metadata for. (e.g. comment, post, term, user) 1207 * @param int $object_id ID of the object the metadata is for. 1208 * @param string $meta_key Optional. Registered metadata key. If not specified, retrieve all registered 1209 * metadata for the specified object. 1210 * 1211 * @return mixed|WP_Error 1212 */ 1213 function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) { 1214 global $wp_meta_keys; 1215 1216 if ( ! is_array( $wp_meta_keys ) ) { 1217 return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) ); 1218 } 1219 1220 $type_subtype = WP_Object_Type::parse_object_type( $object_type ); 1221 1222 if ( 'post' === $type_subtype[ 0 ] ) { 1223 $type_subtype[ 1 ] = array( get_post_type( $object_id ) ); 1224 } 1225 1226 $object_type = WP_Object_Type::get_instance( $type_subtype ); 1227 1228 if( ! empty( $meta_key ) ) { 1229 if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) { 1230 return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) ); 1231 } 1232 $meta_keys = get_registered_meta_keys( $object_type ); 1233 $meta_key_data = $meta_keys[ $object_type->type_group() ][ $object_type->post_type() ][ $meta_key ]; 1234 1235 $data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data->single ); 1236 1237 return $data; 1238 } 1239 1240 $data = get_metadata( $object_type->type_group(), $object_id, $meta_key ); 1241 1242 $meta_keys = get_registered_meta_keys( $object_type ); 1243 1244 $registered_data = array(); 1245 1246 foreach( $meta_keys as $k => $v ) { 1247 if ( isset( $data[ $k ] ) ) { 1248 $registered_data[ $k ] = $data[ $k ]; 1249 } 1250 } 1251 1252 return $registered_data; 987 1253 } -
www/wp-includes/class-wp-meta-query.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
311 311 * @since 3.2.0 312 312 * @access public 313 313 * 314 * @param string $type 314 * @param string $type_group Type of meta, eg 'user', 'post'. 315 315 * @param string $primary_table Database table where the object being filtered is stored (eg wp_users). 316 316 * @param string $primary_id_column ID column for the filtered object in $primary_table. 317 317 * @param object $context Optional. The main query object. … … 322 322 * @type string $where SQL fragment to append to the main WHERE clause. 323 323 * } 324 324 */ 325 public function get_sql( $type , $primary_table, $primary_id_column, $context = null ) {326 if ( ! $meta_table = _get_meta_table( $type ) ) {325 public function get_sql( $type_group, $primary_table, $primary_id_column, $context = null ) { 326 if ( ! $meta_table = _get_meta_table( $type_group ) ) { 327 327 return false; 328 328 } 329 329 330 330 $this->table_aliases = array(); 331 331 332 332 $this->meta_table = $meta_table; 333 $this->meta_id_column = sanitize_key( $type . '_id' );333 $this->meta_id_column = sanitize_key( $type_group . '_id' ); 334 334 335 335 $this->primary_table = $primary_table; 336 336 $this->primary_id_column = $primary_id_column; … … 352 352 * 353 353 * @param array $clauses Array containing the query's JOIN and WHERE clauses. 354 354 * @param array $queries Array of meta queries. 355 * @param string $type Type of meta.355 * @param string $type_group Type of meta. 356 356 * @param string $primary_table Primary table. 357 357 * @param string $primary_id_column Primary column ID. 358 358 * @param object $context The main query object. 359 359 */ 360 return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type , $primary_table, $primary_id_column, $context ) );360 return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type_group, $primary_table, $primary_id_column, $context ) ); 361 361 } 362 362 363 363 /**