activity_types = include plugin_dir_path( ATKAI_PLUGIN_FILE ) . '/activities/types.php'; $this->logger = $logger; add_action( 'wp_insert_comment', array( $this, 'atk_comment_log' ), 10, 2 ); add_action( 'edit_comment', array( $this, 'atk_comment_log' ) ); add_action( 'spam_comment', array( $this, 'atk_comment_log' ) ); add_action( 'unspam_comment', array( $this, 'atk_comment_log' ) ); add_action( 'trash_comment', array( $this, 'atk_comment_log' ) ); add_action( 'untrash_comment', array( $this, 'atk_comment_log' ) ); add_action( 'delete_comment', array( $this, 'atk_comment_log' ) ); add_action( 'transition_comment_status', array( $this, 'atk_transition_comment_status' ), 10, 3 ); } public function atk_transition_comment_status( $new_status, $old_status, $comment ) { $commenter_name = !empty( $comment->comment_author ) ? $comment->comment_author : $comment->comment_ID; if ( $old_status != $new_status ) { // Check if the comment was approved switch ( $new_status ) { case 'approve': case 'approved': $activity = 'approved'; $description = 'Comment Approved: by '. $commenter_name; break; case 'hold': case 'unapproved': $activity = 'unapproved'; $description = 'Comment Unapproved: by '. $commenter_name; break; case 'spam': $activity = 'spam'; $description = 'Comment Spammed: by '. $commenter_name; break; case 'trash': $activity = 'trash'; $description = 'Comment Trashed: by '. $commenter_name; break; case 'deleted': $activity = 'deletion'; $description = 'Comment Deleted: by '. $commenter_name; break; } $user_id = get_current_user_id(); // Get the current user ID $activity_type = $this->activity_types['comment'][$activity]; $this->logger->insert_log( $user_id, 'Comment', $activity_type, $description, $activity ); } } public function atk_comment_log( $comment_ID, $comment = null ) { if ( is_null( $comment ) ) { $comment = get_comment( $comment_ID ); } $commenter_name = !empty( $comment->comment_author ) ? $comment->comment_author : $comment_ID; $activity = 'creation'; $description = 'Comment Edit: by '. $commenter_name; switch ( current_filter() ) { case 'wp_insert_comment' : $activity = 1 === (int) $comment->comment_approved ? 'approved' : 'pending'; $description = 'Comment Creaded: by '. $commenter_name; break; case 'edit_comment' : $activity = 'edit'; $description = 'Comment Updated: by '. $commenter_name; break; case 'delete_comment' : $activity = 'deletion'; $description = 'Comment Deleted: by '. $commenter_name; break; case 'trash_comment' : $activity = 'trash'; $description = 'Comment Trashed: by '. $commenter_name; break; case 'untrash_comment' : $activity = 'untrash'; $description = 'Comment Untrashed: by '. $commenter_name; break; case 'spam_comment' : $activity = 'spam'; $description = 'Comment Spammed: by '. $commenter_name; break; case 'unspam_comment' : $activity = 'unspam'; $description = 'Comment Unspammed: by '. $commenter_name; break; } $activity_type = $this->activity_types['comment'][$activity]; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Comment', $activity_type, $description, $activity ); } }