Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4619 closed defect (bug) (invalid)

add_feed does not generate rewrite rules

Reported by: cavemonkey50's profile cavemonkey50 Owned by: westi's profile westi
Milestone: Priority: normal
Severity: normal Version: 2.2.1
Component: Administration Keywords: reporter-feedback
Focuses: Cc:

Description

When using the function add_feed to add a new feed type, the function is supposed to generate the correct rewrite rules to make the feed type functional. However, this does not occur in the function.

Lines 30-32 of includes/rewrite.php are supposed to handle adding the feed type to the array of feeds:

if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is
	$wp_rewrite->feeds[] = $feedname;
}

However, when add_feed calls the array, the array is empty because the $wp_rewrite class has not yet been executed. Therefore, the check to see if the feed name already exists is pointless. Even though $wp_rewrite class has not been run, $wp-rewrite->feeds gets populated with the new feed names, which then could be added to the array later.

Although, adding the new feed names to the array never occurs. Line 229 then defines feed names, completely ignoring the previously added feed names.

var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' );

So basically, the feed names never get added to the feeds array, therefore never having the correct rewrite rules generated.

Change History (3)

#1 @Nazgul
17 years ago

  • Milestone set to 2.3 (trunk)

#2 @westi
17 years ago

  • Keywords reporter-feedback added
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

Can you provide simple example code demonstrating this issue?

You should not be calling add_feed when your plugin is included but in an action on the init hook and then all will work fine.

Plugins should not really run any code at include time apart from hooking onto init (or maybe plugins_loaded) to run there initialisation code.

You cannot guarantee that WordPress has loaded and is ready for you to call it's API until the init hook fires.

#3 @cavemonkey50
17 years ago

  • Milestone 2.3 (trunk) deleted
  • Resolution set to invalid
  • Status changed from assigned to closed

You're correct. add_feed just needed to be moved to the init section and it worked correctly.

Note: See TracTickets for help on using tickets.