Skip to content

Conversation

@t-hamano
Copy link

@t-hamano t-hamano commented Dec 21, 2025

Closes: https://meta.trac.wordpress.org/ticket/8149

This PR adds a plugin that displays a warning for blocks that contain inappropriate external resources. This helps encourage contributors to upload resources when creating documentation by copying content from external documents, preventing media from potentially disappearing in the future.

How this plugin works

  • Check the three blocks that allow you to set external resources as media.
  • Check whether the media URL matches your site's domain. If not, this plugin checks whether it matches one of the allowed domains. Finally, if the media URL does not match any domain, it is considered an inappropriate media resource.
  • Blocks with invalid media resources will have a red border and overlay.
    Additionally, the block toolbar will have a red icon button. Clicking that button will display a popover with details about the error.

Testing Instructions

Use the .wp-env.override.json file to map the plugin to your local wp-env environment:

{
	"plugins": [
		"./your/plugins/plugin",
		"../path/to/wordpress.org/wordpress.org/public_html/wp-content/plugins/wporg-media-resource-checker"
	]
}

Screenshot

image

@t-hamano t-hamano force-pushed the media-resource-checker branch from a189f1f to d12ab9f Compare December 21, 2025 06:45
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the right place for this file; maybe it should be in a higher directory to cover all plugin files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably define this into /.gitignore or just leave it in the project-specific area since it doesn't matter all that much.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion about where this file should be located 😄 Please feel free to move it elsewhere if necessary.

* License: GPLv2 or later
*/

namespace WPOrg_Media_Resource_Checker;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use WordPressdotorg\Media_Resource_Checker instead?


namespace WPOrg_Media_Resource_Checker;

use function WPOrg_Media_Resource_Checker\{ get_build_path, get_build_url };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the purpose of this is? Importing the functions defined in the current file into the file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've imitated the implementation of the Learn plugin:

/**
* Shortcut to the build directory.
*
* @return string
*/
function get_build_path() {
return PLUGIN_DIR . 'build/';
}
/**
* Shortcut to the build URL.
*
* @return string
*/
function get_build_url() {
return PLUGIN_URL . 'build/';
}

use function WPOrg_Learn\{ get_build_path, get_build_url };

We can also use an approach that doesn't use it if we don't need it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9d72889

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably define this into /.gitignore or just leave it in the project-specific area since it doesn't matter all that much.

Comment on lines 26 to 36
// List of allowed domain regexes.
export const ALLOWED_DOMAINS = [
{
authority: 'wordpress.org',
regex: /^(.*\.)?wordpress\.org$/,
},
{
authority: 'wp.com',
regex: /^(.*\.)?wp\.com$/,
},
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if wp.com should be allowed here, since WordPress.org != WordPress.com, and often using wpcom hosted images ends up invalid.

I can imagine this might also be intended for photon images? In which case, allowing ^(.*\.)?wp.com/(.*\.)?wordpress\.org/ could make sense?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine this might also be intended for photon images?

Yes, that's right. For example, the handbook uses images that are actually delivered from the Photon CDN:

https://github.com/search?q=repo%3AWordPress%2Fdeveloper-plugins-handbook%20wp.com&type=code

In which case, allowing ^(.*\.)?wp.com/(.*\.)?wordpress\.org/ could make sense?

I agree, fixed in e1db353.

Specific examples of allowed URLs can be found here.

https://github.com/WordPress/wordpress.org/pull/536/changes#diff-6b3ed010975581690ee4c331ff822c288910b4e110783cb70ede501d96183e36R66-R70

Comment on lines 28 to 31
{
authority: 'wordpress.org',
regex: /^(.*\.)?wordpress\.org$/,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We likely should also allow the WordPress.org CDNs here:

Suggested change
{
authority: 'wordpress.org',
regex: /^(.*\.)?wordpress\.org$/,
},
{
authority: 'wordpress.org',
regex: /^(.*\.)?wordpress\.org$/,
},
{
authority: 'wordpress.org',
regex: /^(.*\.)?w\.org$/,
},

Eg; https://s.w.org/images/core/6.9/01-notes.webp?v=24082

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 302493e

Just to be sure, I have distinguished between the authority texts wordpress.org and w.org.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants