# CLAUDE.md

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

## Project Overview

WP-Short.io is a WordPress plugin that integrates with the Short.io URL shortening service. It automatically generates short links for WordPress posts, pages, and custom post types.

## Architecture

### Core Components

- **Main Plugin File**: `wp-shortcm.php` - Entry point and main controller class `WP_Shortcm` (singleton pattern)
- **Admin Interface**: `includes/class.wp-shortcm-admin.php` - Handles WordPress admin settings and UI
- **Helper Functions**: `includes/functions.php` - Core functionality for shortlink generation and API communication

### Key Classes and Functions

- `WP_Shortcm`: Main singleton controller class that manages options, includes files, and sets up hooks
- `shortcm_generate_shortlink()`: Creates shortlinks via Short.io API
- `shortcm_get_shortlink()`: Retrieves existing shortlinks or generates new ones
- `shortcm_request()`: Wrapper for WordPress HTTP API to communicate with Short.io

### Data Storage

- Plugin options stored in WordPress database as `shortcm-options`
- Individual shortlinks stored as post meta with key `_shortcm`
- Debug logs written to `log/debug.txt` when debug mode enabled

## Development Commands

### Build and Package

```bash
# Build plugin package for distribution
make build

# Clean build artifacts
make clean
```

The build process:
1. Copies files to `_build` directory (excludes .git and existing builds)
2. Creates `wp-shortcm.zip` package
3. Syncs to `../wp-shortcm/trunk` for WordPress SVN repository

## API Integration

The plugin communicates with Short.io API endpoints:
- Base URL: `https://api.short.io`
- Authentication: Uses API key passed in Authorization header
- Main endpoint: `/links` for creating shortlinks

## WordPress Integration Points

- Hooks into `save_post` action to generate shortlinks
- Filters `pre_get_shortlink` to provide shortlinks to WordPress
- Adds admin column "Short URL" to posts list
- Provides `[shortcm]` shortcode for embedding shortlinks
- Integrates with admin bar shortlink menu