Opened 4 years ago
Last modified 4 years ago
#52518 new enhancement
sanitize_post_field filter for 'raw' context
Reported by: | Tkama | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.6.1 |
Component: | Posts, Post Types | Keywords: | |
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 (2)
Note: See
TracTickets for help on using
tickets.
/wp-includes/post.php