#15515 closed enhancement (wontfix)
content_save_pre et al don't supply context
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.3 |
Component: | Posts, Post Types | Keywords: | has-patch needs-refresh bulk-reopened |
Focuses: | Cc: |
Description
All of the {field}_save_pre
filters don't provide any additional parameters with context. The {field}_edit_pre
(when editing) and post_{field}
(when displaying) filters pass the $post_id variable as a second parameter. The {field}_save_pre
filter is the odd one out.
Currently if a plugin uses (for example) the content_save_pre
filter and needs to know anything about the post (eg. the post type) then it has to use the global $post object directly. It works, but it's not ideal.
Can we add some context to these hooks? All they need is a second parameter containing the $post_id variable to bring them in line with the other field filters.
Attachments (2)
Change History (13)
#1
@
14 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#2
follow-up:
↓ 3
@
14 years ago
Should post ID be added to pre_{field
}, pre_post_{field
}, {field}_pre
and comment ID to comment_save_pre
as well? Or is {field}_save_pre
the only one that needs modification?
#3
in reply to:
↑ 2
@
14 years ago
- Keywords has-patch added; needs-patch removed
Patch.
Replying to SergeyBiryukov:
Should post ID be added to
pre_{field
},pre_post_{field
},{field}_pre
and comment ID tocomment_save_pre
as well?
Yeah I've added it to pre_{field
}, pre_post_{field
} and {field}_pre
too.
#4
@
14 years ago
Patch for comment_save_pre
as suggested by SergeyBiryukov. However it might be worth discussing if the other comment fields should be filtered too at this point, for consistency.
#6
@
9 years ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from new to closed
No interest in 5 years. Everyone just uses the global $post
at this point.
#7
@
9 years ago
- Milestone set to Future Release
- Resolution wontfix deleted
- Status changed from closed to reopened
- Version set to 2.3
I'm interested.
Using a global $post
is not robust since calling wp_insert_post()
/wp_update_post()
(via a plugin) will not necessarily set the $post
global. Besides, relying on globals isn't a practice we should encourage anyway.
#8
@
9 years ago
My use case here is to intercept some pre-save filters for a certain post type. But in the case of wp_insert_post()
, the $post_id
would have to be empty since the post hasn't been inserted yet, so that context wouldn't be directly available.
#12
@
6 years ago
- Keywords bulk-reopened added
- Resolution set to wontfix
- Status changed from reopened to closed
Still no interest in 4 years.
#13
@
4 years ago
Unfortunately this workaround of accessing the global $post
doesn't seem to work. It's never set, neither are any other useful globals.
I want to filter wp_kses_allowed_html
only for a specific post type. My current workaround is to use the wp_insert_post_data
filter, which provides access to both the sanitized and unsanitized post data. So in this filter I just run the unsanitized data through KSES, but now with my filters applied.
Excellent idea. Patches Welcome :-)