BP_XProfile_Field::update_position( int $field_id, int|null $position = null, int|null $field_group_id = null )

Update field position and/or field group when relocating.


Parameters Parameters

$field_id

(int) (Required) ID of the field to update.

$position

(int|null) (Optional) Field position to update.

Default value: null

$field_group_id

(int|null) (Optional) ID of the field group.

Default value: null


Top ↑

Return Return

(boolean)


Source Source

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

	public static function update_position( $field_id, $position = null, $field_group_id = null ) {
		global $wpdb;

		// Bail if invalid position or field group.
		if ( ! is_numeric( $position ) || ! is_numeric( $field_group_id ) ) {
			return false;
		}

		// Get table name and field parent.
		$table_name = buddypress()->profile->table_name_fields;
		$sql        = $wpdb->prepare( "UPDATE {$table_name} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id );
		$parent     = $wpdb->query( $sql );

		$retval = false;

		// Update $field_id with new $position and $field_group_id.
		if ( ! empty( $parent ) && ! is_wp_error( $parent ) ) {

			// Update any children of this $field_id.
			$sql = $wpdb->prepare( "UPDATE {$table_name} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id );
			$wpdb->query( $sql );

			// Invalidate profile field and group query cache.
			wp_cache_delete( $field_id, 'bp_xprofile_fields' );

			$retval = $parent;
		}

		bp_core_reset_incrementor( 'bp_xprofile_groups' );

		return $retval;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.