bp_admin_update_activity_favourite()

Check if BuddyPress activity favorites data needs upgrade & Update to BuddyBoss activity like data

Description

Source

File: bp-core/admin/bp-core-admin-tools.php

1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
function bp_admin_update_activity_favourite() {
 
    $bp_activity_favorites = bp_get_option( 'bp_activity_favorites', false );
 
    if ( ! $bp_activity_favorites ) {
 
        $offset = isset( $_POST['offset'] ) ? (int) ( $_POST['offset'] ) : 0;
 
        $args = array(
            'number' => 50,
            'offset' => $offset,
        );
 
        $users = get_users( $args );
 
        if ( ! empty( $users ) ) {
 
            foreach ( $users as $user ) {
                $user_favs = bp_get_user_meta( $user->ID, 'bp_favorite_activities', true );
                if ( empty( $user_favs ) || ! is_array( $user_favs ) ) {
                    $offset ++;
                    continue;
                }
                foreach ( $user_favs as $fav ) {
 
                    // Update the users who have favorited this activity.
                    $favorite_users = bp_activity_get_meta( $fav, 'bp_favorite_users', true );
                    if ( empty( $favorite_users ) || ! is_array( $favorite_users ) ) {
                        $favorite_users = array();
                    }
                    // Add to activity's favorited users.
                    $favorite_users[] = $user->ID;
 
                    // Update activity meta
                    bp_activity_update_meta( $fav, 'bp_favorite_users', array_unique( $favorite_users ) );
 
                }
                $offset ++;
            }
 
            $records_updated = sprintf( __( '%s members activity favorite updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );
 
            return array(
                'status'  => 'running',
                'offset'  => $offset,
                'records' => $records_updated,
            );
 
        } else {
 
            bp_update_option( 'bp_activity_favorites', true );
 
            $statement = __( 'Update members activity favorites… %s', 'buddyboss' );
 
            return array(
                'status'  => 1,
                'message' => sprintf( $statement, __( 'Complete!', 'buddyboss' ) ),
            );
        }
 
    } else {
        $statement = __( 'Update members activity favorites… %s', 'buddyboss' );
 
        return array(
            'status'  => 1,
            'message' => sprintf( $statement, __( 'Complete!', 'buddyboss' ) ),
        );
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.3.3 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.