bp_notifications_delete_meta( int $notification_id, string $meta_key = '', string $meta_value = '', bool $delete_all = false )

Delete a meta entry from the DB for a notification item.


Parameters Parameters

$notification_id

(int) (Required) ID of the notification item whose metadata is being deleted.

$meta_key

(string) (Optional) The key of the metadata being deleted. If omitted, all metadata associated with the notification item will be deleted.

Default value: ''

$meta_value

(string) (Optional) If present, the metadata will only be deleted if the meta_value matches this parameter.

Default value: ''

$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 notification item. Default: false.

Default value: false


Top ↑

Return Return

(bool) True on success, false on failure.


Source Source

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

function bp_notifications_delete_meta( $notification_id, $meta_key = '', $meta_value = '', $delete_all = false ) {

	// Legacy - if no meta_key is passed, delete all for the item.
	if ( empty( $meta_key ) ) {
		$all_meta = bp_notifications_get_meta( $notification_id );
		$keys     = ! empty( $all_meta )
			? array_keys( $all_meta )
			: array();

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

	$retval = true;

	add_filter( 'query', 'bp_filter_metaid_column_name' );
	foreach ( $keys as $key ) {
		$retval = delete_metadata( 'notification', $notification_id, $key, $meta_value, $delete_all );
	}
	remove_filter( 'query', 'bp_filter_metaid_column_name' );

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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