Make WordPress Core

Changeset 39993


Ignore:
Timestamp:
01/26/2017 04:56:21 PM (7 years ago)
Author:
boonebgorges
Message:

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.

Merge of [39992] to the 4.7 branch.

See #38792, #37738.

Location:
branches/4.7
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/class-wp-comment.php

    r38381 r39993  
    192192        global $wpdb;
    193193
    194         if ( ! is_numeric( $id ) || $id != floor( $id ) || ! $id ) {
     194        $comment_id = (int) $id;
     195        if ( ! $comment_id ) {
    195196            return false;
    196197        }
    197 
    198         $comment_id = (int) $id;
    199198
    200199        $_comment = wp_cache_get( $comment_id, 'comment' );
  • branches/4.7/src/wp-includes/class-wp-post.php

    r38951 r39993  
    211211        global $wpdb;
    212212
    213         if ( ! is_numeric( $post_id ) || $post_id != floor( $post_id ) || ! $post_id ) {
     213        $post_id = (int) $post_id;
     214        if ( ! $post_id ) {
    214215            return false;
    215216        }
    216 
    217         $post_id = (int) $post_id;
    218217
    219218        $_post = wp_cache_get( $post_id, 'posts' );
  • branches/4.7/src/wp-includes/class-wp-term.php

    r38381 r39993  
    126126        global $wpdb;
    127127
    128         if ( ! is_numeric( $term_id ) || $term_id != floor( $term_id ) || ! $term_id ) {
     128        $term_id = (int) $term_id;
     129        if ( ! $term_id ) {
    129130            return false;
    130131        }
    131 
    132         $term_id = (int) $term_id;
    133132
    134133        $_term = wp_cache_get( $term_id, 'terms' );
  • branches/4.7/tests/phpunit/tests/comment/wpComment.php

    r38398 r39993  
    5353     * @ticket 37738
    5454     */
    55     public function test_get_instance_should_fail_for_bool() {
    56         $found = WP_Comment::get_instance( true );
    57 
    58         $this->assertFalse( $found );
    59     }
    60 
    61     /**
    62      * @ticket 37738
    63      */
    6455    public function test_get_instance_should_succeed_for_float_that_is_equal_to_post_id() {
    6556        $found = WP_Comment::get_instance( 1.0 );
     
    6758        $this->assertEquals( 1, $found->comment_ID );
    6859    }
    69 
    70     /**
    71      * @ticket 37738
    72      */
    73     public function test_get_instance_should_fail_for_float() {
    74         $found = WP_Comment::get_instance( 1.6 );
    75 
    76         $this->assertFalse( $found );
    77     }
    78 
    79     /**
    80      * @ticket 37738
    81      */
    82     public function test_get_instance_should_fail_for_array() {
    83         $found = WP_Comment::get_instance( array( 1 ) );
    84 
    85         $this->assertFalse( $found );
    86     }
    87 
    88     /**
    89      * @ticket 37738
    90      */
    91     public function test_get_instance_should_fail_for_class() {
    92         $class = new stdClass();
    93         $found = WP_Comment::get_instance( $class );
    94 
    95         $this->assertFalse( $found );
    96     }
    9760}
  • branches/4.7/tests/phpunit/tests/post/wpPost.php

    r38398 r39993  
    5151     * @ticket 37738
    5252     */
    53     public function test_get_instance_should_fail_for_bool() {
    54         $found = WP_Post::get_instance( true );
    55 
    56         $this->assertFalse( $found );
    57     }
    58 
    59     /**
    60      * @ticket 37738
    61      */
    6253    public function test_get_instance_should_succeed_for_float_that_is_equal_to_post_id() {
    6354        $found = WP_Post::get_instance( 1.0 );
     
    6556        $this->assertSame( 1, $found->ID );
    6657    }
    67 
    68     /**
    69      * @ticket 37738
    70      */
    71     public function test_get_instance_should_fail_for_float() {
    72         $found = WP_Post::get_instance( 1.6 );
    73 
    74         $this->assertFalse( $found );
    75     }
    76 
    77     /**
    78      * @ticket 37738
    79      */
    80     public function test_get_instance_should_fail_for_array() {
    81         $found = WP_Post::get_instance( array( 1 ) );
    82 
    83         $this->assertFalse( $found );
    84     }
    85 
    86     /**
    87      * @ticket 37738
    88      */
    89     public function test_get_instance_should_fail_for_class() {
    90         $class = new stdClass();
    91         $found = WP_Post::get_instance( $class );
    92 
    93         $this->assertFalse( $found );
    94     }
    9558}
  • branches/4.7/tests/phpunit/tests/term/wpTerm.php

    r38398 r39993  
    6464     * @ticket 37738
    6565     */
    66     public function test_get_instance_should_fail_for_bool() {
    67         $found = WP_Term::get_instance( true );
    68 
    69         $this->assertFalse( $found );
    70     }
    71 
    72     /**
    73      * @ticket 37738
    74      */
    7566    public function test_get_instance_should_succeed_for_float_that_is_equal_to_post_id() {
    7667        $found = WP_Term::get_instance( 1.0 );
     
    7869        $this->assertSame( 1, $found->term_id );
    7970    }
    80 
    81     /**
    82      * @ticket 37738
    83      */
    84     public function test_get_instance_should_fail_for_float() {
    85         $found = WP_Term::get_instance( 1.6 );
    86 
    87         $this->assertFalse( $found );
    88     }
    89 
    90     /**
    91      * @ticket 37738
    92      */
    93     public function test_get_instance_should_fail_for_array() {
    94         $found = WP_Term::get_instance( array( 1 ) );
    95 
    96         $this->assertFalse( $found );
    97     }
    98 
    99     /**
    100      * @ticket 37738
    101      */
    102     public function test_get_instance_should_fail_for_class() {
    103         $class = new stdClass();
    104         $found = WP_Term::get_instance( $class );
    105 
    106         $this->assertFalse( $found );
    107     }
    10871}
Note: See TracChangeset for help on using the changeset viewer.