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

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.