bp_document_move_folder_to_folder (folder_id美元,destination_folder_id美元,group_id美元)
这个函数将把文件夹移动到另一个目标文件夹id。
描述
参数
- folder_id美元
-
(必需)
- destination_folder_id美元
-
(必需)
- group_id美元
-
(必需)
返回
(保龄球)
源
文件:bp-document / bp-document-functions.php
函数bp_document_move_folder_to_folder($folder_id, $destination_folder_id, $group_id = 0) {global $wpdb, $bp;If (" === $folder_id || " === $destination_folder_id){返回false;} if ((int) $folder_id > 0) {$has_access = bp_folder_user_can_edit($folder_id);如果(!$has_access){返回false;}} if ((int) $destination_folder_id > 0) {$has_destination_access = bp_folder_user_can_edit($destination_folder_id);如果(!$has_destination_access){返回false;}} if (!$group_id) {$get_folder = new BP_Document_Folder($folder_id); if ( $get_folder->group_id > 0 ) { $group_id = $get_folder->group_id; } } $destination_privacy = 'loggedin'; if ( $group_id > 0 ) { $destination_privacy = 'grouponly'; } elseif ( $destination_folder_id > 0 ) { $destination_folder = BP_Document_Folder::get_folder_data( array( $destination_folder_id ) ); $destination_privacy = $destination_folder[0]->privacy; // Update modify date for destination folder. $destination_folder_update = new BP_Document_Folder( $destination_folder_id ); $destination_folder_update->date_modified = bp_core_current_time(); $destination_folder_update->save(); } // Update main parent folder. $folder = new BP_Document_Folder( $folder_id ); $folder->privacy = $destination_privacy; $folder->parent = $destination_folder_id; $folder->date_modified = bp_core_current_time(); $folder->save(); // Get all the documents of main folder. $document_ids = bp_document_get_folder_document_ids( $folder_id ); if ( ! empty( $document_ids ) ) { foreach ( $document_ids as $id ) { // Update privacy of the document. $query_update_document = $wpdb->prepare( "UPDATE {$bp->document->table_name} SET privacy = %s WHERE id = %d", $destination_privacy, $id ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $query = $wpdb->query( $query_update_document ); // Update document activity privacy. $document = new BP_Document( $id ); if ( ! empty( $document ) && ! empty( $document->attachment_id ) ) { $post_attachment = $document->attachment_id; $activity_id = get_post_meta( $post_attachment, 'bp_document_parent_activity_id', true ); if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) { $activity = new BP_Activity_Activity( (int) $activity_id ); if ( bp_activity_user_can_delete( $activity ) ) { $activity->privacy = $destination_privacy; $activity->save(); } } } } } // Update privacy for all child folders. $get_children = bp_document_get_folder_children( $folder_id ); foreach ( $get_children as $child ) { $query_update_child = $wpdb->prepare( "UPDATE {$bp->document->table_name_folder} SET privacy = %s WHERE id = %d", $destination_privacy, $child ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $query = $wpdb->query( $query_update_child ); // Get all the documents of particular folder. $document_ids = bp_document_get_folder_document_ids( $child ); if ( ! empty( $document_ids ) ) { foreach ( $document_ids as $id ) { // Update privacy of the document. $query_update_document = $wpdb->prepare( "UPDATE {$bp->document->table_name} SET privacy = %s WHERE id = %d", $destination_privacy, $id ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $query = $wpdb->query( $query_update_document ); // Update document activity privacy. $document = new BP_Document( $id ); if ( ! empty( $document ) && ! empty( $document->attachment_id ) ) { $post_attachment = $document->attachment_id; $activity_id = get_post_meta( $post_attachment, 'bp_document_parent_activity_id', true ); if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) { $activity = new BP_Activity_Activity( (int) $activity_id ); if ( bp_activity_user_can_delete( $activity ) ) { $activity->privacy = $destination_privacy; $activity->save(); } } } } } } return true; }
更新日志
版本 | 描述 |
---|---|
BuddyBoss 1.4.0 | 介绍了。 |