[wp-trac] [WordPress Trac] #12955: Add get_post filter
WordPress Trac
noreply at wordpress.org
Thu Oct 15 22:08:18 UTC 2015
#12955: Add get_post filter
------------------------------------+-----------------------------
Reporter: JohnLamansky | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+-----------------------------
Comment (by sc0ttkclark):
If we moved the filter to run only if $post wasn't an instanceof, that
could greatly reduce the number of times this filter has to get called.
So that'd be from the current patch:
{{{
if ( $post instanceof WP_Post ) {
$_post = $post;
} elseif ( is_object( $post ) ) {
if ( empty( $post->filter ) ) {
$_post = sanitize_post( $post, 'raw' );
$_post = new WP_Post( $_post );
} elseif ( 'raw' == $post->filter ) {
$_post = new WP_Post( $post );
} else {
$_post = WP_Post::get_instance( $post->ID );
}
} else {
$_post = WP_Post::get_instance( $post );
}
/**
* Filter that allows a post object to be further sanitized,
virtualized and/or have properties annotated.
*
* @since 4.4.0
*
* @param WP_Post $_post Post object to
saitize/virtualize/annotate/etc.
* @param WP_Post|int $post Original post object passed in.
* @param string $output Format of data to return,
potentially 'OBJECT', 'ARRAY_A' or 'ARRAY_N'.
* @param string $filter Type of filter to apply,
potentially 'raw', 'edit', 'db' or 'display'.
*/
$_post = apply_filters( 'get_post', $_post, $post, $output,
$filter );
}}}
to
{{{
if ( $post instanceof WP_Post ) {
$_post = $post;
} else {
if ( is_object( $post ) ) {
if ( empty( $post->filter ) ) {
$_post = sanitize_post( $post, 'raw' );
$_post = new WP_Post( $_post );
} elseif ( 'raw' == $post->filter ) {
$_post = new WP_Post( $post );
} else {
$_post = WP_Post::get_instance( $post->ID
);
}
} else {
$_post = WP_Post::get_instance( $post );
}
/**
* Filter that allows a post object to be further
sanitized, virtualized and/or have properties annotated.
*
* @since 4.4.0
*
* @param WP_Post $_post Post object to
saitize/virtualize/annotate/etc.
* @param WP_Post|int $post Original post object
passed in.
* @param string $output Format of data to
return, potentially 'OBJECT', 'ARRAY_A' or 'ARRAY_N'.
* @param string $filter Type of filter to apply,
potentially 'raw', 'edit', 'db' or 'display'.
*/
$_post = apply_filters( 'get_post', $_post, $post,
$output, $filter );
}
}}}
This
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12955#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list