Jetpack_Sync_Module_Meta

The WordPress Core Jetpack Sync Module Meta class.

Defined (1)

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

/sync/class.jetpack-sync-module-meta.php  
  1. class Jetpack_Sync_Module_Meta extends Jetpack_Sync_Module { 
  2.  
  3. public function name() { 
  4. return 'meta'; 
  5.  
  6. /** 
  7. * This implementation of get_objects_by_id() is a bit hacky since we're not passing in an array of meta IDs,  
  8. * but instead an array of post or comment IDs for which to retrieve meta for. On top of that,  
  9. * we also pass in an associative array where we expect there to be 'meta_key' and 'ids' keys present. 
  10. * This seemed to be required since if we have missing meta on WP.com and need to fetch it, we don't know what 
  11. * the meta key is, but we do know that we have missing meta for a given post or comment. 
  12. * @param string $object_type The type of object for which we retrieve meta. Either 'post' or 'comment' 
  13. * @param array $config Must include 'meta_key' and 'ids' keys 
  14. * @return array 
  15. */ 
  16. public function get_objects_by_id( $object_type, $config ) { 
  17. global $wpdb; 
  18.  
  19. $table = _get_meta_table( $object_type ); 
  20.  
  21. if ( ! $table ) { 
  22. return array(); 
  23.  
  24. if ( ! isset( $config['meta_key'] ) || ! isset( $config['ids'] ) || ! is_array( $config['ids'] ) ) { 
  25. return array(); 
  26.  
  27. $meta_key = $config['meta_key']; 
  28. $ids = $config['ids']; 
  29. $object_id_column = $object_type.'_id'; 
  30.  
  31. // Sanitize so that the array only has integer values 
  32. $ids_string = implode( ', ', array_map( 'intval', $ids ) ); 
  33. $metas = $wpdb->get_results( 
  34. $wpdb->prepare( 
  35. "SELECT * FROM {$table} WHERE {$object_id_column} IN ( {$ids_string} ) AND meta_key = %s",  
  36. $meta_key 
  37. ); 
  38.  
  39. $meta_objects = array(); 
  40. foreach( (array) $metas as $meta_object ) { 
  41. $meta_object = (array) $meta_object; 
  42. $meta_objects[ $meta_object[ $object_id_column ] ] = array( 
  43. 'meta_type' => $object_type,  
  44. 'meta_id' => $meta_object['meta_id'],  
  45. 'meta_key' => $meta_key,  
  46. 'meta_value' => $meta_object['meta_value'],  
  47. 'object_id' => $meta_object[ $object_id_column ],  
  48. ); 
  49.  
  50. return $meta_objects;