bp_rest_document_endpoint :: bp_documents_update_rest_field_callback(目的$对象那目的美元的价值那字符串美元的属性的)
用于更新文档的活动REST字段的函数。
描述
参数
- $对象
-
(目的的)(必需的)BuddyPress组件的对象刚刚在请求期间创建/更新。(在这种情况下bp_actity_actity.目的)。
- 美元的价值
-
(目的的)(必需的)要保存的REST字段的值。
- 美元的属性
-
(字符串的)(必需的)用于休息响应的REST字段键。
返回
(对象)
源
文件:bp-document /类/ class-bp-rest-document-endpoint.php
Protected函数bp_documents_update_rest_field_callback($object, $value, $attribute) {global $bp_activity_edit, $bp_activity_post_update_id, $bp_activity_post_update;If ('bp_documents' !== $attribute) {$value->bp_documents = null;美元返回值;} $bp_activity_edit = (isset($value->edit)) ?True: false);// phpcs:ignore $_POST['edit'] = $bp_activity_edit; // phpcs:ignore $_POST['edit'] = $bp_activity_edit;If (false === $bp_activity_edit && empty($object)){返回$value;} $activity_id = $value->id;隐私=美元价值- >隐私;美元group_id = 0; $documents = wp_parse_id_list( $object ); $old_document_ids = bp_activity_get_meta( $activity_id, 'bp_document_ids', true ); $old_document_ids = ( ! empty( $old_document_ids ) ? explode( ',', $old_document_ids ) : array() ); $new_documents = array(); $old_documents = array(); $old_documents_objects = array(); if ( ! empty( $old_document_ids ) ) { foreach ( $old_document_ids as $id ) { $document_object = new BP_Document( $id ); $old_documents_objects[ $document_object->attachment_id ] = $document_object; $old_documents[ $id ] = $document_object->attachment_id; } } $bp_activity_post_update = true; $bp_activity_post_update_id = $activity_id; if ( ! empty( $value->component ) && 'groups' === $value->component ) { $group_id = $value->item_id; $privacy = 'grouponly'; } if ( ! isset( $documents ) || empty( $documents ) ) { // delete document ids and meta for activity if empty document in request. // delete media ids and meta for activity if empty media in request. if ( ! empty( $activity_id ) && ! empty( $old_document_ids ) ) { foreach ( $old_document_ids as $document_id ) { bp_document_delete( array( 'id' => $document_id ), 'activity' ); } bp_activity_delete_meta( $activity_id, 'bp_document_ids' ); } return $value; } else { $order_count = 0; foreach ( $documents as $id ) { $wp_attachment_url = wp_get_attachment_url( $id ); // when the file found to be empty it's means it's not a valid attachment. if ( empty( $wp_attachment_url ) ) { continue; } $order_count ++; if ( in_array( $id, $old_documents, true ) ) { $new_documents[] = array( 'document_id' => $old_documents_objects[ $id ]->id, ); } else { $new_documents[] = array( 'id' => $id, 'name' => get_the_title( $id ), 'folder_id' => 0, 'group_id' => $group_id, 'menu_order' => $order_count, 'privacy' => $privacy, 'error_type' => 'wp_error', ); } } } remove_action( 'bp_activity_posted_update', 'bp_document_update_activity_document_meta', 10, 3 ); remove_action( 'bp_groups_posted_update', 'bp_document_groups_activity_update_document_meta', 10, 4 ); remove_action( 'bp_activity_comment_posted', 'bp_document_activity_comments_update_document_meta', 10, 3 ); remove_action( 'bp_activity_comment_posted_notification_skipped', 'bp_document_activity_comments_update_document_meta', 10, 3 ); $document_ids = bp_document_add_handler( $new_documents, $privacy, '', $group_id ); add_action( 'bp_activity_posted_update', 'bp_document_update_activity_document_meta', 10, 3 ); add_action( 'bp_groups_posted_update', 'bp_document_groups_activity_update_document_meta', 10, 4 ); add_action( 'bp_activity_comment_posted', 'bp_document_activity_comments_update_document_meta', 10, 3 ); add_action( 'bp_activity_comment_posted_notification_skipped', 'bp_document_activity_comments_update_document_meta', 10, 3 ); // save document meta for activity. if ( ! empty( $activity_id ) ) { // Delete document if not exists in current document ids. if ( true === $bp_activity_edit ) { if ( ! empty( $old_document_ids ) ) { foreach ( $old_document_ids as $document_id ) { if ( ! in_array( (int) $document_id, $document_ids, true ) ) { bp_document_delete( array( 'id' => $document_id ) ); } } } } bp_activity_update_meta( $activity_id, 'bp_document_ids', implode( ',', $document_ids ) ); } }