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

986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
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

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.