Skip to content

Commit

Permalink
Add back tinyurl.com support and test up to WP 6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kvibber committed Jul 7, 2024
1 parent d981b72 commit aa6e915
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Unwrap Shortlinks

Stable tag: 0.3.3
Stable tag: 0.3.4
Tags: urls, links, classicpress
Tested up to: 6.5
Tested up to: 6.6
Contributors: Kelson
License: GPLv2 or later

Expand All @@ -25,8 +25,7 @@ Automatically expands URLs at the following known link shorteners when you save
* fb.me
* qr.ae
* aka.ms

NOTE: tinyurl.com has been removed from the list because they are blocking automated requests. (See changelog)
* tinyurl.com

## Installation

Expand Down Expand Up @@ -60,7 +59,10 @@ It should work going back to the classic editor and forward to the block editor.

## Changelog

### [0.3.3]
### [0.3.4] - 2024-07-07
* tinyurl.com is accepting curl requests again, so I've added it back to the list.

### [0.3.3] - 2023-07-22
* tinyurl.com is screening requests using Cloudflare, and a simple curl request is no longer allowed through. Removing it from the list.

### [0.3.2] - 2022-10-29
Expand Down
6 changes: 3 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.3.3
Version: 0.3.4
Requires at least: 3.0
Requires CP: 1.0
Requires PHP: 7.0
Expand All @@ -16,7 +16,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|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\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|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms|tinyurl\.com)\/[^\s"\'<>]+)\b/', $content, $matches, PREG_PATTERN_ORDER);
foreach ($matches[1] as $link) {
$getlink = ktv_unwrap_shortlinks_replace($link, 5);
if ($getlink != "")
Expand All @@ -37,7 +37,7 @@ function ktv_unwrap_shortlinks_replace($url, $countdown) {
if ($status == 301 || $status == 302 || $status == 307 || $status == 308) {
// TODO Is it also a redirector? Do we have iterations left?
// If so, try to follow that one!
if( $countdown > 0 && preg_match('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\s"\'<>]+)\b/', $finalURL) ) {
if( $countdown > 0 && preg_match('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms|tinyurl\.com)\/[^\s"\'<>]+)\b/', $finalURL) ) {
return ktv_unwrap_shortlinks_replace($finalURL, $countdown - 1);
} else {
// Otherwise, send it back up the chain!
Expand Down

0 comments on commit aa6e915

Please sign in to comment.