BP_REST_Messages_Endpoint:: update_item (WP_REST_Request美元的请求

更新线程的一个消息的元数据。

描述

参数

美元的请求

WP_REST_Request(必需)请求的全部细节。

返回

(WP_REST_Response)| WP_Error

文件:bp-messages /类/ class-bp-rest-messages-endpoint.php

public function update_item($request){//设置上下文。$request->set_param('context', 'edit');//获取线程。$this->get_thread_object($request['id']);$error = new WP_Error('bp_rest_messages_update_failed', __('试图更新消息时出错。', 'buddyboss'), array('status' => 500,));如果(!$thread->thread_id) {return $error;} //默认使用最后一条消息。$last_message = reset($thread->messages);message_id = last_message美元- > id; if ( $request['message_id'] ) { $message_id = $request['message_id']; } $updated_message = wp_list_filter( $thread->messages, array( 'id' => $message_id ) ); $updated_message = reset( $updated_message ); /** * Filter here to allow more users to edit the message meta (eg: the recipients). * * @param boolean $value Whether the user can edit the message meta. * By default: only the sender and a community moderator can. * @param BP_Messages_Message $updated_message The updated message object. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ $can_edit_item_meta = apply_filters( 'bp_rest_messages_can_edit_item_meta', bp_loggedin_user_id() === $updated_message->sender_id || bp_current_user_can( 'bp_moderate' ), $updated_message, $request ); // The message must exist in the thread, and the logged in user must be the sender. if ( ! isset( $updated_message->id ) || ! $updated_message->id || ! $can_edit_item_meta ) { return $error; } $fields_update = $this->update_additional_fields_for_object( $updated_message, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $retval = $this->prepare_response_for_collection( $this->prepare_item_for_response( $thread, $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a message is updated via the REST API. * * @param BP_Messages_Message $updated_message The updated message. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_messages_update_item', $updated_message, $response, $request ); return $response; }

更新日志

更新日志
版本 描述
0.1.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队