/** * @group bp_messages_delete_meta * @group messages_delete_thread */ public function test_bp_messages_delete_metadata_cache_on_thread_delete() { $this->old_current_user = get_current_user_id(); $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); // create the thread $t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Oy')); // create a reply $this->factory->message->create(array('thread_id' => $t1, 'sender_id' => $u2, 'recipients' => array($u1), 'content' => 'Yo')); // add message meta list($m1, $m2) = $this->get_message_ids($t1); bp_messages_update_meta($m1, 'yolo', 'gah'); bp_messages_update_meta($m2, 'yolo', 'bah'); // prime message meta cache bp_messages_get_meta($m1, 'yolo'); bp_messages_get_meta($m2, 'yolo'); // delete thread // to outright delete a thread, both recipients must delete it $this->set_current_user($u1); messages_delete_thread($t1); $this->set_current_user($u2); messages_delete_thread($t1); // assert empty meta cache $this->assertEmpty(wp_cache_get($m1, 'message_meta')); $this->assertEmpty(wp_cache_get($m2, 'message_meta')); // cleanup $this->set_current_user($this->old_current_user); }
/** * Function to determine if a message ID is starred. * * @since 2.3.0 * * @param int $mid The message ID. Please note that this isn't the message thread ID. * @param int $user_id The user ID. * @return bool */ function bp_messages_is_message_starred($mid = 0, $user_id = 0) { if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } if (empty($mid)) { return false; } $starred = array_flip((array) bp_messages_get_meta($mid, 'starred_by_user', false)); if (isset($starred[$user_id])) { return true; } else { return false; } }
/** * Fetch a private message item's cached embeds. * * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}. * * @since 2.2.0 * * @param string $cache An empty string passed by BP_Embed::parse_oembed() for * functions like this one to filter. * @param int $id The ID of the message item. * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). * @return mixed The cached embeds for this message item. */ function bp_embed_message_cache($cache, $id, $cachekey) { return bp_messages_get_meta($id, $cachekey); }