bp_xprofile_delete_meta( int $object_id, string $object_type, string|bool $meta_key = false, mixed $meta_value = false, bool $delete_all = false )

Delete a piece of xprofile metadata.


Parameters Parameters

$object_id

(int) (Required) ID of the object the metadata belongs to.

$object_type

(string) (Required) Type of object. 'group', 'field', or 'data'.

$meta_key

(string|bool) (Optional) Key of the metadata being deleted. If omitted, all metadata for the object will be deleted.

Default value: false

$meta_value

(mixed) (Optional) If provided, only metadata that matches the value will be permitted.

Default value: false

$delete_all

(bool) (Optional) If true, delete matching metadata entries for all objects, ignoring the specified object_id. Otherwise, only delete matching metadata entries for the specified object. Default: false.

Default value: false


Top ↑

Return Return

(bool) True on success, false on failure.


Source Source

File: bp-xprofile/bp-xprofile-functions.php

function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false, $delete_all = false ) {
	global $wpdb;

	// Sanitize object type.
	if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
		return false;
	}

	// Legacy - if no meta_key is passed, delete all for the item.
	if ( empty( $meta_key ) ) {
		$table_key  = 'xprofile_' . $object_type . 'meta';
		$table_name = $wpdb->{$table_key};
		$keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) );

		// Force delete_all to false if deleting all for object.
		$delete_all = false;
	} else {
		$keys = array( $meta_key );
	}

	add_filter( 'query', 'bp_filter_metaid_column_name' );
	add_filter( 'query', 'bp_xprofile_filter_meta_query' );

	$retval = false;
	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value, $delete_all );
	}

	remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
	remove_filter( 'query', 'bp_filter_metaid_column_name' );

	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.