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/user.php

    r49757 r50935  
    203203        foreach ( get_object_vars( $user ) as $key => $value ) {
    204204            $this->assertSame( $value, $user->$key );
     205        }
     206    }
     207
     208    /**
     209     * @ticket 53235
     210     */
     211    public function test_numeric_properties_should_be_cast_to_ints() {
     212        $user     = new WP_User( self::$author_id );
     213        $contexts = array( 'raw', 'edit', 'db', 'display', 'attribute', 'js' );
     214
     215        foreach ( $contexts as $context ) {
     216            $user->filter = $context;
     217            $user->init( $user->data );
     218
     219            $this->assertInternalType( 'int', $user->ID );
    205220        }
    206221    }
Note: See TracChangeset for help on using the changeset viewer.