#15515 closed enhancement (wontfix)
content_save_pre et al don't supply context
| Reported by: | johnbillion | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 2.3 |
| Severity: | normal | Keywords: | has-patch needs-refresh bulk-reopened |
| Cc: | Focuses: |
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)
#2
follow-up:
↓ 3
@
16 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
@
16 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}_preand comment ID tocomment_save_preas well?
Yeah I've added it to pre_{field}, pre_post_{field} and {field}_pre too.
#4
@
16 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
@
11 years ago
- Milestone Future Release
- Resolution → wontfix
- Status new → closed
No interest in 5 years. Everyone just uses the global $post at this point.
#7
@
11 years ago
- Milestone → Future Release
- Resolution wontfix
- Status closed → reopened
- Version → 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
@
11 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
@
7 years ago
- Keywords bulk-reopened added
- Resolution → wontfix
- Status reopened → closed
Still no interest in 4 years.
#13
@
5 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Excellent idea. Patches Welcome :-)