=== Internet Archive Wayback Machine Link Fixer ===
Contributors: waybackmachineplugin, wpspecialprojects, cagrimmett, glynnquelch
Tags: wayback machine, internet archive, broken links, archive links
Requires at least: 6.4
Tested up to: 7.1
Stable tag: 1.5.0
Requires PHP: 7.4
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Automatically fix broken links by replacing them with archived versions from the Internet Archive's Wayback Machine.

== Description ==

**Internet Archive Wayback Machine Link Fixer** is a WordPress plugin designed to combat **link rot**—the gradual decay of web links as pages are moved, changed, or taken down. It automatically scans your post content—on save and across existing posts—to detect outbound links. For each one, it checks the Internet Archive's Wayback Machine for an archived version and creates a snapshot if one isn't available.

When a linked page disappears, the plugin helps preserve your user experience by redirecting visitors to a reliable archived version. It also works proactively by archiving your own posts every time they're updated, creating a consistent backup of your content's history.

Protect your links, preserve your content, and automate the archiving process—all with minimal effort.

= Key Features =

* Automatically scans for outbound links in post content
* Checks the Wayback Machine for existing archives
* Creates new snapshots if no archive exists
* Redirects broken or missing links to archived versions
* Archives your own posts on updates
* Works on both new and existing content
* Helps maintain long-term content reliability and SEO

== Installation ==

The plugin stores its link data in a JSON column, so it requires MySQL 5.7 or later, or MariaDB 10.2 or later. Activation is blocked with an explanatory notice on anything older.

1. Upload the plugin folder to `/wp-content/plugins/`, or install it through the Plugins screen in WordPress.
2. Activate the plugin through the Plugins screen in WordPress.
3. A setup wizard opens on activation and walks you through choosing which post types to scan, whether to archive your own content, and how links should be handled.

The wizard can be run again at any time from the plugin's settings page.

An Archive.org account is not required, but adding your API keys on the settings page raises the number of snapshots you can create per day.

== Frequently Asked Questions ==

= How does the link checker work? =
Your content is checked for any links. When it finds a link it will check if we have already handled this link before, if not, it will find or create a snapshot of the webpage on the Internet Archive.
Then if later that link's target site goes offline, we can change the link to the archived version.

= How do we determine if a link is broken? =
We use a similar policy as Wikipedia. We check links once per week and if we get 3 consecutive errors, we treat the link as broken, unless the target website comes back.

= Can all links be handled? =
Sadly not, some sites do not allow the Internet Archive to archive their content.

= Is my own content archived? =
Yes, you can enable the Auto Archiver and this will create new snapshots every time you make changes.

= What happens to broken links? =
When we find a broken link, we update the src on the fly; this means the base content is not edited and remains as created.

= Why is a working link being reported as broken? =
Some websites block automated bots, so the checker can receive a "403 Forbidden" and flag the link as broken even though it works fine in a browser. If this happens you can exclude that single link from its report page, or add a URL rule (with a * wildcard) to the Link Exclusions setting to cover a whole domain.

= How long does this take? =
This all depends on how many links there are within your content. This is all handled in the background but can take many weeks if a site has thousands of links. It is best used as a tool you setup and leave running in the background.

= Does this add lots of overhead to my site? =
As this is all processed behind the scenes, in custom tables it should not add any noticeable overhead to your site.

= Do I need an archive.org api key? =
While you don't need one, it will greatly increase the number of snapshots you can create in a day.

= What happens if the Internet Archive goes offline? =
If the Internet Archive services go offline, the link fixer will delay all processes by 24 hours and try again later.

= How often are my own posts updated when auto archive is active? =
Existing content is sent to the Wayback Machine in batch when the plugin is activated, then again every 30 days (by default, but can be changed). New content is sent to be archived shortly after it is published. Updates to existing content also trigger updates to be sent to the Wayback Machine.

= Multisite Compatible? =
Sadly at present, it is not fully compatible. The only way it can currently be used on multisite is to only enable it site-wide and not network-wide. We plan to resolve this in a future release.

= Page builder plugins and custom fields support? =
Right now the plugin works best with the core block editor and we have some more work to do to support page builder plugins and custom fields.

== Screenshots ==

