Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions assets/js/src/front_link_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ const getRenderedLinks = () => {
});
}

// Look for all script tags with '__iawmlf-post-loop-links' class
const loopLinks = document.querySelectorAll('script.__iawmlf-post-loop-links');
// Look for all loop data nodes with '__iawmlf-post-loop-links' class
const loopLinks = document.querySelectorAll('.__iawmlf-post-loop-links[data-iawmlf-links]');

// Get the links from the script tag content
// Get the links from the loop data attribute.
loopLinks.forEach((loopLink) => {
const links = JSON.parse(loopLink.textContent);
addLinks(links);
try {
const links = JSON.parse(loopLink.getAttribute('data-iawmlf-links'));
addLinks(links);
} catch (e) {
// Do nothing.
}
});


Expand Down
6 changes: 3 additions & 3 deletions internet-archive-wayback-machine-link-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* The wayback-link-fixer bootstrap file.
*
* @since 1.0.0
* @version 1.4.0
* @version 1.4.1
* @author Internet Archive
* @license GPL-3.0-or-later
*
Expand All @@ -12,7 +12,7 @@
* @wordpress-plugin
* Plugin Name: Internet Archive Wayback Machine Link Fixer
* Description: This plugin scans your content for links, replacing broken ones with archived versions from the Wayback Machine. It also features Auto Archiving, which automatically creates snapshots of your own pages and any other links on your site that aren’t yet archived, ensuring long-term accessibility.
* Version: 1.4.0
* Version: 1.4.1
* Requires at least: 6.4
* Tested up to: 7.0
* Requires PHP: 7.4
Expand All @@ -30,7 +30,7 @@
define( 'IAWMLF_BASENAME', plugin_basename( __FILE__ ) );
define( 'IAWMLF_PATH', plugin_dir_path( __FILE__ ) );
define( 'IAWMLF_URL', plugin_dir_url( __FILE__ ) );
define( 'IAWMLF_VERSION', '1.4.0' );
define( 'IAWMLF_VERSION', '1.4.1' );
define(
'IAWMLF_MINIMUM_VERSIONS',
array(
Expand Down
95 changes: 59 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wayback-link-fixer",
"version": "1.4.0",
"version": "1.4.1",
"description": "A WordPress plugin that scans content for links, replacing broken ones with archived versions from the Wayback Machine. It also features Auto Archiving, creating snapshots of your own pages and other site links that aren’t yet archived. Uses Action Scheduler for background tasks.",
"author": {
"name": "WordPress.com Special Projects Team",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: waybackmachineplugin, wpspecialprojects, cagrimmett, glynnquelch
Tags: wayback machine, internet archive, broken links, archive links
Requires at least: 6.4
Tested up to: 6.9
Stable tag: 1.4.0
Stable tag: 1.4.1
Requires PHP: 7.4
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -116,6 +116,9 @@ The Internet Archive is a non-profit organization dedicated to preserving digita

== Changelog ==

= 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.
Expand Down
7 changes: 4 additions & 3 deletions src/WP_Post/WP_Post_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,11 @@ public function render_block( string $block_content, array $block ): string { //
return $block_content;
}

$json = wp_json_encode( $links, JSON_HEX_TAG );
$html_data = "<script type='application/json' class='__iawmlf-post-loop-links'>{$json}</script>";
// Encode with all JSON_HEX_* flags.
$json = wp_json_encode( $links, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT );
$html_data = '<span hidden class="__iawmlf-post-loop-links" data-iawmlf-links="' . esc_attr( $json ) . '"></span>';

return $html_data . $block_content;
return $block_content . $html_data;
}

/**
Expand Down
Loading
Loading