bp_nouveau_ajax_post_update ()
处理通过POST请求接收的Activity更新。
描述
返回
(字符串)JSON应答。
源
文件:bp-templates / bp-nouveau包括/活动/ ajax.php
函数bp_nouveau_ajax_post_update() {$bp = buddypress();如果(!is_user_logged_in() | |空($ _POST [' _wpnonce_post_update ']) | | !wp_verify_nonce($_POST['_wpnonce_post_update'], 'post_update') {wp_send_json_error();} if (!strlen(trim($_POST['content'])){//检查activity工具栏选项,如果其中一个设置了,activity可以是空的$toolbar_option = false;If (bp_is_active('media') && !empty($_POST['media']) {$toolbar_option = true;} else if (bp_is_activity_link_preview_active() && !empty($_POST['link_url']) {$toolbar_option = true;} else if (bp_is_active('media') && ! empty( $_POST['gif_data'] ) ) { $toolbar_option = true; } if ( ! $toolbar_option ) { wp_send_json_error( array( 'message' => __( 'Please enter some content to post.', 'buddyboss' ), ) ); } } $activity_id = 0; $item_id = 0; $object = ''; $is_private = false; // Try to get the item id from posted variables. if ( ! empty( $_POST['item_id'] ) ) { $item_id = (int) $_POST['item_id']; } // Try to get the object from posted variables. if ( ! empty( $_POST['object'] ) ) { $object = sanitize_key( $_POST['object'] ); // If the object is not set and we're in a group, set the item id and the object } elseif ( bp_is_group() ) { $item_id = bp_get_current_group_id(); $object = 'group'; $status = groups_get_current_group()->status; } if ( 'user' === $object && bp_is_active( 'activity' ) ) { $content = $_POST['content']; if ( ! empty( $_POST['user_id'] ) && bp_get_displayed_user() && $_POST['user_id'] != bp_get_displayed_user()->id ) { $content = sprintf('@%s %s', bp_get_displayed_user_mentionname(), $content); } $activity_id = bp_activity_post_update( array( 'content' => $content ) ); } elseif ( 'group' === $object ) { if ( $item_id && bp_is_active( 'groups' ) ) { // This function is setting the current group! $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, ) ); if ( empty( $status ) ) { if ( ! empty( $bp->groups->current_group->status ) ) { $status = $bp->groups->current_group->status; } else { $group = groups_get_group( array( 'group_id' => $group_id ) ); $status = $group->status; } $is_private = 'public' !== $status; } } } else { /** This filter is documented in bp-activity/bp-activity-actions.php */ $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] ); } if ( empty( $activity_id ) ) { wp_send_json_error( array( 'message' => __( 'There was a problem posting your update. Please try again.', 'buddyboss' ), ) ); } ob_start(); if ( bp_has_activities( array( 'include' => $activity_id, 'show_hidden' => $is_private ) ) ) { while ( bp_activities() ) { bp_the_activity(); bp_get_template_part( 'activity/entry' ); } } $activity = ob_get_contents(); ob_end_clean(); wp_send_json_success( array( 'id' => $activity_id, 'message' => esc_html__( 'Update posted.', 'buddyboss' ) . ' ' . sprintf( '%s', esc_url( bp_activity_get_permalink( $activity_id ) ), esc_html__( 'View activity.', 'buddyboss' ) ), 'activity' => $activity, /** * Filters whether or not an AJAX post update is private. * * @since BuddyPress 3.0.0 * * @param string/bool $is_private Privacy status for the update. */ 'is_private' => apply_filters( 'bp_nouveau_ajax_post_update_is_private', $is_private ), 'is_directory' => bp_is_activity_directory(), ) ); }
更新日志
版本 | 描述 |
---|---|
BuddyPress 3.0.0 | 介绍了。 |