Opened 12 years ago
Closed 12 years ago
#21335 closed defect (bug) (invalid)
add_rewrite_endpoint() malfunction
Reported by: | Fike | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 3.4.1 |
Component: | Rewrite Rules | Keywords: | |
Focuses: | Cc: |
Description
- If add_rewrite_endpoint() is called just right from plugin file, it will result in standard PHP error, telling that $wp_rewrite isn't initialized yet (call to blahblahblah on a non-object). I guess there should be placed _doing_it_wrong() function explaining that add_rewrite_point should be called during 'init' action (it would be even better if add_rewrite_endpoint() would automatically store passed arguments until 'init' action and would tell developer that his callings are late if add_rewrite_point() is called after uri parsing - as for me, finding the right action during core interaction is VERY complicated).
- add_rewrite_endpoint() doesn't work on my localhost at all (404 is being returned without any additional query vars; i've tried adding endpoint 'json' to EP_ALL, EP_PAGES, EP_PERMALINKS, etc. and calling site/page/json and site/page/json/x), even if i just copy example code and declare new query var through 'query_vars' filter. Tried this on customized theme and on fresh install with twenty-eleven theme with no success.
Change History (3)
#2
follow-up:
↓ 3
@
12 years ago
Looks like point 2 is resolved - that's more codex problem than core problem.
Calling $wp_rewrite->flush_rules() after adding new endpoint did the job (saving new permalinks in settings didn't). Now i'm completely lost - why add_rewrite_endpoint() should be called during each request, while it is added once and forever after flush_rules()?
#3
in reply to:
↑ 2
@
12 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Replying to Fike:
Calling $wp_rewrite->flush_rules() after adding new endpoint did the job (saving new permalinks in settings didn't). Now i'm completely lost - why add_rewrite_endpoint() should be called during each request, while it is added once and forever after flush_rules()?
Because if rules get flushed again at a later point (e.g. user visiting permalinks options page) then your endpoint will be lost as it wasn't registered on that page load.
Closing this ticket as invalid.
Point 1 also applies to
add_feed()
(#4619, #20431) and the other Rewrite API functions, I suppose. There's a note in the Codex article:I could not reproduce point 2. My steps: