Opened 5 years ago
Closed 3 months ago
#52518 closed enhancement (maybelater)
sanitize_post_field filter for 'raw' context
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | reporter-feedback |
| Focuses: | Cc: |
Description
In some cases it can be useful to change values in raw context.
For example I need to change post_status value for replyto-comment ajax call, like so:
<?php add_action( 'wp_ajax_replyto-comment', function() { add_filter( 'post_status', function(){ return 'publish'; } ); }, 0 );
But I can't do this because existing filters don't work for raw context.
I don't see any reasons to not add such filter for raw context too.
Code snippet to do this change:
<?php $prefixed = false; if ( false !== strpos( $field, 'post_' ) ) { $prefixed = true; $field_no_prefix = str_replace( 'post_', '', $field ); } if ( 'raw' === $context ) { if ( $prefixed ) { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "{$field}", $value, $post_id, $context ); } else { $value = apply_filters( "post_{$field}", $value, $post_id, $context ); } return $value; } if ( 'edit' === $context ) { $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' );
Attachments (1)
Change History (4)
#2
in reply to:
↑ description
@
6 months ago
- Keywords reporter-feedback added
- Version 5.6.1 deleted
Replying to Tkama:
In some cases it can be useful to change values in
rawcontext.
For how the code is structured, I cannot really figure out a nice case where those filters, which also are concurrent with this and this, could be of use
Can you put a good testing use case (check this), to showcase how you could be using this without being able of taking advantage of what we currently have available?
#3
@
3 months ago
- Milestone Awaiting Review deleted
- Resolution set to maybelater
- Status changed from new to closed
Given that this post has been stale for too long and no feedback has been received, I will preventively close it as maybelater.
@Tkama if you are still experiencing this trouble or you can provide more testing information so we can proceed with this ticket, feel free to comment here, and I will be happy to reopen it and keep working on it.
/wp-includes/post.php