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.
Description
Parameters
- $object_id
-
(Required) ID of the object the metadata belongs to.
- $object_type
-
(Required) Type of object. 'group', 'field', or 'data'.
- $meta_key
-
(Optional) Key of the metadata being deleted. If omitted, all metadata for the object will be deleted.
Default value: false
- $meta_value
-
(Optional) If provided, only metadata that matches the value will be permitted.
Default value: false
- $delete_all
-
(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
Return
(bool) True on success, false on failure.
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; }
Changelog
Version | Description |
---|---|
BuddyPress 1.5.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.