# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a WordPress plugin called "Adminify Activity Logs" that tracks and records all user activities within the WordPress dashboard. It's designed as a free monitoring tool for maintaining security, accountability, and transparency across WordPress sites.

## Architecture

### Plugin Structure

The plugin follows WordPress plugin conventions with PSR-4 autoloading and uses the following namespace structure:
- Main namespace: `JLTAdminify\Modules\ActivityLogs`
- Sub-namespaces for different components (Inc, Libs, Hooks)

### Key Components

1. **Main Entry Points**
   - `adminify-activity-logs.php`: Plugin bootstrap file, defines constants and initializes the plugin
   - `loader.php`: Loads the main plugin class
   - `class-adminify-activity-logs.php`: Main plugin class that coordinates all components

2. **Core Modules**
   - `Inc/ActivityLogs/Module_ActivityLogs.php`: Core module that manages the activity logging functionality, admin menu, and list table display
   - `Inc/ActivityLogs/Inc/DB_Table.php`: Handles database table creation and management for storing activity logs
   - `Inc/ActivityLogs/Inc/Api.php`: API layer for interacting with the activity logs database
   - `Inc/ActivityLogs/Inc/Hooks.php`: Manages WordPress hooks for tracking various activities

3. **Hook System**
   - `Inc/ActivityLogs/Hooks/`: Contains specialized hook classes for different WordPress components:
     - `Adminify_Logs_Core.php`: Core WordPress actions
     - `Adminify_Logs_Plugins.php`: Plugin-related activities
     - `Adminify_Logs_Taxonomy.php`: Taxonomy operations
     - `Adminify_Logs_Theme.php`: Theme-related activities
     - `WP_Adminify_Logs_Attachments.php`: Media/attachment tracking

4. **Database**
   - Table name: `{prefix}_adminify_activity_logs`
   - Stores activity logs with user, IP, action type, and timestamp information
   - Default retention period: 30 days (configurable)

## Development Commands

### Dependency Management

```bash
# Install PHP dependencies (Composer)
composer install

# Update PHP dependencies
composer update
```

### Testing the Plugin

1. **Local WordPress Setup**: This plugin requires a working WordPress installation. Based on the directory structure, it appears to be running in Local Sites.

2. **Activation**: Activate the plugin through WordPress admin panel or WP-CLI:
   ```bash
   wp plugin activate adminify-activity-logs
   ```

3. **Database Setup**: The plugin automatically creates its database table on activation via the `DB_Table::activation_hook()` method.

### Version Control

The project uses Git with the current branch being `wporg` and the main branch being `main`. When creating pull requests, target the `main` branch.

## Key Constants

The plugin defines several constants for paths and URLs:
- `ACTIVITYLOGS`: Plugin name
- `ACTIVITYLOGS_VER`: Plugin version
- `ACTIVITYLOGS_DIR`: Plugin directory path
- `ACTIVITYLOGS_PATH`: Plugin path with trailing slash
- `ACTIVITYLOGS_URL`: Plugin URL
- `ACTIVITYLOGS_INC`: Include directory path
- `ACTIVITYLOGS_ASSETS`: Assets URL

## Integration Points

### Freemius SDK
The plugin integrates with Freemius SDK for licensing and analytics (though configured as a free plugin). The SDK is loaded conditionally based on the presence of the parent Adminify plugin.

### WordPress Hooks
The plugin extensively uses WordPress action and filter hooks to track activities:
- User login/logout
- Post/page creation, updates, deletion
- Plugin activation/deactivation
- Theme changes
- Taxonomy operations
- Media uploads

### Admin Interface
- Creates a top-level menu item "Activity Logs" in the WordPress admin
- Uses WordPress List Table API for displaying logs
- Includes filtering capabilities by user role, time period, and action type

## Important Considerations

1. **Parent Plugin Dependency**: While the plugin can work standalone, it's designed to integrate with the WP Adminify plugin ecosystem.

2. **Database Performance**: The plugin automatically cleans up old logs based on the retention period to maintain database performance.

3. **User Capabilities**: Most administrative functions require `manage_options` capability.

4. **AJAX Operations**: The plugin uses WordPress AJAX for saving settings like log retention days, with proper nonce verification.

5. **Multisite Compatibility**: The plugin is configured to work with WordPress multisite installations.

## Code Style

- Uses WordPress coding standards
- PHP 7.0+ features
- Proper escaping and sanitization following WordPress security best practices
- Internationalization ready with text domain `adminify-activity-logs`