bb_append_meta

Adds an objects meta data to the object.

Description

bb_append_meta( $object, $type ); 

This is the only function that should add to user / topic - NOT bbdb::prepared

Parameters (2)

0. $object
The object.
1. $type
The type.

Usage

  1. if ( !function_exists( 'bb_append_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-meta.php'; 
  3.  
  4. // The object. 
  5. $object = null; 
  6.  
  7. // The type. 
  8. $type = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_append_meta($object, $type); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-meta.php  
  1. function bb_append_meta( $object, $type ) 
  2. global $bbdb; 
  3. switch ( $type ) { 
  4. case 'user': 
  5. global $wp_users_object; 
  6. return $wp_users_object->append_meta( $object ); 
  7. break; 
  8. case 'forum': 
  9. $object_id_column = 'forum_id'; 
  10. $object_type = 'bb_forum'; 
  11. $slug = 'forum_slug'; 
  12. break; 
  13. case 'topic': 
  14. $object_id_column = 'topic_id'; 
  15. $object_type = 'bb_topic'; 
  16. $slug = 'topic_slug'; 
  17. break; 
  18. case 'post': 
  19. $object_id_column = 'post_id'; 
  20. $object_type = 'bb_post'; 
  21. $slug = false; 
  22. break; 
  23.  
  24. if ( is_array( $object ) && count( $object ) ) { 
  25. $trans = array(); 
  26. foreach ( array_keys( $object ) as $i ) { 
  27. $trans[$object[$i]->$object_id_column] =& $object[$i]; 
  28. $ids = array_map( 'intval', array_keys( $trans ) ); 
  29. $query_ids = array(); 
  30. $cached_objects = array(); 
  31. $position = 0; 
  32. foreach ( $ids as $_id ) { 
  33. if ( false !== $_cached_object = wp_cache_get( $_id, $object_type ) ) { 
  34. $cached_objects[$position] = $_cached_object; 
  35. } else { 
  36. $query_ids[$position] = $_id; 
  37. $position++; 
  38. if ( !count( $query_ids ) ) { 
  39. return $cached_objects; 
  40.  
  41. $_query_ids = $query_ids; 
  42. sort( $_query_ids ); 
  43. $_query_ids = join( ', ', $_query_ids ); 
  44.  
  45. if ( $metas = $bbdb->get_results( "SELECT `object_id`, `meta_key`, `meta_value` FROM `$bbdb->meta` WHERE `object_type` = '$object_type' AND `object_id` IN ($_query_ids) /* bb_append_meta */" ) ) { 
  46. usort( $metas, '_bb_append_meta_sort' ); 
  47. foreach ( $metas as $meta ) { 
  48. $trans[$meta->object_id]->{$meta->meta_key} = maybe_unserialize( $meta->meta_value ); 
  49. if ( strpos($meta->meta_key, $bbdb->prefix) === 0 ) { 
  50. $trans[$meta->object_id]->{substr($meta->meta_key, strlen($bbdb->prefix))} = maybe_unserialize( $meta->meta_value ); 
  51. foreach ( $query_ids as $position => $i ) { 
  52. $cached_objects[$position] = $trans[$i]; 
  53. wp_cache_add( $i, $trans[$i], $object_type ); 
  54. if ( $slug ) { 
  55. wp_cache_add( $trans[$i]->$slug, $i, 'bb_' . $slug ); 
  56. if ( !count( $cached_objects ) ) { 
  57. return $object; 
  58. ksort( $cached_objects ); 
  59.  
  60. return $cached_objects; 
  61. } elseif ( $object ) { 
  62. if ( false !== $cached_object = wp_cache_get( $object->$object_id_column, $object_type ) ) { 
  63. return $cached_object; 
  64. if ( $metas = $bbdb->get_results( $bbdb->prepare( "SELECT `object_id`, `meta_key`, `meta_value` FROM `$bbdb->meta` WHERE `object_type` = '$object_type' AND `object_id` = %d /* bb_append_meta */", $object->$object_id_column ) ) ) { 
  65. usort( $metas, '_bb_append_meta_sort' ); 
  66. foreach ( $metas as $meta ) { 
  67. $object->{$meta->meta_key} = maybe_unserialize( $meta->meta_value ); 
  68. if ( strpos( $meta->meta_key, $bbdb->prefix ) === 0 ) { 
  69. $object->{substr( $meta->meta_key, strlen( $bbdb->prefix ) )} = $object->{$meta->meta_key}; 
  70. if ( $object->$object_id_column ) { 
  71. wp_cache_add( $object->$object_id_column, $object, $object_type ); 
  72. if ( $slug ) { 
  73. wp_cache_add( $object->$slug, $object->$object_id_column, 'bb_' . $slug ); 
  74. return $object;