﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
17935,Quick edit in admin bypasses custom_column filters in wp-admin/edit.php,postpostmodern,wonderboymusic,"Calling get_post( integer ) bypasses all normal query filters, like `posts_fields` and `posts_join`.  I ran into this problem when using Quick Edit on wp-admin/edit.php in conjunction with query filters in a plugin.

Example plugin:

{{{

/*
Plugin Name: get_posts bug report 
*/

add_filter( 'posts_fields', 'get_post_bug_posts_fields' );
add_filter( 'posts_request', 'get_post_bug_posts_request' );
add_filter( 'manage_posts_columns', 'get_post_bug_manage_posts_columns' );
add_filter( 'manage_posts_custom_column', 'get_post_bug_manage_posts_custom_column', 10, 2 );

function get_post_bug_posts_fields( $sql ){
	$sql .= "", 'ffffoooooooo' AS `foo`, 'baaaaaarrrr' AS `bar`"";
	return $sql;
}

function get_post_bug_posts_request( $sql ){
	//var_dump( $sql );
	return $sql;
}

function get_post_bug_manage_posts_columns( $headings ){
	$a = array_slice( $headings, 0, 3 );
	$b = array_slice( $headings, 4 );
	
	$headings = array_merge( $a, array('foo'=>'Foo'), array('bar'=>'Bar'), $b );
	return $headings;
}

function get_post_bug_manage_posts_custom_column( $column_name, $post_id ){
	global $post;
	
	switch( $column_name ){
		case 'foo':
			echo $post->foo;
			break;
		
		case 'bar':
			echo $post->bar;
			break;
	}
}
}}}

On page load, the edit list table will load correctly with two custom columns, however saving the post from the Quick Edit interface will result in the two columns having no data.

Proposed fix:

wp-includes/post.php line 391

{{{
$_post = $wpdb->get_row($wpdb->prepare(""SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1"", $post_id));
}}}

becomes

{{{
$_posts = query_posts( array('p' => $post_id, 
			     'post_type' => 'any', 
			     'post_status' => 'any', 
			     'posts_per_page' => 1) );
$_post = count( $_posts ) ? $_posts[0] : $wpdb->get_row( $wpdb->prepare(""SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1"", $post_id) );
}}}
",defect (bug),closed,normal,,Query,3.2,normal,wontfix,has-patch,
