Make WordPress Core

Opened 22 months ago

Closed 9 months ago

#43638 closed enhancement (maybelater)

Introducing 'sanitize_post' filter

Reported by: enrico.sorcinelli Owned by: SergeyBiryukov
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: Posts, Post Types Keywords: has-patch has-unit-tests reporter-feedback
Focuses: Cc:
PR Number:


I was trying to do a post field sanitization on new post insertions that depended on the value of another field.

While it quite easy in administration context, using for example pre_{$field} or {$field_no_prefix}_save_pre filters in conjunction to $_POST and so on, it seems that there's no direct way using wp_insert_post since the filters above do not have references to the other fields or to the ID of the post (which is also useless in the case of new posts) but only refers to the value to be sanitized.

So this enhancement aims to introduce new sanitize_post filter.

PS: Of course I could sanitize values directly in wp_insert_post but only assuming I have control of the code or at the cost of duplicate the sanitization in each wp_insert_post calls.

Attachments (2)

43638.patch (2.5 KB) - added by enrico.sorcinelli 22 months ago.
43638.2.patch (2.9 KB) - added by enrico.sorcinelli 21 months ago.

Download all attachments as: .zip

Change History (11)

#1 @enrico.sorcinelli
22 months ago

  • Keywords has-patch has-unit-tests added

#2 @SergeyBiryukov
22 months ago

  • Milestone changed from Awaiting Review to 5.0
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 @enrico.sorcinelli
21 months ago

I just updated the patch by moving the filter at the end of sanitize_post() function.

#4 @pento
16 months ago

  • Milestone changed from 5.0 to 5.1

#5 @pento
13 months ago

  • Milestone changed from 5.1 to 5.2

#6 @SergeyBiryukov
10 months ago

  • Milestone changed from 5.2 to 5.3

Missed the 5.2 Beta 1 deadline, moving to 5.3.

#7 in reply to: ↑ description @SergeyBiryukov
10 months ago

  • Keywords reporter-feedback added

Replying to enrico.sorcinelli:

I was trying to do a post field sanitization on new post insertions that depended on the value of another field.

What about using the wp_insert_post_data filter for that? Just want to make sure I understand the use case.

#8 @desrosj
9 months ago

@enricosorcinelli To answer @SergeyBiryukov's question, does the wp_insert_post_data filter work for your situation?

#9 @SergeyBiryukov
9 months ago

  • Milestone 5.3 deleted
  • Resolution set to maybelater
  • Status changed from reviewing to closed

I talked to @enrico.sorcinelli at WordCamp Torino. IIRC, wp_insert_post_data should do the job here.

The consensus was that #21676 is more important, any efforts are better spent there.

Closing as maybelater, feel free to reopen if still relevant.

Note: See TracTickets for help on using tickets.