bp_document_forums_new_post_document_save (post_id美元)
保存新主题或回复时保存文档
描述
参数
- post_id美元
-
(必需)
源
文件:bp-document / bp-document-filters.php
函数bp_document_forums_new_post_document_save($post_id) {if (!empty($_POST['bbp_document']){//保存活动id,如果它保存在论坛和平台设置启用。$main_activity_id = get_post_meta($post_id, '_bbp_activity_id', true);/ /保存文档。$documents = json_decode(stripslashes($_POST['bbp_document']), true); / /将所有文件都保存在json_decode中//获取当前上传的文档id。数组$ existing_document = ();$existing_document_ids = get_post_meta($post_id, 'bp_document_ids', true); / /创建文件数组$ existing_document_attachment_ids = ();如果(! empty( $existing_document_ids ) ) { $existing_document_ids = explode( ',', $existing_document_ids ); foreach ( $existing_document_ids as $existing_document_id ) { $existing_document[ $existing_document_id ] = new BP_Document( $existing_document_id ); if ( ! empty( $existing_document[ $existing_document_id ]->attachment_id ) ) { $existing_document_attachment_ids[] = $existing_document[ $existing_document_id ]->attachment_id; } } } $document_ids = array(); foreach ( $documents as $document ) { $title = ! empty( $document['name'] ) ? $document['name'] : ''; $attachment_id = ! empty( $document['id'] ) ? $document['id'] : 0; $attached_document_id = ! empty( $document['document_id'] ) ? $document['document_id'] : 0; $folder_id = ! empty( $document['folder_id'] ) ? $document['folder_id'] : 0; $group_id = ! empty( $document['group_id'] ) ? $document['group_id'] : 0; $forum_id = ! empty( $document['forum_id'] ) ? $document['forum_id'] : 0; $topic_id = ! empty( $document['topic_id'] ) ? $document['topic_id'] : 0; $reply_id = ! empty( $document['reply_id'] ) ? $document['reply_id'] : 0; $menu_order = ! empty( $document['menu_order'] ) ? $document['menu_order'] : 0; if ( ! empty( $existing_document_attachment_ids ) ) { $index = array_search( $attachment_id, $existing_document_attachment_ids ); if ( ! empty( $attachment_id ) && $index !== false && ! empty( $existing_document[ $attached_document_id ] ) ) { $existing_document[ $attached_document_id ]->menu_order = $menu_order; $existing_document[ $attached_document_id ]->save(); unset( $existing_document_ids[ $index ] ); $document_ids[] = $attached_document_id; continue; } } if ( 0 === $reply_id && bbp_get_reply_post_type() === get_post_type( $post_id ) ) { $reply_id = $post_id; $topic_id = bbp_get_reply_topic_id( $reply_id ); $forum_id = bbp_get_topic_forum_id( $topic_id ); } elseif ( 0 === $topic_id && bbp_get_topic_post_type() === get_post_type( $post_id ) ) { $topic_id = $post_id; $forum_id = bbp_get_topic_forum_id( $topic_id ); } elseif ( 0 === $forum_id && bbp_get_forum_post_type() === get_post_type( $post_id ) ) { $forum_id = $post_id; } $attachment_data = get_post( $document['id'] ); $file = get_attached_file( $document['id'] ); $file_type = wp_check_filetype( $file ); $file_name = basename( $file ); $document_id = bp_document_add( array( 'attachment_id' => $attachment_id, 'title' => $title, 'folder_id' => $folder_id, 'group_id' => $group_id, 'privacy' => 'forums', 'error_type' => 'wp_error', 'menu_order' => $menu_order, ) ); if ( ! is_wp_error( $document_id ) && ! empty( $document_id ) ) { $document_ids[] = $document_id; // save document meta. bp_document_update_meta( $document_id, 'forum_id', $forum_id ); bp_document_update_meta( $document_id, 'topic_id', $topic_id ); bp_document_update_meta( $document_id, 'reply_id', $reply_id ); bp_document_update_meta( $document_id, 'file_name', $file_name ); bp_document_update_meta( $document_id, 'extension', '.' . $file_type['ext'] ); // save document is saved in attachment. update_post_meta( $attachment_id, 'bp_document_saved', true ); } } $document_ids = implode( ',', $document_ids ); // Save all attachment ids in forums post meta. update_post_meta( $post_id, 'bp_document_ids', $document_ids ); // save document meta for activity. if ( ! empty( $main_activity_id ) && bp_is_active( 'activity' ) ) { bp_activity_update_meta( $main_activity_id, 'bp_document_ids', $document_ids ); } // delete documents which were not saved or removed from form. if ( ! empty( $existing_document_ids ) ) { foreach ( $existing_document_ids as $document_id ) { bp_document_delete( array( 'id' => $document_id ) ); } } } }
更新日志
版本 | 描述 |
---|---|
BuddyBoss 1.4.0 | 介绍了。 |