bp_document_folder ::删除(数组args美元=数组())
从数据库中删除文件夹。
描述
要删除一个特定的文件夹,请传递一个“id”参数。否则使用过滤器。
参数
- args美元
-
(数组)(可选的)
默认值:数组()
返回
(数组| bool)成功时删除的文档id数组,失败时为false。
源
文件:bp-document / classes / class-bp-document-folder.php
公共静态函数删除($ args = array()){global $ wpdb;$ bp = buddypress();$ r = wp_parse_args($ args,array('id'=> false,'user_id'=> false,'group_id'=> false,'date_created'=> false,));//从查询参数的位置设置空数组。$ where_args = array();// ID。if(!空($ r ['id']))){$ where_args [] = $ wpdb->准备('id =%d',$ r ['id');} // 用户身份。if(!空($ r ['user_id']))){$ where_args [] = $ wpdb->准备('user_id =%d',$ r ['user_id']);} //组ID。 if ( ! empty( $r['group_id'] ) ) { $where_args[] = $wpdb->prepare( 'group_id = %d', $r['group_id'] ); } // Date created. if ( ! empty( $r['date_created'] ) ) { $where_args[] = $wpdb->prepare( 'date_created = %s', $r['date_created'] ); } // Bail if no where arguments. if ( empty( $where_args ) ) { return false; } // Join the where arguments for querying. $where_sql = 'WHERE ' . join( ' AND ', $where_args ); // Fetch all document folders being deleted so we can perform more actions. $folders = $wpdb->get_results( "SELECT * FROM {$bp->document->table_name_folder} {$where_sql}" ); // db call ok; no-cache ok; if ( ! empty( $r['id'] ) && empty( $r['date_created'] ) && empty( $r['group_id'] ) && empty( $r['user_id'] ) ) { $recursive_folders = $wpdb->get_results( "SELECT * FROM {$bp->document->table_name_folder} WHERE FIND_IN_SET(ID,(SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM ( SELECT @pv:=(SELECT GROUP_CONCAT(id SEPARATOR ',') FROM {$bp->document->table_name_folder} WHERE parent IN (@pv)) AS lv FROM {$bp->document->table_name_folder} JOIN (SELECT @pv:= {$r['id']})tmp WHERE parent IN (@pv)) a))" ); // db call ok; no-cache ok; $folders = array_merge( $folders, $recursive_folders ); } /** * Action to allow intercepting folders to be deleted. * * @param array $folders Array of document folders. * @param array $r Array of parsed arguments. * * @since BuddyBoss 1.4.0 */ do_action_ref_array( 'bp_document_folder_before_delete', array( $folders, $r ) ); if ( ! empty( $r['id'] ) && empty( $r['date_created'] ) && empty( $r['group_id'] ) && empty( $r['user_id'] ) ) { $recursive_folders = $wpdb->get_results( "SELECT * FROM {$bp->document->table_name_folder} WHERE FIND_IN_SET(ID,(SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM ( SELECT @pv:=(SELECT GROUP_CONCAT(id SEPARATOR ',') FROM {$bp->document->table_name_folder} WHERE parent IN (@pv)) AS lv FROM {$bp->document->table_name_folder} JOIN (SELECT @pv:= {$r['id']})tmp WHERE parent IN (@pv)) a))" ); // db call ok; no-cache ok; $folders = array_merge( $folders, $recursive_folders ); // Pluck the document folders IDs out of the $folders array. $foldr_ids = wp_parse_id_list( wp_list_pluck( $folders, 'id' ) ); // delete the document associated with folder. if ( ! empty( $foldr_ids ) ) { foreach ( $foldr_ids as $folder_id ) { // Attempt to delete document folders from the database. $deleted = $wpdb->query( "DELETE FROM {$bp->document->table_name_folder} where id = {$folder_id}" ); // db call ok; no-cache ok; } } } else { // Attempt to delete document folders from the database. $deleted = $wpdb->query( "DELETE FROM {$bp->document->table_name_folder} {$where_sql}" ); // db call ok; no-cache ok; } // Bail if nothing was deleted. if ( empty( $deleted ) ) { return false; } /** * Action to allow intercepting folders just deleted. * * @param array $folders Array of document folders. * @param array $r Array of parsed arguments. * * @since BuddyBoss 1.4.0 */ do_action_ref_array( 'bp_document_folder_after_delete', array( $folders, $r ) ); // Pluck the document folders IDs out of the $folders array. $foldr_ids = wp_parse_id_list( wp_list_pluck( $folders, 'id' ) ); // delete the document associated with folder. if ( ! empty( $foldr_ids ) ) { foreach ( $foldr_ids as $folder_id ) { bp_document_delete( array( 'folder_id' => $folder_id ) ); } } if ( ! empty( $foldr_ids ) ) { // Delete all folder meta entries for folder items. self::delete_document_folder_meta_entries( wp_list_pluck( $folders, 'id' ) ); } // delete all child folders. if ( ! empty( $foldr_ids ) ) { foreach ( $foldr_ids as $folder_id ) { // Get child folders. $get_children = bp_document_get_folder_children( $folder_id ); if ( $get_children ) { foreach ( $get_children as $child ) { // Delete all documents of folder. bp_document_delete( array( 'folder_id' => $child ) ); // Delete Child folder. bp_folder_delete( array( 'id' => $child ) ); } } } } return $foldr_ids; }
更新日志
版本 | 描述 |
---|---|
Buddyboss 1.4.0. | 介绍了。 |