Make WordPress Core


Ignore:
Timestamp:
05/19/2021 10:10:58 PM (5 years ago)
Author:
SergeyBiryukov
Message:

General: Ensure consistent type for integer properties of WP_Post, WP_Term, and WP_User.

Previously, these properties could be unexpectedly converted to strings in some contexts.

This applies to the following functions:

  • sanitize_post_field()
  • sanitize_term_field()
  • sanitize_user_field()

and the following properties:

  • WP_Post::ID
  • WP_Post::post_parent
  • WP_Post::menu_order
  • WP_Term::term_id
  • WP_Term::term_taxonomy_id
  • WP_Term::parent
  • WP_Term::count
  • WP_Term::term_group
  • WP_User::ID

Props grantmkin, SergeyBiryukov.
Fixes #53235. See #52995.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/objects.php

    r48937 r50935  
    185185    }
    186186
     187    /**
     188     * @ticket 53235
     189     */
     190    public function test_numeric_properties_should_be_cast_to_ints() {
     191        $post_id  = self::factory()->post->create();
     192        $contexts = array( 'raw', 'edit', 'db', 'display', 'attribute', 'js' );
     193
     194        foreach ( $contexts as $context ) {
     195            $post = get_post( $post_id, OBJECT, $context );
     196
     197            $this->assertInternalType( 'int', $post->ID );
     198            $this->assertInternalType( 'int', $post->post_parent );
     199            $this->assertInternalType( 'int', $post->menu_order );
     200        }
     201    }
     202
    187203    function test_get_post_identity() {
    188204        $post = get_post( self::factory()->post->create() );
Note: See TracChangeset for help on using the changeset viewer.