From 893beee31e67692f8fa077546cba93a191e8ae7e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 19 May 2021 22:11:56 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@50935 git-svn-id: http://core.svn.wordpress.org/trunk@50544 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 5 +++++ wp-includes/taxonomy.php | 6 ++++++ wp-includes/user.php | 6 ++++++ wp-includes/version.php | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index ed95625d10..81d152f638 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2633,6 +2633,11 @@ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { } } + // Restore the type for integer fields after esc_attr(). + if ( in_array( $field, $int_fields, true ) ) { + $value = (int) $value; + } + return $value; } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1de90cf877..7d7785407c 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1760,6 +1760,12 @@ function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) { } elseif ( 'js' === $context ) { $value = esc_js( $value ); } + + // Restore the type for integer fields after esc_attr(). + if ( in_array( $field, $int_fields, true ) ) { + $value = (int) $value; + } + return $value; } diff --git a/wp-includes/user.php b/wp-includes/user.php index 13c1542e86..4de8b12b3c 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1530,6 +1530,12 @@ function sanitize_user_field( $field, $value, $user_id, $context ) { } elseif ( 'js' === $context ) { $value = esc_js( $value ); } + + // Restore the type for integer fields after esc_attr(). + if ( in_array( $field, $int_fields, true ) ) { + $value = (int) $value; + } + return $value; } diff --git a/wp-includes/version.php b/wp-includes/version.php index af494e806b..ca445e437f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-50934'; +$wp_version = '5.8-alpha-50935'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.