Revert to pre-4.7 behavior for fetching object instances by id.
This changeset reverts [38381], which caused inconsistencies in the way the REST API fetches posts and other objects. See #38792, #37738. git-svn-id: https://develop.svn.wordpress.org/trunk@39992 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0167cea791
commit
18e09d246e
|
@ -191,12 +191,11 @@ final class WP_Comment {
|
|||
public static function get_instance( $id ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_numeric( $id ) || $id != floor( $id ) || ! $id ) {
|
||||
$comment_id = (int) $id;
|
||||
if ( ! $comment_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$comment_id = (int) $id;
|
||||
|
||||
$_comment = wp_cache_get( $comment_id, 'comment' );
|
||||
|
||||
if ( ! $_comment ) {
|
||||
|
|
|
@ -210,12 +210,11 @@ final class WP_Post {
|
|||
public static function get_instance( $post_id ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_numeric( $post_id ) || $post_id != floor( $post_id ) || ! $post_id ) {
|
||||
$post_id = (int) $post_id;
|
||||
if ( ! $post_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
$_post = wp_cache_get( $post_id, 'posts' );
|
||||
|
||||
if ( ! $_post ) {
|
||||
|
|
|
@ -125,12 +125,11 @@ final class WP_Term {
|
|||
public static function get_instance( $term_id, $taxonomy = null ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_numeric( $term_id ) || $term_id != floor( $term_id ) || ! $term_id ) {
|
||||
$term_id = (int) $term_id;
|
||||
if ( ! $term_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$term_id = (int) $term_id;
|
||||
|
||||
$_term = wp_cache_get( $term_id, 'terms' );
|
||||
|
||||
// If there isn't a cached version, hit the database.
|
||||
|
|
|
@ -49,15 +49,6 @@ class Tests_Term_WpComment extends WP_UnitTestCase {
|
|||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_bool() {
|
||||
$found = WP_Comment::get_instance( true );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
|
@ -66,32 +57,4 @@ class Tests_Term_WpComment extends WP_UnitTestCase {
|
|||
|
||||
$this->assertEquals( 1, $found->comment_ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_float() {
|
||||
$found = WP_Comment::get_instance( 1.6 );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_array() {
|
||||
$found = WP_Comment::get_instance( array( 1 ) );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_class() {
|
||||
$class = new stdClass();
|
||||
$found = WP_Comment::get_instance( $class );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,15 +47,6 @@ class Tests_Post_WpPost extends WP_UnitTestCase {
|
|||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_bool() {
|
||||
$found = WP_Post::get_instance( true );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
|
@ -64,32 +55,4 @@ class Tests_Post_WpPost extends WP_UnitTestCase {
|
|||
|
||||
$this->assertSame( 1, $found->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_float() {
|
||||
$found = WP_Post::get_instance( 1.6 );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_array() {
|
||||
$found = WP_Post::get_instance( array( 1 ) );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_class() {
|
||||
$class = new stdClass();
|
||||
$found = WP_Post::get_instance( $class );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,15 +60,6 @@ class Tests_Term_WpTerm extends WP_UnitTestCase {
|
|||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_bool() {
|
||||
$found = WP_Term::get_instance( true );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
|
@ -77,32 +68,4 @@ class Tests_Term_WpTerm extends WP_UnitTestCase {
|
|||
|
||||
$this->assertSame( 1, $found->term_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_float() {
|
||||
$found = WP_Term::get_instance( 1.6 );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_array() {
|
||||
$found = WP_Term::get_instance( array( 1 ) );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37738
|
||||
*/
|
||||
public function test_get_instance_should_fail_for_class() {
|
||||
$class = new stdClass();
|
||||
$found = WP_Term::get_instance( $class );
|
||||
|
||||
$this->assertFalse( $found );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue