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/term/getTerm.php

    r50926 r50935  
    125125    /**
    126126     * @ticket 14162
     127     * @ticket 53235
    127128     */
    128129    public function test_numeric_properties_should_be_cast_to_ints() {
     
    134135        $term_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms t JOIN $wpdb->term_taxonomy tt ON ( t.term_id = tt.term_id ) WHERE t.term_id = %d", $t ) );
    135136
    136         $found = get_term( $term_data );
    137 
    138         $this->assertInstanceOf( 'WP_Term', $found );
    139         $this->assertInternalType( 'int', $found->term_id );
    140         $this->assertInternalType( 'int', $found->term_taxonomy_id );
    141         $this->assertInternalType( 'int', $found->parent );
    142         $this->assertInternalType( 'int', $found->count );
    143         $this->assertInternalType( 'int', $found->term_group );
     137        $contexts = array( 'raw', 'edit', 'db', 'display', 'rss', 'attribute', 'js' );
     138
     139        foreach ( $contexts as $context ) {
     140            $found = get_term( $term_data, '', OBJECT, $context );
     141
     142            $this->assertInstanceOf( 'WP_Term', $found );
     143            $this->assertInternalType( 'int', $found->term_id );
     144            $this->assertInternalType( 'int', $found->term_taxonomy_id );
     145            $this->assertInternalType( 'int', $found->parent );
     146            $this->assertInternalType( 'int', $found->count );
     147            $this->assertInternalType( 'int', $found->term_group );
     148        }
    144149    }
    145150
Note: See TracChangeset for help on using the changeset viewer.