#20431 closed defect (bug) (duplicate)
add_feed() - Warning
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Feeds | Version: | 3.4 |
| Severity: | normal | Keywords: | |
| Cc: | pavelevap@… |
Description
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)
comment:1
SergeyBiryukov — 13 months ago
comment:3
SergeyBiryukov — 12 months ago
- Component changed from General to Feeds
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...
Hmmm, strange Trac warning:
Warning: The change has been saved, but an error occurred while sending notifications: (111, 'Connection refused')
comment:6
SergeyBiryukov — 12 months ago
- Keywords reporter-feedback removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
comment:7
SergeyBiryukov — 12 months ago
I've updated the Codex page.
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."

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