#50387 closed defect (bug) (invalid)
Cannot modify header information - headers already sent for "nocache_headers()"
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.5 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
function nocache_headers needs to be modified to not try to set/remove headers when the headers were already sent to avoid generating a notice.
Optionally it would also make sense to change the return type to bool, so we can return false in case the headers were already sent.
Suggestion (would be better with return false; though):
function nocache_headers() { if ( headers_sent() ) { return; }
Change History (3)
#2
@
3 years ago
- Resolution set to wontfix
- Status changed from new to closed
I didn't realise the project I was on was on an older WP version of this file/function.
Ticket can be closed, unless one wants to modify the return value to make it more descriptive.
However there's nothing that can be done if it returns false/error anyway; that's why it's probably not worth to change it.
Note: See
TracTickets for help on using
tickets.
Hi @malthert,
Thank you for opening this ticket and sorry you ran into a problem here.
The
nocache_headers()
function actually does already contain an early bail the same as your suggested change. See: https://developer.wordpress.org/reference/functions/nocache_headers/#sourceIs there something else wrong with the function that you think could be improved? Is your suggestion only about returning false?
If we are changing the returns in the function personally I would prefer a descriptive
WP_Error
object be returned so it could proved feedback about what is going wrong.