[wp-trac] [WordPress Trac] #59945: About the feed name specified in the add_feed()

WordPress Trac noreply at wordpress.org
Wed Nov 22 02:51:18 UTC 2023


#59945: About the feed name specified in the add_feed()
--------------------------+-----------------------------
 Reporter:  tmatsuur      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Feeds         |    Version:  6.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 There is no restriction on the first parameter of the add_feed function,
 but if it starts with "_" it will not function properly.


 {{{
 function feed2_callback( $is_comment_feed, $feed ) {
         header( 'Content-Type: application/xml; charset=UTF-8', true );
         echo '<?xml version="1.0" encoding="UTF-8" ?>';
 ?>
 <rss version="2.0"
         xmlns:content="http://purl.org/rss/1.0/modules/content/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:atom="http://www.w3.org/2005/Atom"
 >
         <title>Test</title>
 </rss>
 <?php
 }

 add_feed( '_feed2', 'feed2_callback' );
 }}}

 Next, update the rewrite rule and access "http://localhost/_feed2", which
 will return the following:
 {{{
 <error>
     <code>wp_die</code>
     <title><![CDATA[WordPress &rsaquo; Error]]></title>
     <message><![CDATA[<strong>Error:</strong> This is not a
 valid feed template.]]></message>
     <data>
         <status>404</status>
     </data>
 </error>
 }}}

 This is not a problem with the code I tried, but because the "_" at the
 beginning of the feed name is removed in the do_feed function.

 {{{
 function do_feed() {
         global $wp_query;

         $feed = get_query_var( 'feed' );

         // Remove the pad, if present.
         $feed = preg_replace( '/^_+/', '', $feed );
 }}}

 This process results in an action name of 'do_feed_' . **'feed2'** when
 $feed is '_feed2'.

 Since this is not done in the add_feed function and the action name
 specified in the add_action function is 'do_feed_' . **'_feed2'**, it
 appears that the two action names do not match, resulting in the error
 indicated in the response.

 Should I remove the leading '_' in the feed name in the add_feed function
 or not remove the '_' in the do_feed function?

 In any case, I would like to see consistency in the handling of feed
 names.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59945>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list