Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#49937 closed defect (bug) (invalid)

Magnet links are being broken when saving posts using Classic Editor

Reported by: kareldonk's profile KarelDonk Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.4
Component: Editor Keywords:
Focuses: Cc:

Description

When creating a new post using the Classic Editor on a self-hosted WordPress blog and adding a magnet link in the text, the link gets broken or completely removed when saving the post. This problem did not exist in previous versions of WordPress as I was able to save posts containing magnet links without problems. I don't know exactly from which version it got broken.

Here is a magnet link example:

magnet:?xt=urn:btih:testing&dn=Test%20Link&tr=udp://tracker.cyberia.is:6969/announce&tr=udp://tracker.port443.xyz:6969/announce&tr=http://tracker3.itzmx.com:6961/announce&tr=udp://tracker.moeking.me:6969/announce&tr=http://vps02.net.orel.ru:80/announce&tr=http://tracker.openzim.org:80/announce&tr=udp://tracker.skynetcloud.tk:6969/announce&tr=https://1.tracker.eu.org:443/announce&tr=https://3.tracker.eu.org:443/announce&tr=http://re-tracker.uz:80/announce&tr=https://tracker.parrotsec.org:443/announce&tr=udp://explodie.org:6969/announce&tr=udp://tracker.filemail.com:6969/announce&tr=udp://tracker.nyaa.uk:6969/announce&tr=udp://retracker.netbynet.ru:2710/announce&tr=http://tracker.gbitt.info:80/announce&tr=http://tracker2.dler.org:80/announce

Change History (6)

#1 follow-up: @joyously
4 years ago

There were protocols added https://developer.wordpress.org/reference/functions/wp_allowed_protocols/
How did magnet links work before? They seem crazy complicated. The functions that filter links in content have had some recent changes: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php?annotate=blame#L3057 and down through L3280.

#2 in reply to: ↑ 1 @KarelDonk
4 years ago

Replying to joyously:

There were protocols added https://developer.wordpress.org/reference/functions/wp_allowed_protocols/

The magnet links used to work for sure in the WordPress 4.x versions. With one of the later updates something got added that filters away the magnet link from the href attribute when saving a post.

How did magnet links work before? They seem crazy complicated.

I would simply select the text in the editor and then click the link button to add the link, and in the URL field paste the magnet link. Even in the most basic form it does not survive a save anymore. Below is an example of a basic magnet link which should be placed in the href attribute of an A tag.

Example: magnet:?xt=urn:btih:test&dn=Test%20Link

in a link: <a href="magnet:?xt=urn:btih:test&dn=Test%20Link">Test</a>

You can create magnet links on this site to try: https://magnetlinkgenerator.com/

#3 follow-up: @apedog
4 years ago

  • Resolution set to invalid
  • Status changed from new to closed

This is a support question. "How to". Not a bug.
WordPress allows filtering the allowed protocols. So you can add any protocol you need.

/**
 * Add extra protocols to list of allowed protocols.
 *
 * @param array $protocols List of protocols allowed by default by WordPress.
 *
 * @return array $protocols Updated list including extra protocols added.
 */
function wporg49937_add_more_protocols( $protocols ){
	$protocols[] = 'magnet';
	return $protocols;
}
add_filter( 'kses_allowed_protocols' , 'wporg49937_add_more_protocols' );

#4 in reply to: ↑ 3 @KarelDonk
4 years ago

Replying to apedog:

This is a support question. "How to". Not a bug.

It used to work before in WordPress 4.x without any extra functions and now it doesn't. In any case, I'll try your solution.

Version 0, edited 4 years ago by KarelDonk (next)

#5 @desrosj
4 years ago

  • Milestone Awaiting Review deleted
  • Severity changed from major to normal

Glad that worked for you @KarelDonk! I did a brief glance and this is potentially related in some way to [46895] which was released in 5.3.1.

#6 @thesimarchitect
4 years ago

Thanks! This solved my problem! I used the "plugin editor" plugin to add the code @apedog shared above.

Note: See TracTickets for help on using tickets.