BP_XProfile_Group::get_group_data( array $group_ids )
Get data about a set of groups, based on IDs.
Description
Parameters
- $group_ids
-
(Required) Array of IDs.
Return
(array)
Source
File: bp-xprofile/classes/class-bp-xprofile-group.php
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | protected static function get_group_data( $group_ids ) { global $wpdb ; // Bail if no group IDs are passed. if ( empty ( $group_ids ) ) { return array (); } // Setup empty arrays. $groups = array (); $uncached_gids = array (); // Loop through groups and look for cached & uncached data. foreach ( $group_ids as $group_id ) { // If cached data is found, use it. $group_data = wp_cache_get( $group_id , 'bp_xprofile_groups' ); if ( false !== $group_data ) { $groups [ $group_id ] = $group_data ; // Otherwise leave a placeholder so we don't lose the order. } else { $groups [ $group_id ] = '' ; // Add to the list of items to be queried. $uncached_gids [] = $group_id ; } } // Fetch uncached data from the DB if necessary. if ( ! empty ( $uncached_gids ) ) { // Setup IN query for uncached group data. $uncached_gids_sql = implode( ',' , wp_parse_id_list( $uncached_gids ) ); // Get table name to query. $table_name = buddypress()->profile->table_name_groups; // Fetch data, preserving order. $queried_gdata = $wpdb ->get_results( "SELECT * FROM {$table_name} WHERE id IN ({$uncached_gids_sql}) ORDER BY FIELD( id, {$uncached_gids_sql} )" ); // Make sure query returned valid data. if ( ! empty ( $queried_gdata ) && ! is_wp_error( $queried_gdata ) ) { // Put queried data into the placeholders created earlier, // and add it to the cache. foreach ( ( array ) $queried_gdata as $gdata ) { // Add group to groups array. $groups [ $gdata ->id ] = $gdata ; // Cache previously uncached group data. wp_cache_set( $gdata ->id, $gdata , 'bp_xprofile_groups' ); } } } // Integer casting. foreach ( ( array ) $groups as $key => $data ) { $groups [ $key ]->id = (int) $groups [ $key ]->id; $groups [ $key ]->group_order = (int) $groups [ $key ]->group_order; $groups [ $key ]->can_delete = (int) $groups [ $key ]->can_delete; } // Reset indexes & return. return array_values ( $groups ); } |
Changelog
Version | Description |
---|---|
BuddyPress 2.0.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.