Changeset 18597 for trunk/wp-includes/meta.php
- Timestamp:
- 08/24/2011 07:32:59 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/meta.php
r18500 r18597 74 74 75 75 wp_cache_delete($object_id, $meta_type . '_meta'); 76 // users cache stores usermeta that must be cleared.77 if ( 'user' == $meta_type )78 clean_user_cache($object_id);79 76 80 77 do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); … … 150 147 151 148 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 152 149 153 150 if ( 'post' == $meta_type ) 154 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 151 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 155 152 156 153 $wpdb->update( $table, $data, $where ); 157 154 158 155 wp_cache_delete($object_id, $meta_type . '_meta'); 159 // users cache stores usermeta that must be cleared.160 if ( 'user' == $meta_type )161 clean_user_cache($object_id);162 156 163 157 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 164 158 165 159 if ( 'post' == $meta_type ) 166 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 160 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 167 161 168 162 return true; … … 211 205 $_meta_value = $meta_value; 212 206 $meta_value = maybe_serialize( $meta_value ); 213 207 214 208 $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); 215 209 … … 228 222 229 223 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 230 224 231 225 if ( 'post' == $meta_type ) 232 226 do_action( 'delete_postmeta', $meta_ids ); … … 247 241 } 248 242 249 // users cache stores usermeta that must be cleared.250 if ( 'user' == $meta_type )251 clean_user_cache($object_id);252 253 243 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 254 244 255 245 if ( 'post' == $meta_type ) 256 246 do_action( 'deleted_postmeta', $meta_ids ); … … 311 301 312 302 /** 303 * Determine if a meta key is set for a given object 304 * 305 * @since 3.3.0 306 * 307 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 308 * @param int $object_id ID of the object metadata is for 309 * @param string $meta_key Metadata key. 310 * @return boolean true of the key is set, false if not. 311 */ 312 function metadata_exists( $meta_type, $object_id, $meta_key ) { 313 if ( ! $meta_type ) 314 return false; 315 316 if ( ! $object_id = absint( $object_id ) ) 317 return false; 318 319 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); 320 if ( null !== $check ) 321 return true; 322 323 $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); 324 325 if ( !$meta_cache ) { 326 $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); 327 $meta_cache = $meta_cache[$object_id]; 328 } 329 330 if ( isset( $meta_cache[ $meta_key ] ) ) 331 return true; 332 333 return false; 334 } 335 336 /** 313 337 * Get meta data by meta ID 314 338 * … … 407 431 if ( 'post' == $meta_type ) 408 432 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 409 433 410 434 // Run the update query, all fields in $data are %s, $where is a %d. 411 435 $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' ); … … 413 437 // Clear the caches. 414 438 wp_cache_delete($object_id, $meta_type . '_meta'); 415 416 // Users cache stores usermeta that must be cleared.417 if ( 'user' == $meta_type )418 clean_user_cache($object_id);419 439 420 440 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); … … 425 445 return $result; 426 446 } 427 447 428 448 // And if the meta was not found. 429 449 return false; … … 444 464 function delete_metadata_by_mid( $meta_type, $meta_id ) { 445 465 global $wpdb; 446 466 447 467 // Make sure everything is valid. 448 468 if ( ! $meta_type ) … … 454 474 if ( ! $table = _get_meta_table( $meta_type ) ) 455 475 return false; 456 476 457 477 // object and id columns 458 478 $column = esc_sql($meta_type . '_id'); … … 474 494 wp_cache_delete($object_id, $meta_type . '_meta'); 475 495 476 // Users cache stores usermeta that must be cleared.477 if ( 'user' == $meta_type )478 clean_user_cache($object_id);479 480 496 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 481 497 … … 486 502 487 503 } 488 504 489 505 // Meta id was not found. 490 506 return false; … … 819 835 /** 820 836 * Register meta key 821 * 837 * 822 838 * @since 3.3.0 823 839 *
Note: See TracChangeset
for help on using the changeset viewer.