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
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 | 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.