comment_type) && $comment->comment_type === 'order_note') { return true; } // Skip WooCommerce order notes which are stored as comments $post = get_post($comment->comment_post_ID); if ($post && ($post->post_type === 'shop_order' || $post->post_type === 'shop_order_placehold')) { return true; } return false; } /** * Check if this comment has already been logged recently. * * @since 1.0.0 * @param int $comment_id Comment ID. * @param string $action Action being logged. * @return boolean True if this comment has been logged recently, false otherwise. */ private function is_duplicate_log($comment_id, $action) { $transient_key = 'actlogpro_comment_log_' . $comment_id . '_' . $action; $logged = get_transient($transient_key); if ($logged) { return true; } // Set transient to prevent duplicate logging (expires in 5 seconds) set_transient($transient_key, true, 5); return false; } /** * Log comment creation event. * * @since 1.0.0 * @param int $comment_id Comment ID. * @param WP_Comment $comment Comment object. */ public function comment_created($comment_id, $comment) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'created')) { return; } // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'created', /* translators: %s: Post title */ sprintf(__('New comment added to "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title, 'comment_status' => $comment->comment_approved ) ); } /** * Log comment update event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_updated($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'updated')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'updated', /* translators: %s: Post title */ sprintf(__('Comment updated on "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title, 'comment_status' => $comment->comment_approved ) ); } /** * Log comment status change event. * * @since 1.0.0 * @param string $new_status New comment status. * @param string $old_status Old comment status. * @param WP_Comment $comment Comment object. */ public function comment_status_changed($new_status, $old_status, $comment) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } // Map status to action $status_map = array( '0' => 'unapproved', '1' => 'approved', 'spam' => 'spammed', 'trash' => 'trashed' ); // Only log if status actually changed if ($new_status === $old_status) { return; } // Check for duplicate logs $action = isset($status_map[$new_status]) ? $status_map[$new_status] : 'status_changed'; if ($this->is_duplicate_log($comment->comment_ID, $action)) { return; } // Get human-readable status names $new_status_name = isset($status_map[$new_status]) ? $status_map[$new_status] : $new_status; $old_status_name = isset($status_map[$old_status]) ? $status_map[$old_status] : $old_status; ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment->comment_ID, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), $action, /* translators: 1: Old status, 2: New status, 3: Post title */ sprintf(__('Comment status changed from %1$s to %2$s on "%3$s"', 'activity-log-pro'), $old_status_name, $new_status_name, $post->post_title ), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title, 'old_status' => $old_status, 'new_status' => $new_status ) ); } /** * Log comment trashed event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_trashed($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'trashed')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'trashed', /* translators: %s: Post title */ sprintf(__('Comment moved to trash on "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title ) ); } /** * Log comment untrashed event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_untrashed($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'untrashed')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'untrashed', /* translators: %s: Post title */ sprintf(__('Comment restored from trash on "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title ) ); } /** * Log comment marked as spam event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_spammed($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'spammed')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'spammed', /* translators: %s: Post title */ sprintf(__('Comment marked as spam on "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title ) ); } /** * Log comment unmarked as spam event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_unspammed($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'unspammed')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'unspammed', /* translators: %s: Post title */ sprintf(__('Comment unmarked as spam on "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'comment_content' => wp_trim_words($comment->comment_content, 20), 'post_id' => $post->ID, 'post_title' => $post->post_title ) ); } /** * Log comment deletion event. * * @since 1.0.0 * @param int $comment_id Comment ID. */ public function comment_deleted($comment_id) { // Check if comment event tracking is enabled if (!$this->is_tracking_enabled()) { return; } // Check for duplicate logs if ($this->is_duplicate_log($comment_id, 'deleted')) { return; } $comment = get_comment($comment_id); // Skip WooCommerce order notes if ($this->is_woocommerce_order_note($comment)) { return; } $post = get_post($comment->comment_post_ID); if (!$post) { return; } ACTLOGPRO_Logger::log_activity( 'comment', 'comment', $comment_id, /* translators: %s: Post title */ sprintf(__('Comment on "%s"', 'activity-log-pro'), $post->post_title), 'deleted', /* translators: %s: Post title */ sprintf(__('Comment permanently deleted from "%s"', 'activity-log-pro'), $post->post_title), array( 'comment_author' => $comment->comment_author, 'post_id' => $post->ID, 'post_title' => $post->post_title ) ); } }