Support » Plugin: WP-Activity » [RESOLVED] Activity logged as POST_ADD instead of POST_EDIT

  • For WP_Activity v2.0, when editing posts, I noticed that POST_ADD activities were logged instead of POST_EDIT. I am not sure if this is due to WordPress keeping a version history (and stores an edited page in its entirety, hence calling it a ‘new’ post)

    I made some modifications to the code that worked for me. Feel free to use, but it will be on your own risk 🙂

    Replace act_post_add function in File: wp-activity.php

    function act_post_add($act_post) {
        global $wpdb, $user_ID, $options_act;
    	$posttype = "POST_ADD";
    	$sql = "SELECT COUNT(*) as numEdits FROM ".$wpdb->prefix."activity WHERE act_params = '". $act_post."'";
    	$results = $wpdb->get_results($sql);
    	foreach ($results as $post)
    	{ $numEdits = $post->numEdits;
    	  if (($numEdits)>1)
    	    $posttype = "POST_EDIT";
        if (!get_usermeta($user_ID, 'act_private')) {
            $act_time=current_time('mysql', true);
            $wpdb->query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID, '".$posttype."', '".$act_time."', $act_post)");

    I wrote also small php script to correct older entries. Again, use at your own risk 🙂

    File: correctme.php

    global $wpdb, $table_prefix;
        $posttype = "POST_EDIT";
    	$sql = "SELECT id, act_params AS postid FROM ".$wpdb->prefix."activity WHERE act_type = 'POST_ADD' GROUP BY act_params ORDER BY id ASC";
        echo "Main query:".$sql."<BR>";
    	$results = $wpdb->get_results($sql);
    	foreach ($results as $post)
    	{ $act_id = $post->id;
    	  $postid = $post->postid;
    	  $sql = "UPDATE ".$wpdb->prefix."activity SET act_type = 'POST_EDIT' WHERE act_params = '".$postid."' AND id != '".$act_id."'";
    	  echo "  post_id: ".$postid." (acivitylog entry: ".$act_id.") - PAUSED SQL:".$sql."<BR>";

    Just copy this into a php/text file and place it within in the WP-Activity plugin folder:

    Then, direct your browser to fix the old entries:

  • The topic ‘[RESOLVED] Activity logged as POST_ADD instead of POST_EDIT’ is closed to new replies.