WordPress.org

Forums

WP-Activity
[RESOLVED] Activity logged as POST_ADD instead of POST_EDIT (1 post)

  1. Dennis Maasbommel
    Member
    Posted 1 year ago #

    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

    <?php
    
    global $wpdb, $table_prefix;
    
    if(!isset($wpdb))
    {
        require_once('../../../wp-config.php');
        require_once('../../../wp-includes/wp-db.php');
    }
    
        $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>";
          $wpdb->query($sql);
        }
    ?>

    Just copy this into a php/text file and place it within in the WP-Activity plugin folder:
    \wordpress\htdocs\wp-content\plugins\wp-activity\correctme.php

    Then, direct your browser to fix the old entries:
    /wordpress/wp-content/plugins/wp-activity/correctme.php

    https://wordpress.org/plugins/wp-activity/

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP-Activity
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Dennis Maasbommel
  • This topic is not resolved
  • WordPress version: 3.8.1

Tags

No tags yet.