/** * @group bp_notifications_update_meta_cache */ public function test_bp_notifications_update_meta_cache() { $u = $this->factory->user->create(); $n1 = $this->factory->notification->create(array('component_name' => 'messages', 'user_id' => $u)); $n2 = $this->factory->notification->create(array('component_name' => 'groups', 'user_id' => $u)); // Add cache for each notification. bp_notifications_update_meta($n1, 'meta', 'data'); bp_notifications_update_meta($n1, 'data', 'meta'); bp_notifications_update_meta($n2, 'meta', 'human'); // Prime cache. bp_notifications_get_meta($n1, 'meta'); // Ensure an empty cache for second notification. wp_cache_delete($n2, 'notification_meta'); // Update notification meta cache. bp_notifications_update_meta_cache(array($n1, $n2)); $expected = array($n1 => array('meta' => array('data'), 'data' => array('meta')), $n2 => array('meta' => array('human'))); $found = array($n1 => wp_cache_get($n1, 'notification_meta'), $n2 => wp_cache_get($n2, 'notification_meta')); $this->assertEquals($expected, $found); }
/** * Delete a meta entry from the DB for a notification item. * * @since 2.3.0 * * @global object $wpdb WordPress database access object. * * @param int $notification_id ID of the notification item whose metadata is being deleted. * @param string $meta_key Optional. The key of the metadata being deleted. If * omitted, all metadata associated with the notification * item will be deleted. * @param string $meta_value Optional. If present, the metadata will only be * deleted if the meta_value matches this parameter. * @param bool $delete_all Optional. If true, delete matching metadata entries * for all objects, ignoring the specified object_id. Otherwise, * only delete matching metadata entries for the specified * notification item. Default: false. * * @return bool True on success, false on failure. */ function bp_notifications_delete_meta($notification_id, $meta_key = '', $meta_value = '', $delete_all = false) { // Legacy - if no meta_key is passed, delete all for the item if (empty($meta_key)) { $all_meta = bp_notifications_get_meta($notification_id); $keys = !empty($all_meta) ? array_keys($all_meta) : array(); // With no meta_key, ignore $delete_all $delete_all = false; } else { $keys = array($meta_key); } $retval = true; add_filter('query', 'bp_filter_metaid_column_name'); foreach ($keys as $key) { $retval = delete_metadata('notifications', $notification_id, $key, $meta_value, $delete_all); } remove_filter('query', 'bp_filter_metaid_column_name'); return $retval; }