BP_REST_Messages_Endpoint::prepare_item_for_database( WP_REST_Request $request )
Prepare a message for create.
Description
Parameters
- $request
-
(Required) The request sent to the API.
Return
(stdClass)
Source
File: bp-messages/classes/class-bp-rest-messages-endpoint.php
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | protected function prepare_item_for_database( $request ) { $prepared_thread = new stdClass(); $schema = $this ->get_item_schema(); $thread = $this ->get_thread_object( $request [ 'id' ] ); if ( ! empty ( $schema [ 'properties' ][ 'id' ] ) && ! empty ( $request [ 'id' ] ) ) { $prepared_thread ->thread_id = $request [ 'id' ]; } elseif ( ! empty ( $thread ->thread_id ) ) { $prepared_thread ->thread_id = $thread ->thread_id; } if ( ! empty ( $schema [ 'properties' ][ 'sender_id' ] ) && ! empty ( $request [ 'sender_id' ] ) ) { $prepared_thread ->sender_id = $thread ->sender_id; } elseif ( ! empty ( $thread ->sender_id ) ) { $prepared_thread ->sender_id = $thread ->sender_id; } else { $prepared_thread ->sender_id = bp_loggedin_user_id(); } if ( ! empty ( $schema [ 'properties' ][ 'message' ] ) && ! empty ( $request [ 'message' ] ) ) { $prepared_thread ->content = $request [ 'message' ]; } elseif ( ! empty ( $thread ->message ) ) { $prepared_thread ->message = $thread ->message; } if ( ! empty ( $schema [ 'properties' ][ 'subject' ] ) && ! empty ( $request [ 'subject' ] ) ) { $prepared_thread ->subject = $request [ 'subject' ]; } elseif ( ! empty ( $thread ->subject ) ) { $prepared_thread ->subject = $thread ->subject; } if ( ! empty ( $schema [ 'properties' ][ 'recipients' ] ) && ! empty ( $request [ 'recipients' ] ) ) { $prepared_thread ->recipients = $request [ 'recipients' ]; } elseif ( ! empty ( $thread ->recipients ) ) { $prepared_thread ->recipients = wp_parse_id_list( wp_list_pluck( $thread ->recipients, 'user_id' ) ); } $prepared_thread ->mark_visible = true; /** * Filters a message before it is inserted via the REST API. * * @param stdClass $prepared_thread An object prepared for inserting into the database. * @param WP_REST_Request $request Request object. * * @since 0.1.0 */ return apply_filters( 'bp_rest_message_pre_insert_value' , $prepared_thread , $request ); } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.