BP_XProfile_Field::delete_for_group( int $group_id )

Delete all fields in a field group.

Description

Parameters

$group_id

(Required) ID of the field group to delete fields from.

Return

(boolean)

Source

File: bp-xprofile/classes/class-bp-xprofile-field.php

	public static function delete_for_group( $group_id = 0 ) {
		global $wpdb;

		// Bail if no group ID.
		if ( empty( $group_id ) ) {
			return false;
		}

		$bp      = buddypress();
		$ids     = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
		$sql     = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
		$deleted = $wpdb->get_var( $sql );

		// Return true if fields were deleted.
		if ( false !== $deleted ) {
			foreach ( $ids as $id ) {
			    if ( isset( $id->id ) ) {
				    $wpdb->get_var( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_meta} WHERE object_id = %s", $id->id ) );
                }
			}
            $wpdb->get_var( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_meta} WHERE object_id = %s", $group_id ) );
			return true;
		}

		return false;
	}

Changelog

Changelog
Version Description
BuddyPress 1.2.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.