Skip to content

Commit

Permalink
Fix bugs with plaintext URLs at the end of a block.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvibber committed Jun 13, 2022
1 parent c979347 commit b82e80c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unwrap Shortlinks

Stable tag: 0.2.3
Stable tag: 0.2.4
Tags: urls, links, classicpress
Requires at least: 3.0
Tested up to: 6.0
Expand Down Expand Up @@ -60,12 +60,13 @@ Thanks to [igienger's post](https://wordpress.org/support/topic/error-curl-error

### What about compatibility?

TODO: It's stopped working with the block editor. I'll fix this asap.

It should work going back to the classic editor and forward to the block editor. It even works on [ClassicPress](https://www.classicpress.net/).

## Changelog

### [0.2.4] - 2022-06-13
* Fix bugs with plaintext URLs at the end of a block.

### [0.2.3] - 2022-06-10
* Fix bugs with tinyurl.com and URLs inside HTML links. (Plaintext URLs were working fine.)

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== Unwrap Shortlinks ===

Stable tag: 0.2.3
Stable tag: 0.2.4
Tags: urls, links, classicpress
Requires at least: 3.0
Tested up to: 6.0
Expand Down Expand Up @@ -60,6 +60,9 @@ Thanks to [igienger's post](https://wordpress.org/support/topic/error-curl-error

== Changelog ==

= [0.2.4] - 2022-06-13 =
* Fix bugs with plaintext URLs at the end of a block.

= [0.2.3] - 2022-06-10 =
* Fix bugs with tinyurl.com and URLs inside HTML links. (Plaintext URLs were working fine.)

Expand Down
5 changes: 2 additions & 3 deletions unwrap-shortlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Unwrap Shortlinks
Plugin URI: https://codeberg.org/kvibber/unwrap-shortlinks
Description: Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination.
Version: 0.2.3
Version: 0.2.4
Author: Kelson Vibber
Author URI: https://kvibber.com
License: GPLv2 or later
Expand All @@ -13,7 +13,7 @@
// ini_set('display_errors', '1'); ini_set('error_reporting', E_ALL);

function ktv_unwrap_shortlinks($content) {
preg_match_all('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|tinyurl\.com|goo\.gl|dlvr\.it|fb\.me|qr\.ae)\/[^\s"\']+)\b/', $content, $matches, PREG_PATTERN_ORDER);
preg_match_all('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|tinyurl\.com|goo\.gl|dlvr\.it|fb\.me|qr\.ae)\/[^\s"\'<>]+)\b/', $content, $matches, PREG_PATTERN_ORDER);
foreach ($matches[1] as $link) {
$getlink = ktv_unwrap_shortlinks_replace($link);
if ($getlink != "")
Expand All @@ -40,5 +40,4 @@ function ktv_unwrap_shortlinks_replace($url) {

add_filter('content_save_pre', 'ktv_unwrap_shortlinks', 700);


?>

0 comments on commit b82e80c

Please sign in to comment.