Skip to content

add a filterable list of feed namespaces - #12812

Open
pfefferle wants to merge 7 commits into
WordPress:trunkfrom
pfefferle:fix/65785-duplicate-feed-namespaces
Open

add a filterable list of feed namespaces#12812
pfefferle wants to merge 7 commits into
WordPress:trunkfrom
pfefferle:fix/65785-duplicate-feed-namespaces

Conversation

@pfefferle

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65785

The rss2_ns and atom_ns actions are echo-only, so two plugins that add the same namespace produce a duplicate attribute, and the whole feed becomes invalid XML.

This adds get_feed_namespaces() and feed_namespaces() (named after feed_content_type()) and a wp_feed_namespaces filter. Namespaces are keyed by their prefix, so the same namespace can not be printed twice. The default namespaces of the templates moved into the filtered list, otherwise a plugin could still duplicate them. The *_ns actions stay untouched for backwards compatibility.

What it does not solve: a plugin that still echoes a namespace via the old actions can produce a duplicate, like before. That would need output buffering around the actions, and I did not want to go there.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pfefferle.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment thread src/wp-includes/feed.php Outdated
Comment on lines +711 to +715
* @param string $type Type of feed. Possible values include 'rss2', 'rss2-comments',
* 'rdf', 'atom', and 'atom-comments'.
* @return string[] Array of namespace URIs, keyed by their prefix.
*/
function get_feed_namespaces( $type ) {

@westonruter westonruter Aug 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @param string $type Type of feed. Possible values include 'rss2', 'rss2-comments',
* 'rdf', 'atom', and 'atom-comments'.
* @return string[] Array of namespace URIs, keyed by their prefix.
*/
function get_feed_namespaces( $type ) {
* @param string $type Type of feed. Possible values include 'rss2', 'rss2-comments',
* 'rdf', 'atom', and 'atom-comments'.
* @return array<string, string> Array of namespace URIs, keyed by their prefix.
* @phpstan-param 'rss2'|'rss2-comments'|'rdf'|'atom'|'atom-comments' $type
* @phpstan-return array<non-falsy-string, non-falsy-string>
*/
function get_feed_namespaces( string $type ): array {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if the 'rss2'|'rss2-comments'|'rdf'|'atom'|'atom-comments' enum is warranted, if other feed types are intended to be supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise, a non-falsy-string would be a good narrowed type.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤔 good point, but I would assume that modern feed formats are no longer XML, so I am not sure if we need a "generic" fallback!?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But I have no strong opinion on that! I am fine with having a general namespace support that could be adopted by third party implementers too!

Comment thread src/wp-includes/feed.php Outdated
Comment thread src/wp-includes/feed.php Outdated
*/
function feed_namespaces( $type ) {
foreach ( get_feed_namespaces( $type ) as $prefix => $uri ) {
printf( "xmlns:%s=\"%s\"\n\t", $prefix, esc_attr( $uri ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
printf( "xmlns:%s=\"%s\"\n\t", $prefix, esc_attr( $uri ) );
printf( "xmlns:%s=\"%s\"\n\t", $prefix, esc_url( $uri ) );

@pfefferle pfefferle Aug 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I applied your suggestion, but I am not sure it works for every value. XML namespaces are IRIs, so they can also be URNs for example (urn:schemas-microsoft-com:office:office), so we may have to stick with esc_attr or have more specific check(s)!?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should WordPress have an esc_iri? Maybe based on src/wp-includes/SimplePie/src/IRI.php???

Comment thread src/wp-includes/feed.php Outdated
pfefferle and others added 5 commits August 6, 2026 20:38
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
@pfefferle
pfefferle requested a review from westonruter August 6, 2026 18:51
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