1. The Dashboard overview covering your current usage stats with the most recent checks and new links added.
2. Overview of links found within your site's content.
3. Help tab to explain the icons and the link table.
4. Link details, show information about the link, all checks and any posts they appear in.

== External Services ==

This plugin connects to external services provided by the Internet Archive to provide its core functionality. The following information details what data is sent, when, and why:

= Internet Archive Wayback Machine API (web.archive.org) =

**What the service is and what it is used for:**
The Internet Archive Wayback Machine is a digital archive of the World Wide Web. This plugin uses their API to check for existing archived versions of web pages, create new snapshots of pages, and verify the status of archiving jobs.

**What data is sent and when:**

- **System Status Check**: No personal data is sent. Used to verify if the Wayback Machine service is online.
- **User Account Validation**: When you configure an API key, your access key and secret key are sent in the Authorization header to validate your account and retrieve usage statistics (available snapshots, daily limits, etc.).
- **URL Archiving**: URLs from your website content are sent to create new snapshots in the Wayback Machine. This includes both external links found in your content and your own post URLs when auto-archiving is enabled.
- **Snapshot Status Checks**: Job IDs are sent to check the status of archiving requests.
- **Existing Snapshot Lookups**: URLs are sent to search for existing archived versions of web pages.

**Service Terms and Privacy Policy:**

- Terms of Service: [https://archive.org/about/terms.php](https://archive.org/about/terms.php)
- Privacy Policy: [https://archive.org/about/privacy.php](https://archive.org/about/privacy.php)

= Internet Archive Bot API (iabot-api.archive.org) =

**What the service is and what it is used for:**
This service checks if web pages are accessible and retrieves final URLs after redirects. It's used to determine if links are broken and need to be replaced with archived versions.

**What data is sent and when:**

- **Link Accessibility Checks**: URLs from your website content are sent to check if they are accessible and to get the final destination URL after any redirects.
- **Impersonation Parameter**: A technical parameter (`impersonate=1`) is sent to ensure proper link checking behavior.

**Service Terms and Privacy Policy:**

- Terms of Service: [https://archive.org/about/terms.php](https://archive.org/about/terms.php)
- Privacy Policy: [https://archive.org/about/privacy.php](https://archive.org/about/privacy.php)

= Internet Archive Wayback Availability API (archive.org) =

**What the service is and what it is used for:**
This API reports whether a URL already has a snapshot in the Wayback Machine. The plugin uses it to find the most recent snapshot for a link, and to find the snapshot closest to a given date.

**What data is sent and when:**

- **Existing Snapshot Lookups**: URLs from your website content are sent to check whether an archived version already exists, along with a date when looking for the closest snapshot to that date.
- **Account Credentials**: If you have configured an API key, your access key and secret key are sent in the Authorization header.

**Service Terms and Privacy Policy:**

- Terms of Service: [https://archive.org/about/terms.php](https://archive.org/about/terms.php)
- Privacy Policy: [https://archive.org/about/privacy.php](https://archive.org/about/privacy.php)

= Internet Archive Save Page Now Status API (web-wp.archive.org) =

**What the service is and what it is used for:**
This service reports the progress of a snapshot that has already been requested. The plugin uses it to find out whether a snapshot has completed, failed, or is still pending.

**What data is sent and when:**

- **Snapshot Status Checks**: The job ID returned when the snapshot was requested is sent to retrieve that job's current status. No personal data is sent.
- **Account Credentials**: If you have configured an API key, your access key and secret key are sent in the Authorization header.

**Service Terms and Privacy Policy:**

- Terms of Service: [https://archive.org/about/terms.php](https://archive.org/about/terms.php)
- Privacy Policy: [https://archive.org/about/privacy.php](https://archive.org/about/privacy.php)

**Data Retention and Privacy:**
The Internet Archive is a non-profit organization dedicated to preserving digital content for public access. URLs sent to these services become part of the public archive and may be accessible through the Wayback Machine interface. Apart from the Archive.org API credentials you choose to configure, no personal information beyond the URLs themselves is transmitted to these services.

== Changelog ==

= 1.5.0 =
* Security fixes around the archive.org credentials, the link check endpoint and admin access. See the upgrade notice.
* Adds a "Last Archived" column to the posts list, enabled from Screen Options.
* Now finds links inside shortcodes, dynamic blocks and international URLs, which were previously skipped.
* Fix: a stray line break at the end of Classic Editor posts.
* Fix: the auto archiver could push back its own queue and never run.
* Fix: Advanced Settings links shown to editors who cannot open it.
* Fix: Advanced Settings Link Icon row, post exclusion search and "%20" in link exclusion rules.
* Fix: Dashboard broken link count and onboarding with drafts or excluded posts.
* Fix: more broken link formats are now replaced, including on pages that list posts.
* The front end now checks at most 2 links at a time.
* Fix: links on sites that block the link checker (401, 403, 429 or 503) are no longer marked broken or replaced, and are flagged in the Links table instead.
* Redirects (300 to 308) no longer count as a failed check.
* medium.com, nytimes.com, udemy.com, kickstarter.com, player.fm, washingtonpost.com, reuters.com and perplexity.ai are added to the built-in exclusion list.
* Various fixes to the links report, link checking and the settings screen.
* Performance and accessibility improvements throughout the admin.
* Now requires MySQL 5.7 or MariaDB 10.2, checked on install.

= 1.4.3 =
* Adds a global set of excluded urls that will never be archived or checked due to the sites blocking the internet archive.
* Reintroduces a Scan but do nothing outcome for broken links.
* Fix: a non-200 response from the link checker is now treated as the service being offline and rescheduled, rather than marking a good link as broken.

= 1.4.2 =
* Fix: Manually excluded links sometimes revert to unexcluded and can still be run through the link checker process. Now fully respects manual exclusions.

= 1.4.1 =
* Fix: link data span now survives themes that wrap post content in `wp_kses_post` (previously the JSON could leak as visible text on category and archive templates).

= 1.4.0 =
* Changes to how we store link information in posts, now uses an escaped `<script>` tag.
* Move the frontend link checker from Ajax-driven to REST.
* Improvements to link table queries for better memory usage.
* Various small UI fixes.
* Added optional link icon displayed next to fixed links on the frontend, with before/after positioning and third-party extensibility via the `iawmlf_link_icons` filter.


= 1.3.6 =
* Allows posts to be selected to be excluded from link fixing and/or auto archiving.
* Improves cleanup of passed attempts to create and verify snapshots
* Adds an Archive.org donation notice.
* Improves translatable strings for betting internationalisation.

= 1.3.5 =
* Minor tweak to how we log errors in snapshot creation process.
* Improvement on how link stats are generated.
* Casts all archived urls to https://, can be disabled in settings.
* Improvements to how we handle cancelled scan own post actions, to prevent flooding database with cancelled jobs.

= 1.3.4 =
* Minor UI tweaks and changes
* Default check intervals and total count of broken pages required to trigger redirection lowered.
* Onboarding process streamlined.

= 1.3.3 =
* Fixes bug where the links and scripts were loaded even if set to do nothing
* Move to custom WP prefixed URLs
* Fixes various issues with the dashboard icons and counts
* Better handling of authentication issues and notices
* Detect staging sites and prevent auto archiving from running.
* Fixes bug where a missing auto archiving database option can result in posts still be indexed.

= 1.3.2 =
* Bugfix

= 1.3.1 =
* Makes various UI and UX changes around icons, tool tips and labels.
* Also fixes a few minor bugs regarding the settings and wizard flows.

= 1.3.0 =
* Initial public release.

Note: All versions prior to 1.3.0 were not publicly released.

== Developer Documentation ==

For developer docs and source code, see the GitHub repository: [https://github.com/a8cteam51/internet-archive-wayback-machine-link-fixer](https://github.com/a8cteam51/internet-archive-wayback-machine-link-fixer)

== Upgrade Notice ==

= 1.5.0 =
Security release. Fixes an unauthenticated request that could spend your archive.org credentials, stops the settings page printing those keys in its page source, and restores TLS verification on snapshot creation. Also fixes a stray line break at the end of Classic Editor posts. Now requires MySQL 5.7 or MariaDB 10.2.

= 1.4.3 =
Adds a bundled list of sites that block the Internet Archive, so they are never queued for archiving or checking. Also adds a "Check only" option, which checks links without redirecting them.

= 1.4.0 =
Changes how link data is stored in post content, and moves the frontend link checker from Ajax to the REST API.

= 1.3.0 =
This updates any pre-release version to the new launched version.


