bp_dd_import_groups( bool|array $users = false )
Importer engine – GROUPS
Description
Parameters
- $users
-
(Optional) Users list we want to work with. Get random if empty.
Default value: false
Return
(array)
Source
File: bp-core/bp-core-tools-default-data.php
function bp_dd_import_groups( $users = false ) { $groups = array(); $group_ids = array(); $forum_group_ids = array(); if ( ! bp_is_active( 'groups' ) ) { return $group_ids; } // Use currently available users from DB if no default were specified. if ( empty( $users ) ) { $users = get_users(); } $image_url = BP_DEFAULT_DATA_URL . 'data/images/groups/'; $cover_image_url = $image_url . 'cover/'; $avatars_image_url = $image_url . 'avatars/'; require( BP_DEFAULT_DATA_DIR . '/data/groups.php' ); foreach ( $groups as $group ) { $creator_id = is_object( $users[ array_rand( $users ) ] ) ? $users[ array_rand( $users ) ]->ID : $users[ array_rand( $users ) ]; $cur = groups_create_group( array( 'creator_id' => $creator_id, 'name' => $group['name'], 'description' => $group['description'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $group['name'] ) ) ), 'status' => $group['status'], 'date_created' => bp_dd_get_random_date( 30, 5 ), ) ); groups_update_groupmeta( $cur, 'last_activity', bp_dd_get_random_date( 10 ) ); // add cover images url into DB if ( ! empty( $group['cover-image'] ) ) { groups_update_groupmeta( $cur, 'cover-image', $cover_image_url . $group['cover-image'] ); } // add cover images url into DB if ( ! empty( $group['avatars'] ) ) { groups_update_groupmeta( $cur, 'avatars', $avatars_image_url . $group['avatars'] ); } $group_ids[] = $cur; if ( ! empty( $group['forums'] ) ) { $forum_group_ids[] = $cur; } } if ( ! empty( $group_ids ) ) { /** @noinspection PhpParamsInspection */ bp_update_option( 'bp_dd_imported_group_ids', $group_ids ); bp_update_option( 'bp_dd_imported_forums_group_ids', $forum_group_ids ); } return $group_ids; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.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.