I have a BuddyPress installation with many custom code.

I had everything ready for production until I moved my database to shared hosting.

The problem is that in strange ocasions, all the activities in wp_bp_activity gets deleted.

I'm not saying that this problem ocured because I moved my database, but I cant reproduce this bug with my original installation (but had the same problem when I compied hosting database to new installation on my local machine)

my details:

1) I don't beliave this DELETE is triggered with buddypress native code because everything staies as is in wp_bp_activity_meta.

2) I can't reproduce this bug and I can't understand when this happens. Also this does not happen often. maybe once or twice a day (or even once in two days). this is why it drives me crazy )

3) The most interesting, it deletes EVERYTHING except "like". I'm using bp-like-unlike compontent. It deletes everything: avatar_change, comments, activity, my own components but not bp-like which is just a copy of original (liked).

UPDATE: As @S_HA_DUM suggested I turned SQL debbuging on and found (in 500mb data) this request (no error from php side)

DELETE FROM wp_bp_activity WHERE item_id = 0 the only thing I found that queries to wp_bp_activitiy is delete function (someone named it this simple :D) in buddypress plugin.

but still can't find where this function is triggered

I want some suggestions how to debug this error. Any help is welcomed

  • 1
    If you can't debug this it is going to be hard for use to do so. The only suggestion I have is to log errors to a file and turn on SQL logging to see if you can find more clues.
    – s_ha_dum
    Nov 15 '13 at 15:50
  • I log everything except SQL, which sounds kind of good. thanks I'll try that
    – CBeTJlu4ok
    Nov 16 '13 at 8:28

Did you enable for debug in wp-config.php, you know, that is great for developing your theme define('WP_DEBUG', false);


I finally found an error and I will write it here

The problem was in my code: I was deleting activites with item_id being activity ID deleted. In other words I have a hook which is triggered after activity gets deleted where I delete "BuddyPress LIKE" activity (X Liked a Post).

But there is a cron job triggered by BBPress which deletes auto_draft posts (if any). and since BBPress can have an activity in BuddyPress, it also triggeres "DELETE_ACTIVITY", but in this case $activity_id is zero (I don't know, maybe because it does not exist and I'm hooking to early.

and that's where I get DELETE FROM wp_bp_activity WHERE item_id = 0

function clean_activity_dollars($activity){
    global $wpdb;
    $activity_table = $wpdb->prefix . 'bp_activity';
    $wpdb->delete($activity_table, array( 'item_id' => $activity['id'] ), array('%d'));

which I changed to this

$wpdb->delete($activity_table, array( 'item_id' => $activity['id'], 'type' => 'activity_liked' ), array('%d', '%s'));

so even if item_id is zero, it will check for type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.