=== Carlos Sánchez Link Analyzer ===
Contributors: carlossanchezprof
Tags: internal links, broken links, seo, interlinking, link manager
Requires at least: 6.0
Tested up to: 6.9
Stable tag: 2.0.0
Requires PHP: 8.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Analyze all internal and external links across your site. Detect orphan pages, broken links, and automate internal linking with the built-in Link Manager.

== Description ==

**Carlos Sánchez Link Analyzer** is a comprehensive link analysis and internal linking tool for WordPress. It scans your entire site to map outgoing and incoming links, identifies orphan pages with zero inbound links, detects broken links (404, 301/302, connection errors), and includes a powerful Link Manager to automate internal linking and URL replacement.

= Key Features =

**Link Analysis**

* Quick Scan: Reads rendered post_content (blocks, shortcodes, page builders) to extract all links.
* Deep Scan: Visits each URL via wp_remote_get to capture the fully rendered HTML, including theme elements, widgets, sidebars, and footer links.
* Tracks internal outgoing, internal incoming, and external outgoing links per page.
* Identifies orphan pages (pages with zero internal incoming links).
* Anchor text extraction for every link found.
* Filter by post type, search by title/URL, and export results to CSV.
* Configurable User-Agent, timeout, delay, and batch size for deep scans.
* Built-in URL diagnostic tool to troubleshoot fetch issues.

**Broken Link Checker**

* Verifies HTTP status of all outgoing links found during analysis.
* Detects 404 errors, redirects (301/302), timeouts, and connection failures.
* Shows which posts link to each broken URL along with anchor texts.
* Filter by external-only links.
* Configurable batch size and timeout.

**Link Manager — Term Linker**

* Scan your content for unlinked keyword occurrences.
* Automatically wrap matching text in links with four application modes:
  * **Buffer** — Applies via the_content filter. Fully reversible.
  * **JS outerHTML** — Injects links via JavaScript in the footer. Invisible to crawlers. Reversible.
  * **JS Obfuscated** — Same as JS but with base64 encoding for anti-scraping. Reversible.
  * **Database** — Permanently modifies post_content. Not reversible.
* Options: case sensitivity, whole word matching, max links per page, nofollow, target _blank.
* Excludes headings, existing links, code blocks, `<head>`, `<iframe>`, `<script>`, `<style>`, and `<textarea>`.
* Date range filtering for scans.

**Link Manager — URL Replacer**

* Find all `<a href="...">` pointing to a specific URL and replace the destination.
* Detects absolute URLs, relative paths, and protocol variants (http/https).
* Same four application modes as the Term Linker: Buffer, JS, JS Obfuscated, and Database.
* Global replacement option — applies to all pages without a prior scan.
* Full-page output buffering to replace links in headers, sidebars, footers, and widgets.

**Multilingual Support**

* Compatible with Polylang, WPML, and TranslatePress.
* Filter scans and rules by language.
* Rules automatically apply only to posts in the matching language.

**Rule Management**

* View, toggle (pause/resume), and delete saved rules.
* Switch between reversible modes (Buffer ↔ JS ↔ JS Obfuscated).
* Apply existing rules to database permanently.
* Filter rules by type, mode, status, scope, and search term.
* Pagination for large rule sets.

= Use Cases =

* **SEO professionals** analyzing internal link structure and PageRank distribution.
* **Content managers** finding and fixing orphan pages.
* **Site administrators** detecting and resolving broken links.
* **Agencies** automating internal linking at scale across multilingual sites.

== Installation ==

1. Upload the `sd-link-analyzer` folder to the `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Navigate to **Link Analyzer** in the admin sidebar to access the Link Analyzer.
4. Use the **Análisis** submenu for link scanning and broken link detection.
5. Use the **Link Manager** submenu to set up automatic term linking and URL replacement rules.

== Frequently Asked Questions ==

= What is the difference between Quick Scan and Deep Scan? =

**Quick Scan** renders each post's content using WordPress filters (blocks, shortcodes, page builders) and extracts links from the resulting HTML. It is fast but only sees the main content area.

**Deep Scan** visits each URL via HTTP request (wp_remote_get) to download the fully rendered page, capturing links from the theme, menus, sidebars, footer, and widgets. It takes longer but provides a complete picture.

= Will the Link Manager modify my posts permanently? =

Only if you choose the **Database** mode. The other three modes (Buffer, JS outerHTML, and JS Obfuscated) are fully reversible — they apply links at runtime without touching your database. You can pause or delete these rules at any time.

= Does it work with page builders like Elementor or WPBakery? =

Yes. The Quick Scan uses `apply_filters('the_content', ...)` which renders output from most page builders. The Deep Scan fetches the fully rendered HTML page, so it captures everything regardless of the builder used.

= Can I use it on multilingual sites? =

Yes. The plugin automatically detects Polylang, WPML, or TranslatePress and allows you to filter scans and rules by language. Rules are applied only to posts in the matching language.

= What happens if a security plugin blocks the deep scan? =

Try changing the User-Agent in the scan settings to a real browser string (Chrome or Firefox). You can also use the built-in URL diagnostic tool to test a specific URL and identify the issue.

= Does the broken link checker slow down my site? =

No. The broken link checker runs on-demand from the admin panel. It does not run automatically or in the background on the frontend.


== Changelog ==

= 2.0.0 =
* Rebranded as Carlos Sánchez Link Analyzer (sanchezdonate.net). New folder, text domain and identifiers (`sd-*`).
* One-time migration of saved analysis, broken-link results and Link Manager rules from the 1.x option keys.
* Admin UI restyled to the brand guide v0.2: Archivo, Literata and JetBrains Mono (self-hosted), lila palette, single primary action per screen.
* Update manifest now served from sanchezdonate.net.

= 1.5.3 =
* Improved anchor text extraction for internal and external links.
* Added date range filtering for Term Linker and URL Replacer scans.
* Bug fixes and performance improvements.

= 1.5.2 =
* Added full-page output buffering for URL replace rules in buffer mode.
* URL replacer now catches links in headers, sidebars, footers, and widgets.
* Improved URL variant matching (relative paths, protocol alternation).

= 1.5.1 =
* Added multilingual support: Polylang, WPML, TranslatePress.
* Rules can be filtered and applied by language.
* Scan results include language column when a multilingual plugin is detected.

= 1.5.0 =
* New Link Manager module with Term Linker and URL Replacer.
* Four application modes: Buffer, JS outerHTML, JS Obfuscated, Database.
* Rule management: toggle, delete, change mode, apply to database.
* Filters and pagination for saved rules.

= 1.4.0 =
* Added Broken Links tab with HTTP status verification.
* Anchor text support in link analysis.
* CSV export functionality.

= 1.3.0 =
* Deep Scan mode with configurable User-Agent, timeout, delay, and batch size.
* URL diagnostic tool for troubleshooting fetch issues.
* Non-content element stripping (admin bar, Query Monitor, etc.).

= 1.2.0 =
* Post type filtering (include/exclude) for scans.
* Slug exclusion support.
* Improved link extraction with dual regex + DOMDocument approach.

= 1.1.0 =
* Incoming link tracking and orphan page detection.
* Sort and filter results by post type, search term, and orphan status.

= 1.0.0 =
* Initial release.
* Quick Scan for internal and external link analysis.

== Upgrade Notice ==

= 2.0.0 =
Folder and option keys change. Activate the new plugin once; saved rules and results are migrated automatically.

= 1.5.3 =
Improved anchor text extraction and added date range filtering for Link Manager scans.