Skip to content

TaxConsultingZA/LinkDoctor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkDoctor AI - WordPress Link Health Management Plugin

Project Overview

LinkDoctor AI is a professional WordPress link health management plugin that provides comprehensive link scanning, detection, repair, and logging capabilities.

Core Features

  • Link Scanning: Automatically extract all links from post content
  • HTTP Detection: Supports Level 1 (fast detection) and Level 2 (browser-mode re-check)
  • Smart Classification: Automatically identify OK, redirect, 404, DNS failure, SSL error, and other statuses
  • One-Click Repair: Supports Unlink (remove link), Wayback Machine snapshot replacement, redirect repair
  • Auto-Fix: Configurable scheduled tasks for automatic link repair with priority strategies
  • Action Logs: Complete logging of all repair operations (manual/auto), supporting audit trails

Requirements

  • WordPress 6.2+
  • PHP 8.0+
  • MySQL 5.7+ / MariaDB 10.3+

Installation

Option 1: Direct Installation

  1. Upload the wp-content/plugins/linkdoctor-ai/ directory to your WordPress wp-content/plugins/ directory
  2. Activate "LinkDoctor AI" in the WordPress admin "Plugins" page
  3. Required database tables will be created automatically upon activation

Option 2: Docker Local Development

# Start WordPress environment
docker-compose up -d

# Access WordPress
# http://localhost:8080

User Guide

Admin Menu

After plugin activation, a "LinkDoctor AI" menu will appear in the WordPress admin sidebar with the following submenus:

Menu Description
Dashboard Dashboard showing link statistics, health score, quick actions
Links Link list, view all links and their statuses, perform repairs
Logs Action logs, view repair history
Settings Settings page, configure scan scope and auto-fix options

Basic Workflow

  1. Configure Scan Scope (Settings)

    • Select post types to scan (posts, pages, etc.)
    • Select post statuses to scan (published, draft, etc.)
  2. Scan Links (Links page)

    • Click "Scan All Published Posts" to scan all posts and extract links
  3. Check Links (Links page)

    • Click "Run Full Check" for complete detection (Level 1 + Smart Re-check)
    • Or run step by step: first "Level 1 Check", then "Smart Re-check"
  4. Repair Links

    • Manual Repair: Perform Unlink / Wayback / Fix Redirect on individual links in the list
    • Batch Repair: Click "Run Auto-Fix Now" for batch repair based on settings

Link Status Reference

Status Description
pending Pending check
ok OK (HTTP 2xx)
redirect Redirect (HTTP 3xx)
broken_404 404 Not Found
broken_410 410 Gone
broken_4xx Other 4xx errors
probation_5xx Server error (HTTP 5xx), possibly temporary
probation_timeout Timeout, possibly temporary
dns_failed DNS resolution failed
ssl_error SSL/TLS certificate error
connection_failed Connection failed
network_error Network error
fixed_redirect Fixed (redirect)
fixed_wayback Fixed (Wayback snapshot - manual)
fixed_wayback_auto Fixed (Wayback snapshot - auto)
fixed_unlinked Unlinked (manual)
fixed_unlinked_auto Unlinked (auto)
unlinked Unlinked (legacy compatibility)

Auto-Fix Settings

The following auto-fix options can be configured on the "Settings" page:

Option Description
Auto-Fix Redirects (301/308) Automatically update permanent redirect links to their final URL
Auto-Fix with Wayback Machine Automatically replace all broken links with Wayback Machine snapshots (will try to create snapshot if none exists)
Batch Size Number of links to process per auto-fix run (1-100)

Note: The Auto-Unlink option has been deprecated. When Wayback repair fails, links will remain in their original state for manual review and will not be automatically unlinked. Manual Unlink is still available on the Links page.

Auto-Fix Priority

When clicking "Run Auto-Fix Now" or when scheduled tasks run, processing follows this priority order:

Priority 1: Fix 301/308 redirects
    ↓
    For links with status = 'redirect' and http_code IN (301, 308)
    → Update to final redirect URL
    → Status changes to fixed_redirect

Priority 2: Wayback repair (all non-OK status links, including internal/external)
    ↓
    For links with status not in pending/ok/redirect/fixed
    → First check if Wayback snapshot exists
    → If no snapshot, try to create one via SavePageNow
    → Replace link after successfully getting/creating snapshot
    → Status changes to fixed_wayback_auto
    → On failure: keep original status for manual review

Important Change: When Wayback repair fails, auto-unlink is no longer performed. This prevents accidental deletion of valuable links and allows administrators to handle them manually.

