Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 07:02:16 PM (11 years ago)
Author:
boonebgorges
Message:

Add delete_all support for all _delete_meta() functions

The delete_all parameter allows you to delete all meta items matching the
specified meta_key, regardless of the associated object.

Because our meta delete functions also support the deletion of all metadata
associated with an object (by leaving out the meta_key param), a decision had
to be made regarding the behavior when _delete_meta() is called with delete_all

true and meta_key = false. The most logical (and least destructive) strategy

was deemed to be: force delete_all to false when meta_key is also false. This
ensures that you don't accidentally wipe out all metadata for a component.

See #5400

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r7879 r7883  
    539539 * Delete a meta entry from the DB for an activity stream item.
    540540 *
    541  * @since BuddyPress (1.2)
     541 * @since BuddyPress (1.2.0)
    542542 *
    543543 * @global object $wpdb WordPress database access object.
    544544 * @global object $bp BuddyPress global settings.
    545  * @uses wp_cache_delete()
    546  * @uses is_wp_error()
    547545 *
    548546 * @param int $activity_id ID of the activity item whose metadata is being deleted.
    549547 * @param string $meta_key Optional. The key of the metadata being deleted. If
    550  *                         omitted, all metadata associated with the activity
    551  *                         item will be deleted.
     548 *        omitted, all metadata associated with the activity
     549 *        item will be deleted.
    552550 * @param string $meta_value Optional. If present, the metadata will only be
    553  *                           deleted if the meta_value matches this parameter.
     551 *        deleted if the meta_value matches this parameter.
     552 * @param bool $delete_all Optional. If true, delete matching metadata entries
     553 *    for all objects, ignoring the specified object_id. Otherwise,
     554 *    only delete matching metadata entries for the specified
     555 *    activity item. Default: false.
    554556 * @return bool True on success, false on failure.
    555557 */
    556 function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '' ) {
     558function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
    557559    global $wpdb, $bp;
    558560
     
    572574        $all_meta = bp_activity_get_meta( $activity_id );
    573575        $keys     = ! empty( $all_meta ) ? wp_list_pluck( $all_meta, 'meta_key' ) : array();
     576
     577        // With no meta_key, ignore $delete_all
     578        $delete_all = false;
    574579    } else {
    575580        $keys = array( $meta_key );
     
    578583    add_filter( 'query', 'bp_filter_metaid_column_name' );
    579584    foreach ( $keys as $key ) {
    580         $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value );
     585        $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value, $delete_all );
    581586    }
    582587    remove_filter( 'query', 'bp_filter_metaid_column_name' );
Note: See TracChangeset for help on using the changeset viewer.