WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 17 months ago

Last modified 17 months ago

#15515 closed enhancement (wontfix)

content_save_pre et al don't supply context

Reported by: johnbillion 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)

15515.patch (795 bytes) - added by johnbillion 10 years ago.
15515.2.patch (504 bytes) - added by johnbillion 10 years ago.
Patch for commetn_save_pre

Download all attachments as: .zip

Change History (12)

#1 @westi
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

Excellent idea. Patches Welcome :-)

#2 follow-up: @SergeyBiryukov
10 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?

@johnbillion
10 years ago

#3 in reply to: ↑ 2 @johnbillion
10 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 to comment_save_pre as well?

Yeah I've added it to pre_{field}, pre_post_{field} and {field}_pre too.

@johnbillion
10 years ago

Patch for commetn_save_pre

#4 @johnbillion
10 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.

#5 @nacin
7 years ago

  • Component changed from Plugins to Posts, Post Types

#6 @johnbillion
5 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 @westonruter
5 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 @westonruter
5 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.

#9 @johnbillion
5 years ago

  • Keywords needs-refresh added

#12 @johnbillion
17 months ago

  • Keywords bulk-reopened added
  • Resolution set to wontfix
  • Status changed from reopened to closed

Still no interest in 4 years.

Note: See TracTickets for help on using tickets.