BP_Document_Folder::get_folder_data( array $folder_ids = array() )
Convert document IDs to document objects, as expected in template loop.
Description
Parameters
- $folder_ids
-
(array) (Optional) Array of document IDs.
Default value: array()
Return
(array)
Source
File: bp-document/classes/class-bp-document-folder.php
public static function get_folder_data( $folder_ids = array() ) { global $wpdb; // Bail if no document ID's passed. if ( empty( $folder_ids ) ) { return array(); } // Get BuddyPress. $bp = buddypress(); $folders = array(); $uncached_ids = bp_get_non_cached_ids( $folder_ids, 'bp_document_folder' ); // Prime caches as necessary. if ( ! empty( $uncached_ids ) ) { // Format the folder ID's for use in the query below. $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); // Fetch data from folder table, preserving order. $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->document->table_name_folder} WHERE id IN ({$uncached_ids_sql})" ); // db call ok; no-cache ok; // Put that data into the placeholders created earlier, // and add it to the cache. foreach ( (array) $queried_adata as $adata ) { wp_cache_set( $adata->id, $adata, 'bp_document_folder' ); } } // Now fetch data from the cache. foreach ( $folder_ids as $folder_id ) { // Integer casting. $folder = wp_cache_get( $folder_id, 'bp_document_folder' ); if ( ! empty( $folder ) ) { $folder->id = (int) $folder->id; $folder->user_id = (int) $folder->user_id; $folder->group_id = (int) $folder->group_id; $folder->folder_id = (int) $folder->id; } $folder->document = bp_document_get( array( 'folder_id' => $folder->id, 'count_total' => true, ) ); $group_name = ''; $visibility = ''; if ( bp_is_active( 'groups') && $folder->group_id > 0 ) { $group = groups_get_group( $folder->group_id ); $group_name = bp_get_group_name( $group ); $status = bp_get_group_status( $group ); if ( 'hidden' === $status || 'private' === $status ) { $visibility = esc_html__( 'Group Members', 'buddyboss' ); } else { $visibility = ucfirst( $status ); } } else { $document_privacy = bp_document_get_visibility_levels(); $visibility = $document_privacy[ $folder->privacy ]; } $folder->group_name = $group_name; $folder->visibility = $visibility; $folders[] = $folder; } // Then fetch user data. $user_query = new BP_User_Query( array( 'user_ids' => wp_list_pluck( $folders, 'user_id' ), 'populate_extras' => false, ) ); // Associated located user data with folders. foreach ( $folders as $a_index => $a_item ) { $a_user_id = intval( $a_item->user_id ); $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : ''; if ( ! empty( $a_user ) ) { $folders[ $a_index ]->user_email = $a_user->user_email; $folders[ $a_index ]->user_nicename = $a_user->user_nicename; $folders[ $a_index ]->user_login = $a_user->user_login; $folders[ $a_index ]->display_name = $a_user->display_name; } } return $folders; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.