Changes from trunk/wp-includes/meta.php at r17170 to branches/3.0/wp-includes/meta.php at r15390
- File:
-
- 1 edited
-
branches/3.0/wp-includes/meta.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/wp-includes/meta.php
r17170 r15390 45 45 // expected_slashed ($meta_key) 46 46 $meta_key = stripslashes($meta_key); 47 $meta_value = stripslashes_deep($meta_value);48 49 $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );50 if ( null !== $check )51 return (bool) $check;52 47 53 48 if ( $unique && $wpdb->get_var( $wpdb->prepare( … … 57 52 58 53 $_meta_value = $meta_value; 59 $meta_value = maybe_serialize( $meta_value ); 60 61 do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); 54 $meta_value = maybe_serialize( stripslashes_deep($meta_value) ); 62 55 63 56 $wpdb->insert( $table, array( … … 113 106 // expected_slashed ($meta_key) 114 107 $meta_key = stripslashes($meta_key); 115 $meta_value = stripslashes_deep($meta_value);116 117 $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );118 if ( null !== $check )119 return (bool) $check;120 108 121 109 if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) ) … … 132 120 133 121 $_meta_value = $meta_value; 134 $meta_value = maybe_serialize( $meta_value);122 $meta_value = maybe_serialize( stripslashes_deep($meta_value) ); 135 123 136 124 $data = compact( 'meta_value' ); … … 189 177 // expected_slashed ($meta_key) 190 178 $meta_key = stripslashes($meta_key); 191 $meta_value = stripslashes_deep($meta_value); 192 193 $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all ); 194 if ( null !== $check ) 195 return (bool) $check; 196 197 $_meta_value = $meta_value; 198 $meta_value = maybe_serialize( $meta_value ); 179 $meta_value = maybe_serialize( stripslashes_deep($meta_value) ); 199 180 200 181 $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); … … 209 190 if ( !count( $meta_ids ) ) 210 191 return false; 211 212 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );213 192 214 193 $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; … … 224 203 clean_user_cache($object_id); 225 204 226 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $ _meta_value );205 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $meta_value ); 227 206 228 207 return true; … … 249 228 return false; 250 229 251 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );252 if ( null !== $check ) {253 if ( $single && is_array( $check ) )254 return $check[0];255 else256 return $check;257 }258 259 230 $meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); 260 231 261 232 if ( !$meta_cache ) { 262 $meta_cache = update_meta_cache( $meta_type, array( $object_id ));263 $meta_cache = $meta_cache[$object_id];264 } 265 266 if ( ! $meta_key )233 update_meta_cache($meta_type, $object_id); 234 $meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); 235 } 236 237 if ( ! $meta_key ) 267 238 return $meta_cache; 268 239 … … 310 281 $cache_key = $meta_type . '_meta'; 311 282 $ids = array(); 312 $cache = array();313 283 foreach ( $object_ids as $id ) { 314 $cached_object = wp_cache_get( $id, $cache_key ); 315 if ( false === $cached_object ) 284 if ( false === wp_cache_get($id, $cache_key) ) 316 285 $ids[] = $id; 317 else318 $cache[$id] = $cached_object;319 286 } 320 287 321 288 if ( empty( $ids ) ) 322 return $cache;289 return false; 323 290 324 291 // Get meta info 325 292 $id_list = join(',', $ids); 293 $cache = array(); 326 294 $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)", 327 295 $meta_type), ARRAY_A ); … … 347 315 if ( ! isset($cache[$id]) ) 348 316 $cache[$id] = array(); 349 wp_cache_add( $id, $cache[$id], $cache_key ); 350 } 317 } 318 319 foreach ( array_keys($cache) as $object) 320 wp_cache_set($object, $cache[$object], $cache_key); 351 321 352 322 return $cache; … … 354 324 355 325 /** 356 * Given a meta query, generates SQL clauses to be appended to a main query357 *358 * @since 3.1.0359 * @access private360 *361 * @param array $meta_query List of metadata queries. A single query is an associative array:362 * - 'key' string The meta key363 * - 'value' string|array The meta value364 * - 'compare' (optional) string How to compare the key to the value.365 * Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.366 * Default: '='367 * - 'type' string (optional) The type of the value.368 * Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.369 * Default: 'CHAR'370 *371 * @param string $meta_type372 * @param string $primary_table373 * @param string $primary_id_column374 * @param object $context (optional) The main query object375 * @return array( 'join' => $join_sql, 'where' => $where_sql )376 */377 function _get_meta_sql( $meta_query, $meta_type, $primary_table, $primary_id_column, $context = null ) {378 global $wpdb;379 380 if ( ! $meta_table = _get_meta_table( $meta_type ) )381 return false;382 383 $meta_id_column = esc_sql( $meta_type . '_id' );384 385 $join = '';386 $where = '';387 $i = 0;388 foreach ( $meta_query as $q ) {389 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';390 $meta_value = isset( $q['value'] ) ? $q['value'] : '';391 $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';392 $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';393 394 if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )395 $meta_compare = '=';396 397 if ( 'NUMERIC' == $meta_type )398 $meta_type = 'SIGNED';399 elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )400 $meta_type = 'CHAR';401 402 if ( empty( $meta_key ) && empty( $meta_value ) )403 continue;404 405 $alias = $i ? 'mt' . $i : $meta_table;406 407 $join .= "\nINNER JOIN $meta_table";408 $join .= $i ? " AS $alias" : '';409 $join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";410 411 $i++;412 413 if ( !empty( $meta_key ) )414 $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );415 416 if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {417 if ( ! is_array( $meta_value ) )418 $meta_value = preg_split( '/[,\s]+/', $meta_value );419 } else {420 $meta_value = trim( $meta_value );421 }422 423 if ( empty( $meta_value ) )424 continue;425 426 if ( 'IN' == substr( $meta_compare, -2) ) {427 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';428 } elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {429 $meta_value = array_slice( $meta_value, 0, 2 );430 $meta_compare_string = '%s AND %s';431 } elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {432 $meta_value = '%' . like_escape( $meta_value ) . '%';433 $meta_compare_string = '%s';434 } else {435 $meta_compare_string = '%s';436 }437 438 // @todo Temporary hack to support empty values. Do not use outside of core.439 if ( '_wp_zero_value' == $meta_value )440 $meta_value = 0;441 442 $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );443 }444 445 return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $meta_query, $meta_type, $primary_table, $primary_id_column, &$context ) );446 }447 448 /**449 * Populates the $meta_query property450 *451 * @access private452 * @since 3.1.0453 *454 * @param array $qv The query variables455 */456 function _parse_meta_query( &$qv ) {457 $meta_query = array();458 459 // Simple query needs to be first for orderby=meta_value to work correctly460 foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {461 if ( !empty( $qv[ "meta_$key" ] ) )462 $meta_query[0][ $key ] = $qv[ "meta_$key" ];463 }464 465 if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {466 $meta_query = array_merge( $meta_query, $qv['meta_query'] );467 }468 469 $qv['meta_query'] = $meta_query;470 }471 472 /**473 326 * Retrieve the name of the metadata table for the specified object type. 474 327 * … … 476 329 * @uses $wpdb WordPress database object for queries. 477 330 * 478 * @param string $ type Type of object to get metadata table for (e.g., comment, post, or user)331 * @param string $meta_type Type of object to get metadata table for (e.g., comment, post, or user) 479 332 * @return mixed Metadata table name, or false if no metadata table exists 480 333 */
Note: See TracChangeset
for help on using the changeset viewer.