Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20431 closed defect (bug) (duplicate)

add_feed() - Warning

Reported by: pavelevap's profile pavelevap Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Feeds Keywords:
Focuses: Cc:


I tried to use add_feed() function, but there is probably some problem (using latest trunk).

Warning: in_array() []: Wrong datatype for second argument in C:\WWW\Wordpress\wp-includes\rewrite.php on line 88

Error is related to rewrite.php (line 88) and in_array() function and it seems that $wp_rewrite->feeds is null everytime, because $feeds is defined later in WP_Rewrite() class?

Code example:

function my_test() {
  echo '<item>';
add_feed( 'test', 'my_test' );

So, I had to use (works well):

add_action( 'do_feed_test', 'my_test' );

I am not sure, but it is probably bug...

Change History (8)

#1 @SergeyBiryukov
12 years ago

Since $wp_rewrite is set after plugins are loaded, the function that calls add_feed() needs to be hooked to the init action.

Last edited 12 years ago by SergeyBiryukov (previous) (diff)

#2 @nacin
12 years ago

  • Keywords reporter-feedback added

#3 @SergeyBiryukov
12 years ago

  • Component changed from General to Feeds

#4 @pavelevap
12 years ago

Sergey was right, this code works well:

function my_test() {
  echo '<item>';

function my_feed() {
  add_feed( 'test', 'my_test' );

add_action( 'init', 'my_feed' );

Is it the right way to do it?

First I found Codex entry for add_feed() - - and there was no mention about init hook. We can probably improve Codex entry, but this ticket can be closed, sorry for bothering...

#5 @pavelevap
12 years ago

Hmmm, strange Trac warning:

Warning: The change has been saved, but an error occurred while sending notifications: (111, 'Connection refused')

#6 @SergeyBiryukov
12 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#7 @SergeyBiryukov
12 years ago

I've updated the Codex page.

#8 @pavelevap
12 years ago

Thank you, Sergey!

Actually, I found another notice on parent Codex page:

"Note that these rules are usually called inside the init hook."

Note: See TracTickets for help on using tickets.