Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#20431 closed defect (bug) (duplicate)

add_feed() - Warning

Reported by: 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() [function.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
4 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 4 years ago by SergeyBiryukov (previous) (diff)

#2 @nacin
4 years ago

  • Keywords reporter-feedback added

#3 @SergeyBiryukov
4 years ago

  • Component changed from General to Feeds

#4 @pavelevap
4 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() - http://codex.wordpress.org/Rewrite_API/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
4 years ago

Hmmm, strange Trac warning:

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

#6 @SergeyBiryukov
4 years ago

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

#7 @SergeyBiryukov
4 years ago

I've updated the Codex page.

#8 @pavelevap
4 years ago

Thank you, Sergey!

Actually, I found another notice on parent Codex page: http://codex.wordpress.org/Rewrite_API

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

Note: See TracTickets for help on using tickets.