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.

git-svn-id: https://develop.svn.wordpress.org/trunk@50935 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-05-19 22:10:58 +00:00
parent 2207c248f0
commit 110f132f7e
6 changed files with 60 additions and 7 deletions

View File

@@ -205,6 +205,21 @@ class Tests_User extends WP_UnitTestCase {
}
}
/**
* @ticket 53235
*/
public function test_numeric_properties_should_be_cast_to_ints() {
$user = new WP_User( self::$author_id );
$contexts = array( 'raw', 'edit', 'db', 'display', 'attribute', 'js' );
foreach ( $contexts as $context ) {
$user->filter = $context;
$user->init( $user->data );
$this->assertInternalType( 'int', $user->ID );
}
}
/**
* Test the magic __unset() method.
*