bp_nouveau_ajax_messages_send_reply ()
AJAX发送消息回复和显示错误。
描述
源
文件:bp-templates / bp-nouveau包括/信息/ ajax.php
函数bp_nouveau_ajax_messages_send_reply() {$response = array('feedback' => __('发送你的回复有问题。请再试一次。', 'buddyboss'), 'type' => 'error',);//验证nonce if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'messages_send_message')) {wp_send_json_error($response);} if (empty($_POST['content']) || empty($_POST['thread_id'])) {$response['feedback'] = __('请添加一些内容到您的消息。”、“buddyboss”);wp_send_json_error($响应);} $_POST['thread_id']; / /创建线程如果(!Bp_current_user_can ('bp_moderate') && (! messages_is_valid_thread( $thread_id ) || ! messages_check_thread_access( $thread_id ) ) ) { wp_send_json_error( $response ); } $new_reply = messages_new_message( array( 'thread_id' => $thread_id, 'subject' => ! empty( $_POST['subject'] ) ? $_POST['subject'] : false, 'content' => $_POST['content'], 'date_sent' => $date_sent = bp_core_current_time(), 'error_type' => 'wp_error', ) ); if ( is_wp_error( $new_reply ) ) { $response['feedback'] = $new_reply->get_error_message(); wp_send_json_error( $response ); } // Send the reply. if ( empty( $new_reply ) ) { wp_send_json_error( $response ); } // Get the message by pretending we're in the message loop. global $thread_template, $media_template; $bp = buddypress(); $reset_action = $bp->current_action; // Override bp_current_action(). $bp->current_action = 'view'; bp_thread_has_messages( array( 'thread_id' => $thread_id , 'before' => $date_sent ) ); // Set current message to current key. $thread_template->current_message = -1; // Now manually iterate message like we're in the loop. bp_thread_the_message(); // Manually call oEmbed // this is needed because we're not at the beginning of the loop. bp_messages_embed(); // Output single message template part. $reply = array( 'id' => bp_get_the_thread_message_id(), 'content' => do_shortcode( bp_get_the_thread_message_content() ), 'sender_id' => bp_get_the_thread_message_sender_id(), 'sender_name' => esc_html( bp_get_the_thread_message_sender_name() ), 'sender_link' => bp_get_the_thread_message_sender_link(), 'sender_is_you' => bp_get_the_thread_message_sender_id() === bp_loggedin_user_id(), 'sender_avatar' => esc_url( bp_core_fetch_avatar( array( 'item_id' => bp_get_the_thread_message_sender_id(), 'object' => 'user', 'type' => 'thumb', 'width' => 32, 'height' => 32, 'html' => false, ) ) ), 'date' => bp_get_the_thread_message_date_sent() * 1000, 'display_date' => bp_get_the_thread_message_time_since(), ); if ( bp_is_active( 'messages', 'star' ) ) { $star_link = bp_get_the_message_star_action_link( array( 'message_id' => bp_get_the_thread_message_id(), 'url_only' => true, ) ); $reply['star_link'] = $star_link; $reply['is_starred'] = array_search( 'unstar', explode( '/', $star_link ) ); } if ( bp_is_active( 'media' ) && bp_is_messages_media_support_enabled() ) { $media_ids = bp_messages_get_meta( bp_get_the_thread_message_id(), 'bp_media_ids', true ); if ( ! empty( $media_ids ) && bp_has_media( array( 'include' => $media_ids, 'order_by' => 'menu_order', 'sort' => 'ASC' ) ) ) { $reply['media'] = array(); while ( bp_media() ) { bp_the_media(); $reply['media'][] = array( 'id' => bp_get_media_id(), 'title' => bp_get_media_title(), 'thumbnail' => bp_get_media_attachment_image_thumbnail(), 'full' => bp_get_media_attachment_image(), 'meta' => $media_template->media->attachment_data->meta, ); } } } if ( bp_is_active( 'media' ) && bp_is_messages_gif_support_enabled() ) { $gif_data = bp_messages_get_meta( bp_get_the_thread_message_id(), '_gif_data', true ); if ( ! empty( $gif_data ) ) { $preview_url = wp_get_attachment_url( $gif_data['still'] ); $video_url = wp_get_attachment_url( $gif_data['mp4'] ); $reply['gif'] = array( 'preview_url' => $preview_url, 'video_url' => $video_url, ); } } $extra_content = bp_nouveau_messages_catch_hook_content( array( 'beforeMeta' => 'bp_before_message_meta', 'afterMeta' => 'bp_after_message_meta', 'beforeContent' => 'bp_before_message_content', 'afterContent' => 'bp_after_message_content', ) ); if ( array_filter( $extra_content ) ) { $reply = array_merge( $reply, $extra_content ); } // Clean up the loop. bp_thread_messages(); // Remove the bp_current_action() override. $bp->current_action = $reset_action; // set a flag $reply['is_new'] = true; wp_send_json_success( array( 'messages' => array( $reply ), 'feedback' => __( 'Your reply was sent successfully', 'buddyboss' ), 'type' => 'success', ) ); }
更新日志
版本 | 描述 |
---|---|
BuddyPress 3.0.0 | 介绍了。 |