Auto-fix tasks run hourly via WordPress Cron, or can be triggered manually from the Links page.


Manual Repair Actions

On the Links list page, each link record has the following action buttons in the Actions column:

Button Display Condition Description
Edit Always shown Jump to edit post page
Open Always shown Open link URL in new tab
Fix Redirect 301/308 redirect links Update link to final redirect URL
Unlink Non-fixed links Remove href attribute, preserve anchor text
Wayback Non-fixed links Replace link URL with Wayback Machine snapshot

For broken links (404/410, etc.), the Wayback button is displayed with blue highlight.


Database Table Structure

The following database tables are created when the plugin is activated:

wp_linkdoctor_links (Main Links Table)

Stores all links extracted from posts and their detection status.

Field Type Description
id bigint Primary key
post_id bigint Associated post ID
post_type varchar Post type
post_title varchar Post title
url text Link URL
url_hash char(32) MD5 hash of URL
anchor_text text Anchor text
domain varchar Link domain
is_internal tinyint Whether internal link
status varchar Link status
http_code int HTTP response code
error_type varchar Error type
redirect_final_url text Final redirect URL
wayback_snapshot_url text Wayback snapshot URL
wayback_snapshot_time varchar Wayback snapshot time
last_checked_at datetime Last check time
first_seen_at datetime First seen time

wp_linkdoctor_actions (Action Logs Table)

Records all repair operations, supporting audit and rollback.

Field Type Description
id bigint Primary key
link_id bigint Associated link ID
action_type varchar Action type (see below)
old_value longtext Value before operation
new_value longtext Value after operation
acted_by varchar Actor (user ID or 'system')
acted_at datetime Action time
batch_id varchar Batch ID

Action Types (action_type)

action_type Description
use_wayback Manual Wayback repair
wayback_auto Auto Wayback repair
unlink Manual Unlink
unlink_auto Auto Unlink
fix_redirect Manual redirect fix
fix_redirect_auto Auto redirect fix
auto_fix_batch Auto-fix batch summary

Code Structure

wp-content/plugins/linkdoctor-ai/
├── linkdoctor-ai.php          # Main plugin file
└── src/
    ├── Admin/                 # Admin pages
    │   ├── DashboardPage.php  # Dashboard page
    │   ├── LinksPage.php      # Links list page
    │   ├── LogsPage.php       # Logs page
    │   ├── Menu.php           # Menu registration
    │   ├── PostColumns.php    # Post list links column
    │   └── SettingsPage.php   # Settings page
    ├── Core/                  # Core functionality
    │   ├── AutoFixer.php      # Auto-fix engine (priority scheduling)
    │   ├── Classifier.php     # Status classifier
    │   ├── Fixer.php          # Link fixer (Unlink/Redirect)
    │   ├── HttpChecker.php    # HTTP checker
    │   ├── Installer.php      # Database installer
    │   ├── LinkExtractor.php  # Link extractor
    │   ├── LinkRepository.php # Link data repository
    │   ├── Logger.php         # Action logger
    │   ├── Scanner.php        # Batch scanner
    │   └── WaybackService.php # Wayback repair service
    └── Services/              # External services
        ├── Settings.php       # Settings manager
        └── WaybackClient.php  # Wayback Machine API client

Core Class Responsibilities

Class Responsibility
WaybackService Encapsulates Wayback repair logic, supports manual/auto modes
AutoFixer Auto-fix engine, implements priority scheduling logic
Fixer Executes specific repairs (unlink/redirect/wayback)
LinkRepository Database CRUD operations, provides various query methods
WaybackClient Calls Wayback Machine API to get snapshots

Docker Setup

The project includes docker-compose.yml for local development:

  • WordPress: http://localhost:8080
  • phpMyAdmin: http://localhost:8081
# Start services
docker-compose up -d

# Stop services
docker-compose down

# View logs
docker-compose logs -f wordpress

Changelog

v0.2.0

  • Added WaybackService class to unify Wayback repair logic
  • Refactored auto-fix engine with priority scheduling: 301/308 → Wayback → Unlink
  • Differentiated manual/auto operation statuses and logs (fixed_wayback vs fixed_wayback_auto)
  • Added get_external_broken_links_for_auto_fix() query method
  • Optimized logging with mode field to identify operation source

v0.1.0

  • Initial release
  • Implemented core link scanning, detection, and repair functionality
  • Supports Level 1 and Level 2 HTTP detection
  • Integrated Wayback Machine API
  • Complete admin interface
  • Action logging feature
  • Auto-fix scheduled tasks

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%