/** * Add a piece of message metadata. * * @deprecated BuddyPress (2.2.2) */ function bp_message_add_meta($message_id, $meta_key, $meta_value, $unique = false) { _deprecated_function(__FUNCTION__, '2.3.0', 'bp_messages_add_meta()'); return bp_messages_add_meta($message_id, $meta_key, $meta_value, $unique); }
/** * Save or delete star message meta according to a message's star status. * * @since 2.3.0 * * @param array $args { * Array of arguments. * @type string $action The star action. Either 'star' or 'unstar'. Default: 'star'. * @type int $thread_id The message thread ID. Default: 0. If not zero, this takes precedence over * $message_id. * @type int $message_id The indivudal message ID to star or unstar. Default: 0. * @type int $user_id The user ID. Defaults to the logged-in user ID. * @type bool $bulk Whether to mark all messages in a thread as a certain action. Only relevant * when $action is 'unstar' at the moment. Default: false. * } * @return bool */ function bp_messages_star_set_action($args = array()) { $r = wp_parse_args($args, array('action' => 'star', 'thread_id' => 0, 'message_id' => 0, 'user_id' => bp_loggedin_user_id(), 'bulk' => false)); // Set thread ID. if (!empty($r['thread_id'])) { $thread_id = (int) $r['thread_id']; } else { $thread_id = messages_get_message_thread_id($r['message_id']); } if (empty($thread_id)) { return false; } // Check if user has access to thread. if (!messages_check_thread_access($thread_id, $r['user_id'])) { return false; } $is_starred = bp_messages_is_message_starred($r['message_id'], $r['user_id']); // Star. if ('star' == $r['action']) { if (true === $is_starred) { return true; } else { bp_messages_add_meta($r['message_id'], 'starred_by_user', $r['user_id']); return true; } // Unstar. } else { // Unstar one message. if (false === $r['bulk']) { if (false === $is_starred) { return true; } else { bp_messages_delete_meta($r['message_id'], 'starred_by_user', $r['user_id']); return true; } // Unstar all messages in a thread. } else { $thread = new BP_Messages_Thread($thread_id); $mids = wp_list_pluck($thread->messages, 'id'); foreach ($mids as $mid) { if (true === bp_messages_is_message_starred($mid, $r['user_id'])) { bp_messages_delete_meta($mid, 'starred_by_user', $r['user_id']); } } return true; } } }