[wp-trac] [WordPress Trac] #17935: function get_post( integer ) bypasses posts_* filters

WordPress Trac wp-trac at lists.automattic.com
Wed Jun 29 21:47:44 UTC 2011


#17935: function get_post( integer ) bypasses posts_* filters
----------------------------+----------------------
 Reporter:  postpostmodern  |       Owner:
     Type:  defect (bug)    |      Status:  closed
 Priority:  normal          |   Milestone:
Component:  Query           |     Version:  3.2
 Severity:  normal          |  Resolution:  invalid
 Keywords:                  |
----------------------------+----------------------

Comment (by postpostmodern):

 That's understandable that using WP_Query inside of get_post() can not be
 used because of ramifications with plugins and overhead.

 However, I think that this bug in relation to the Quick Edit interface is
 still valid, here is my reasoning:

 Wordpress provides APIs to select extra data along with my post, as well
 as APIs to display this in the edit table and sort the columns which this
 data belongs to.  This data is automatically passed to the
 WP_Posts_List_Table class in wp-admin/edit.php via prepare_items(), which
 is using the WP_Query by way of wp_edit_posts_query().

 The 'inline-save' case of wp-admin/admin-ajax.php is bypassing this logic
 by using get_post instead, and in doing so, loses functionality.

 As it exists right now, it seems you are asking developers to make another
 database call inside of the manage_posts_custom_column filter to get the
 data they need.  This is less than optimal, since adding extra database
 calls for each post will add to the overhead, not to mention losing the
 ability to sort the table on this custom column.

 Modifying the 'inline-save' case in wp-admin/admin-ajax.php, line 1227 to
 the following would allow this extra flexibility with the custom tables,
 as well as not impacting functionality outside of Quick Edit:

 {{{
 $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
 }}}

 to:

 {{{
 $posts = get_posts( array('p'=>$post_ID, 'post_type'=>'any',
 'post_status'=>'any', 'suppress_filters'=>FALSE, 'posts_per_page'=>1) );
 $post = count( $posts ) ? $posts[0] : get_post( $post_ID );
 $wp_list_table->display_rows( array($post) );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17935#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list