bp_messages_delete_meta( int $message_id, string|bool $meta_key = false, string|bool $meta_value = false, bool $delete_all = false )

Delete metadata for a message.


Description Description

If $meta_key is false, this will delete all meta for the message ID.

See also See also


Top ↑

Parameters Parameters

$message_id

(int) (Required) ID of the message to have meta deleted for.

$meta_key

(string|bool) (Optional) Meta key to delete.

Default value: false

$meta_value

(string|bool) (Optional) Meta value to delete.

Default value: false

$delete_all

(bool) (Optional) Whether or not to delete all meta data.

Default value: false


Top ↑

Return Return

(bool) True on successful delete, false on failure.


Top ↑

Source Source

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

function bp_messages_delete_meta( $message_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
	global $wpdb;

	// Legacy - if no meta_key is passed, delete all for the item.
	if ( empty( $meta_key ) ) {
		$table_name = buddypress()->messages->table_name_meta;
		$sql        = "SELECT meta_key FROM {$table_name} WHERE message_id = %d";
		$query      = $wpdb->prepare( $sql, $message_id );
		$keys       = $wpdb->get_col( $query );

		// With no meta_key, ignore $delete_all.
		$delete_all = false;
	} else {
		$keys = array( $meta_key );
	}

	$retval = false;

	// No keys, so stop now!
	if ( empty( $keys ) ) {
		return $retval;
	}

	add_filter( 'query', 'bp_filter_metaid_column_name' );

	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'message', $message_id, $key, $meta_value, $delete_all );
	}

	remove_filter( 'query', 'bp_filter_metaid_column_name' );

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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